From ralph
Interactively generate a PRD and task list for a Ralph Loop — invoke to plan a feature before running ralph.sh
How this skill is triggered — by the user, by Claude, or both
Slash command
/ralph:ralph-planThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
You are helping the user plan a feature for execution by the Ralph Loop. Your goal is to produce two artifacts:
You are helping the user plan a feature for execution by the Ralph Loop. Your goal is to produce two artifacts:
.ralph/prd.md — A concise requirements specification that serves as the base context read at the start of every ralph iteration. Written and structured for optimal Claude comprehension in fresh context windows..ralph/tasks.json — A task list with stories sized for the Ralph Loop's fresh-context execution model. Each story is a self-contained implementation instruction that Claude can act on with only the PRD as additional context.These two files have complementary roles — the PRD provides stable context (what, why, who, constraints, technical design), while tasks.json provides execution state (individual stories, acceptance criteria, progress). They must not duplicate each other. Both should be formatted for Claude's consumption — structured, explicit, and unambiguous. The primary reader is Claude in a fresh context window, not a human skimming a document.
The user's initial prompt/instructions for this planning session:
$ARGUMENTS
If $ARGUMENTS is empty or not provided, ask the user what feature they'd like to plan before proceeding.
!bash -c 'test -d .ralph && echo "RALPH_DIR: installed" || echo "RALPH_DIR: MISSING"'
!bash -c 'test -f .ralph/templates/prd-template.md && echo "TEMPLATES: installed" || echo "TEMPLATES: MISSING"'
!bash -c 'test -f .ralph/prd.md && echo "PRD: exists" || echo "PRD: MISSING"'
!bash -c 'test -f .ralph/tasks.json && echo "TASKS: exists" || echo "TASKS: MISSING"'
!bash -c 'test -d .ralph/planning && echo "PLANNING_DIR: exists" || echo "PLANNING_DIR: MISSING"'
Evaluate the status outputs above:
/ralph-install first, then /ralph-init --name my-feature, then /ralph-plan again. Stop here./ralph-install to restore templates. Stop here./ralph-init --name my-feature to initialize state files, then /ralph-plan again. Stop here./ralph-init --name my-feature (or mkdir -p .ralph/planning) to restore the planning directory. Stop here.Before asking the user ANY questions, perform targeted research to build your own understanding of the project and the proposed feature. Research findings persist in .ralph/planning/ so they can be referenced throughout planning and by future subagents.
Start by briefly summarizing your understanding of the user's request from the $ARGUMENTS above (1-2 sentences). This confirms you've internalized the feature description before launching subagents.
!bash -c 'ls .ralph/planning/*.md 2>/dev/null || echo "NO_PRIOR_RESEARCH"'
If prior research files exist, review their contents before deciding whether to re-run subagents. Prior findings may still be relevant — especially if the user is iterating on a plan. Reuse what's still accurate, re-run only what's stale or missing.
Based on the user's feature description, determine which research subagents to launch. Not every task needs all types — use judgment. In rare cases where the feature is simple and well-described, you may skip research entirely.
| Research type | When to use | Subagent |
|---|---|---|
| Codebase exploration | When you need to understand existing code structure, patterns, tech stack, or find relevant files | Launch Task with subagent_type: "ralph-explore". Pass the feature description and specific questions about the codebase. Writes detailed findings to .ralph/planning/ralph-explore.md. |
| Documentation lookup | When the feature involves specific libraries, frameworks, or tools where API details or configuration matter | Launch Task with subagent_type: "ralph-docs". Specify which libraries to research and what questions to answer. Writes findings to .ralph/planning/ralph-docs.md. |
| Web search | When the feature involves external services, third-party APIs, or technology decisions where current information matters | Launch Task with subagent_type: "ralph-web". Specify the research questions. Writes findings to .ralph/planning/ralph-web.md. |
Launch research subagents in parallel whenever multiple types are needed. Each subagent writes detailed findings to .ralph/planning/ and returns a concise summary to you.
When spawning research subagents, your Task prompt must include:
Each subagent will:
.ralph/planning/{agent-name}.mdExample prompt for ralph-explore:
We're adding a real-time notifications system to this project. I need you to explore:
- What WebSocket or real-time infrastructure already exists (if any)?
- How are existing API routes structured — what patterns should new endpoints follow?
- What notification-related components or models already exist?
Scope: Focus on the backend API layer and any existing event/messaging code. Ignore test files, CI/CD config, and documentation. The project root is the current working directory.
If a subagent errors, times out, or returns poor-quality findings: note what information is missing, then either retry with a narrower scope or proceed without it — flagging the gap when asking the user questions so they can fill in what the research couldn't.
Synthesize the returned summaries. If any summary lacks critical detail, read the full findings file from .ralph/planning/ directly. Reference specific discoveries when asking the user questions in Phase 2 (e.g., "I see the project uses Next.js with the app router — should this feature follow the same pattern as the existing /dashboard routes?").
!bash -c 'cat .ralph/prd.md 2>/dev/null || echo "NO_PRD_CONTENT"'
Read the prd.md content above to determine which mode to use. To decide, check if the Summary section (section 1) has any real content beyond the HTML comment placeholder. If it's empty or only contains the template comment, the PRD hasn't been filled in yet.
If the Summary section has no real content (only the template HTML comment or blank), use full planning mode:
Gather requirements via AskUserQuestion — Use your research findings to ask informed, specific questions. Your questions should demonstrate understanding of the codebase and narrow in on decisions the user needs to make — NOT ask about things you already discovered through research. Focus on:
Generate .ralph/prd.md — Write the PRD following the guidelines in the "PRD Guidelines" section below. Fill in all relevant sections. Delete sections that don't apply rather than leaving them empty.
Architect task breakdown — Launch the ralph-plan-tasks subagent via Task with subagent_type: "ralph-plan-tasks". In your prompt, include:
.ralph/prd.md).ralph/planning/ (so it can read them)The subagent writes a detailed task architecture to .ralph/planning/ralph-plan-tasks.md and returns a summary. Read the full .ralph/planning/ralph-plan-tasks.md file to review the proposed breakdown.
Derive .ralph/tasks.json — Using the task architecture from ralph-plan-tasks, generate the final tasks.json. Apply all field requirements (initial state, story IDs, structure) from the "Task Derivation Rules" section below. You may adjust the subagent's recommendations — it provides the architecture, you produce the final artifact.
Present both files for review — Use AskUserQuestion to present your draft of prd.md and tasks.json and ask the user to approve, request changes, or add missing requirements. Iterate until the user confirms both artifacts are ready.
If prd.md already contains real requirements content:
.ralph/prd.md thoroughly (already loaded above)ralph-plan-tasks subagent (same as Mode 1 step 3). Pass the existing PRD content, research findings paths, and any clarifications from the user. Read the full .ralph/planning/ralph-plan-tasks.md output..ralph/tasks.json — Convert the task architecture output into final tasks.json, applying all field requirements from the "Task Derivation Rules" section below.AskUserQuestion to present the task list and ask the user to approve or request changes. Iterate until confirmed.The PRD is read at the start of every ralph iteration in a fresh context window. It serves as the stable "base context" that orients each session. Every word in the PRD costs context budget across every iteration.
Target: 2,000-3,000 words maximum (~2,500-4,000 tokens).
Rationale — measured per-iteration overhead for the ralph loop artifacts:
| Artifact | Size | Tokens (approx) | Notes |
|---|---|---|---|
| Claude Code system prompt + tools | — | ~5,000-15,000 | Fixed overhead, not controllable |
| prompt.md (iteration template) | ~1,400 words / ~10K chars | ~2,000-2,500 | Fixed per iteration |
| prd.md | 2,000-3,000 words | ~2,500-4,000 | Your target — read every iteration |
| tasks.json (5 stories, populated) | ~5-6K chars | ~1,500-2,000 | Grows with stories |
| progress.txt (mid-loop, ~5 iterations) | ~1,000-1,200 words | ~1,000-1,500 | Grows each iteration |
| Orientation (git log, git status, .ralph-active) | — | ~250-500 | Fixed per iteration |
| Total fixed overhead | ~12,000-25,000 | Before any implementation work |
Claude's context window is ~200K tokens (~185-195K usable after system prompt). The "smart zone" — where reasoning quality is highest — is 30-60% utilization (~60K-120K total tokens used). Beyond 60%, reasoning quality degrades progressively ("context rot"). This means:
Formatting rules for PRD:
The PRD provides umbrella context. tasks.json provides per-story execution state. They are complementary, not overlapping.
| Belongs in PRD | Belongs in tasks.json |
|---|---|
| High-level summary (what, why, who) | Individual story titles and descriptions |
| Problem statement and goals | Per-story acceptance criteria |
| Architecture overview and technical design | Story dependencies and ordering |
| Cross-cutting constraints (rules that apply to ALL stories) | Story-specific implementation notes |
| Key file paths and existing patterns to follow | Verification status (passes, reviewStatus) |
| Non-goals and scope boundaries | Story-specific edge cases |
| Global edge cases and error handling strategy | Per-story notes and review feedback |
The PRD should never re-state what's in individual story descriptions. Instead, it provides the context that makes each story's description and acceptance criteria self-sufficient. A fresh Claude session reads the PRD to understand the "world," then reads a specific story to know what to implement in that iteration.
Follow the template structure in .ralph/templates/prd-template.md. Key principles:
Apply these rules when creating the task list in both modes.
Each Ralph Loop iteration runs in a fresh context window. Claude's context window is ~200K tokens (~185-195K usable after system prompt and tool definitions). The "smart zone" — where Claude reasons best — is 30-60% utilization (~60K-120K total tokens). Beyond ~60%, reasoning quality degrades progressively. A story must be completable well within this zone.
How to think about story size in tokens:
A typical source file (100-500 lines) consumes ~1,500-5,000 tokens when read. Each tool call round-trip (read, edit, bash) adds ~500-2,000 tokens. Verification commands add ~500-1,500 tokens each. So a story's implementation work breaks down as:
| Activity | Token cost | Notes |
|---|---|---|
| Reading source files to understand context | ~1,500-5,000 per file | 200-line file ≈ ~2,500 tokens |
| Code edits (read + write per file) | ~1,000-3,000 per modified file | Includes tool call overhead |
| Running verification commands | ~500-1,500 per command | Test output varies |
| Self-review (git diff + analysis) | ~2,000-5,000 | Depends on change size |
| Commit + tasks.json/progress.txt updates | ~1,000-2,000 | Fixed overhead |
With ~40-100K tokens of smart-zone budget for implementation (after the ~20K overhead from ralph artifacts), a story can afford:
Concrete sizing heuristics:
When to split stories:
dependsOn explicitly when story order matters beyond priority numberGET /api/users returns JSON array with id, name, email fields not "API works correctly"src/routes/users.ts exporting a GET handler that queries the users table and returns JSON matching the schema in the PRD §6b" is better than "As a user, I want to see a list of users"/api/v1/users following the pattern in routes/products.ts") — don't just say "add user endpoint"verifyCommands from the project's existing test/lint/typecheck commandsAskUserQuestion if you're unsure which commands to includeAll stories must start with:
{
"passes": false,
"reviewStatus": null,
"reviewCount": 0,
"reviewFeedback": ""
}
{
"project": "<project name>",
"description": "<brief description of the overall feature>",
"verifyCommands": ["<test command>", "<lint command>"],
"userStories": [
{
"id": "US-001",
"title": "<short imperative title — e.g., 'Create users API route'>",
"description": "<implementation instruction for Claude — what to build, which files to create/modify, which patterns to follow, referencing PRD sections for context>",
"acceptanceCriteria": ["<assertion Claude can objectively verify>"],
"priority": 1,
"passes": false,
"reviewStatus": null,
"reviewCount": 0,
"reviewFeedback": "",
"notes": "",
"dependsOn": []
}
]
}
AskUserQuestion to get explicit confirmation before writing prd.md and tasks.json.ralph/planning/. Read these files when you need more detail than the returned summaries provide. The planning folder is archived with the loop and cleaned on init.US-001, US-002, etc.branchName or instruct the user to create a new branch.npx claudepluginhub zakattack9/agentic-coding --plugin ralphCreates bite-sized, testable implementation plans from specs or requirements, with file structure and task decomposition. Activates before coding multi-step tasks.