Hybrid Ralph + Planning-with-Files
A hybrid architecture combining the best of three approaches:
Auto-Recovery Protocol (CRITICAL)
At the START of any interaction, perform this check to recover context after compression/truncation:
-
Check if
.hybrid-execution-context.mdexists in the current directory -
If YES:
- Read the file content using Read tool
- Display: "Detected ongoing hybrid task execution"
- Show current batch and pending stories from the file
- Resume story execution based on the state
- If unsure of state, suggest:
/hybrid:resume --auto
-
If NO but
prd.jsonexists:- Run:
uv run python "${CLAUDE_PLUGIN_ROOT}/skills/hybrid-ralph/scripts/hybrid-context-reminder.py" both - This will generate the context file and display current state
- Run:
This ensures context recovery even after:
-
Context compression (AI summarizes old messages)
-
Context truncation (old messages deleted)
-
New conversation session
-
Claude Code restart
-
Ralph: Structured PRD format (prd.json), progress tracking patterns, small task philosophy
-
Planning-with-Files: 3-file planning pattern (task_plan.md, findings.md, progress.txt), Git Worktree support
-
Claude Code Native: Task tool with subagents for parallel story execution
Quick Start
Automatic PRD Generation
Generate a PRD from your task description:
/hybrid:auto Implement a user authentication system with login, registration, and password reset
This will:
- Launch a Planning Agent to analyze your task
- Generate a PRD with user stories
- Show the PRD for review
- Wait for your approval
Manual PRD Loading
Load an existing PRD file:
/hybrid:manual path/to/prd.json
Approval and Execution
After reviewing the PRD:
/approve
This begins parallel execution of stories according to the dependency graph.
Architecture
File Structure
project-root/
├── prd.json # Product Requirements Document
├── findings.md # Research findings (tagged by story)
├── progress.txt # Progress tracking
├── .current-story # Currently executing story
├── .locks/ # File locks for concurrent access
└── .agent-outputs/ # Individual agent logs
The PRD Format
The prd.json file contains:
- metadata: Creation date, version, description
- goal: One-sentence project goal
- objectives: List of specific objectives
- stories: Array of user stories with:
id: Unique story identifier (story-001, story-002, etc.)title: Short story titledescription: Detailed story descriptionpriority: high, medium, or lowdependencies: Array of story IDs this story depends onstatus: pending, in_progress, or completeacceptance_criteria: List of completion criteriacontext_estimate: small, medium, large, or xlargetags: Array of tags for categorization
Parallel Execution Model
Stories are organized into execution batches:
- Batch 1: Stories with no dependencies (run in parallel)
- Batch 2+: Stories whose dependencies are complete (run in parallel)
Batch 1 (Parallel):
- story-001: Design database schema
- story-002: Design API endpoints
Batch 2 (After story-001 complete):
- story-003: Implement database schema
Batch 3 (After story-002, story-003 complete):
- story-004: Implement API endpoints
Context Filtering
Each agent receives only relevant context:
- Their story description and acceptance criteria
- Summaries of completed dependencies
- Findings tagged with their story ID
This keeps context windows focused and efficient.
Core Python Modules
context_filter (migrated to src/plan_cascade/state/)
Context filtering functionality is now provided by the main package.
# Get story details
uv run python -m plan_cascade.state.context_filter get-story story-001
# Get context for a story
uv run python -m plan_cascade.state.context_filter get-context story-001
# Get execution batch
uv run python -m plan_cascade.state.context_filter get-batch 1
# Show full execution plan
uv run python -m plan_cascade.state.context_filter plan-batches
state_manager.py
Thread-safe file operations with platform-specific locking.
# Read PRD
uv run python state_manager.py read-prd
# Mark story complete
uv run python state_manager.py mark-complete story-001
# Get all story statuses
uv run python state_manager.py get-statuses
prd_generator.py
Generates PRD from task descriptions and manages story dependencies.
# Validate PRD
uv run python prd_generator.py validate
# Show execution batches
uv run python prd_generator.py batches
# Create sample PRD
uv run python prd_generator.py sample
orchestrator.py
Manages parallel execution of stories.
# Show execution plan
uv run python orchestrator.py plan
# Show execution status
uv run python orchestrator.py status
# Execute a batch
uv run python orchestrator.py execute-batch 1
Commands Reference
/hybrid:auto
Generate PRD from task description and enter review mode. Auto-generates user stories with priorities, dependencies, and acceptance criteria for parallel execution.
/hybrid:auto [options] <task description> [design-doc-path]
Parameters:
| Parameter | Description |
|---|---|
--flow <quick|standard|full> | Execution flow depth controlling quality gate strictness |
--tdd <off|on|auto> | Test-Driven Development mode |
--confirm | Require batch confirmation during execution |
--no-confirm | Disable batch confirmation |
--spec <off|auto|on> | Spec interview before PRD generation |
--first-principles | Enable first-principles questioning in spec interview |
--max-questions N | Max questions in spec interview |
--agent <name> | Agent to use for PRD generation |
design-doc-path | Optional path to existing design document |
Parameters are saved to prd.json and propagated to /approve.
/hybrid:manual
Load an existing PRD file and enter review mode.
/hybrid:manual [path/to/prd.json]
/hybrid:worktree
Start a new task in an isolated Git worktree with Hybrid Ralph PRD mode. Creates worktree, branch, loads existing PRD or auto-generates from description.
/hybrid:worktree [options] <task-name> <target-branch> <prd-path-or-description> [design-doc-path]
Arguments:
task-name: Name for the worktree (e.g., "feature-auth", "fix-api-bug")target-branch: Branch to merge into (default: auto-detect main/master)prd-path-or-description: Either a task description to generate PRD, or path to existing PRD file
Parameters:
| Parameter | Description |
|---|---|
--flow <quick|standard|full> | Execution flow depth controlling quality gate strictness |
--tdd <off|on|auto> | Test-Driven Development mode |
--confirm | Require batch confirmation during execution |
--no-confirm | Disable batch confirmation |
--spec <off|auto|on> | Spec interview before PRD generation |
--first-principles | Enable first-principles questioning in spec interview |
--max-questions N | Max questions in spec interview |
--agent <name> | Agent to use for PRD generation |
design-doc-path | Optional path to existing design document |
Parameters are saved to the worktree's prd.json, ensuring isolation from other tasks.
/approve
Approve PRD and begin parallel story execution. Analyzes dependencies, creates execution batches, launches background Task agents, and monitors progress.
/approve [options]
Parameters:
| Parameter | Description |
|---|---|
--flow <quick|standard|full> | Override execution flow depth (quality gate strictness) |
--tdd <off|on|auto> | Control TDD mode for story execution |
--confirm | Require confirmation before each batch |
--no-confirm |