Ralph is an iterative autonomous development pattern that spawns fresh Claude Code instances to work through user stories. Named after Geoffrey Huntley's Ralph Wiggum technique, the pattern exploits a key insight: each iteration benefits from a clean context window.
Traditional agent loops accumulate context as they work. By story 5, the context window is cluttered with implementation details from stories 1-4. Ralph solves this by starting fresh each iteration—Claude reads the PRD, picks an incomplete story, implements it, commits, and exits. The next iteration starts with full context capacity.
The Core Loop
for iteration in 1..MAX_ITERATIONS:
1. Read prd.json
2. Find story where passes == false
3. Spawn fresh Claude Code instance
4. Claude implements story, commits, updates prd.json
5. Log to progress.txt
6. If all stories pass → done
7. Next iterationThe PRD (Product Requirements Document) serves as Claude's task board. Each story
has acceptance criteria that must be satisfied for passes: true. When all
stories pass, Ralph exits.
Key Insight: Context Pollution
Context pollution is real. When working on a multi-file feature in a single session, Claude accumulates tokens about each implementation decision. These tokens are wasted when moving to unrelated stories.
By spawning fresh instances, Ralph ensures:
- Each story gets Claude's full attention (no irrelevant context)
- No "memory" of implementation details that don't matter
- Cleaner, more focused work per iteration
- Natural parallelization opportunity (though Ralph runs sequentially)