A battle-tested approach for autonomous, iterative implementation of features using Claude Code. This strategy has been used to build a complete Telegram bot that negotiates static websites, accepts Stripe payments, and uses Claude Agent SDK to build and deliver sites.
The Ralph strategy uses a Product Requirements Document (PRD) in JSON format combined with a simple shell loop to let Claude autonomously implement features one at a time, maintaining context through a progress log.
- One feature at a time - Claude picks the highest-priority feature, implements it fully, then commits
- Self-verification - Each iteration runs typechecks and tests before committing
- Progress tracking - A markdown log maintains context across sessions
- Autonomous prioritization - Claude decides what to work on next based on dependencies
- Clean exit condition - Outputs
<promise>COMPLETE</promise>when all features are done
[
{
"category": "infrastructure",
"description": "Set up TypeScript monorepo with pnpm",
"steps": [
"Create pnpm-workspace.yaml",
"Configure tsconfig.json with strict mode",
"Add build and typecheck scripts"
],
"passes": false
},
{
"category": "feature",
"description": "Implement user authentication",
"steps": [
"Create auth service with Context.Tag pattern",
"Add login/logout endpoints",
"Write unit tests"
],
"passes": false
}
]# Progress Log
<!-- Append your progress notes below this line -->See ralph.sh in this gist.
bash plans/ralph.sh 10 # Run up to 10 iterations┌─────────────────────────────────────────────────────────────┐
│ ralph.sh loop │
├─────────────────────────────────────────────────────────────┤
│ for i in 1..N: │
│ 1. Claude reads prd.json + progress.txt │
│ 2. Picks highest-priority feature (with `passes: false`) │
│ 3. Implements the feature │
│ 4. Runs `pnpm typecheck && pnpm test` │
│ 5. Updates prd.json (marks `passes: true`) │
│ 6. Appends to progress.txt (context for next iteration) │
│ 7. Git commits the work │
│ 8. If all items pass → outputs COMPLETE → exits │
└─────────────────────────────────────────────────────────────┘
Each item in your PRD JSON array should have:
| Field | Type | Description |
|---|---|---|
category |
string | Groups related features (infrastructure, feature, bugfix, testing, etc.) |
description |
string | Clear, one-line description of what needs to be done |
steps |
string[] | Ordered checklist of implementation steps |
passes |
boolean | false = not done, true = implemented and verified |
infrastructure- Setup, config, CI/CDfeature- New functionalitybugfix- Bug fixestesting- Test infrastructure and test casesrefactor- Code improvements without behavior changedocumentation- Docs (use sparingly)integration- Connecting systems togetherdeployment- Deploy and verify in production
The progress log serves as context memory across iterations. Each entry should include:
## YYYY-MM-DD: Short description
**Feature:** [Exact description from PRD]
**What was done:**
- Bullet points of changes made
- Files created/modified
- Key implementation decisions
**Notes for next person:**
- Context the next iteration needs
- Known issues or limitations
- What should be done nextFor Claude Code users, create .claude/commands/ralph.md:
---
allowed-tools: Bash(bash plans/ralph.sh:*)
description: Run the Ralph iterative PRD loop
---
# Ralph - Iterative PRD Implementation
Run: `bash plans/ralph.sh $ARGUMENTS`Then use /ralph 10 to run 10 iterations.
- Be specific - "Add user authentication" is vague; "Add JWT authentication with refresh tokens" is specific
- Include verification steps - "Ensure tests pass" or "Verify in production"
- Order by dependency - Infrastructure before features, features before integration
- Keep steps atomic - Each step should be independently verifiable
Dependency tracking:
{
"description": "Connect frontend to auth API (REQUIRES: user authentication)",
"steps": ["..."]
}Blocking notes:
{
"description": "Deploy to production",
"steps": [
"NOTE: Requires AWS credentials configured",
"Build Docker image",
"Push to ECR"
]
}- Greenfield projects with clear requirements
- Porting existing codebases
- Feature backlogs with 10+ items
- Projects requiring consistent progress tracking
- Exploratory/research tasks
- One-off bug fixes
- Tasks requiring human judgment at each step
After running bash plans/ralph.sh 5:
Iteration 1
--------------------------------
[Claude implements "Set up TypeScript monorepo"]
...
git commit -m "feat: Set up TypeScript monorepo with pnpm"
Iteration 2
--------------------------------
[Claude implements "Add user authentication"]
...
git commit -m "feat: Add JWT authentication with refresh tokens"
...
Iteration 4
--------------------------------
[Claude detects all items pass]
<promise>COMPLETE</promise>
PRD complete, exiting.
| File | Description |
|---|---|
README.md |
This documentation |
ralph.sh |
The shell script that runs the loop |
prd-example.json |
Example PRD from the Ralph project |
progress-example.txt |
Example progress log showing the format |
ralph-command.md |
Slash command for Claude Code |
MIT - Use freely in your projects.
This strategy was developed while building Ralph, a Telegram bot that negotiates and delivers static websites using Claude.