feature-loop.sh, orchestrated by the wiggum run command.
The five phases
Planning
The coding agent reads the spec at
.ralph/specs/<feature>.md and the codebase context from init. It produces <feature>-implementation-plan.md — a step-by-step task checklist.The plan accounts for your project’s file structure, naming conventions, and existing patterns.Implementation
The agent works through the implementation plan task by task. Each iteration:
- Reads the checklist and picks the next pending task
- Writes code, tests, and configuration changes
- Commits the work
- Loops until all tasks are complete
--max-iterations to override.E2E testing
The agent runs end-to-end tests against the implementation. If tests fail, it iterates — fixing either the code or the tests.Maximum attempts is configurable (default: 5). Use
--max-e2e-attempts to override.Verification
The agent re-reads the original spec and checks every requirement against the actual implementation. Did it add the endpoint? Does the error handling match? Are edge cases covered?This is not a rubber stamp. It’s an explicit confirmation step that catches subtle cases where code “works” but doesn’t match what was specified.
Phase isolation
The key insight of the Ralph loop is phase isolation. Each phase runs independently with its own:- Prompt template — Stored in
.ralph/prompts/(e.g.PROMPT_feature.md.tmplfor planning,PROMPT_e2e.md.tmplfor testing) - Status tracking — Each phase logs
started→successorfailedto a status file - Error handling — A failure in E2E testing doesn’t require restarting implementation
- Retry logic — Each phase can retry independently
Status tracking
While the loop runs, wiggum tracks progress in real-time status files:| File | Contents | |
|---|---|---|
.status | Current iteration out of max (e.g. `3 | 10`) |
.phases | Phase-by-phase progress with timestamps | |
.tokens | Token usage: input, output, cache create, cache read | |
.log | Full execution log from the coding agent | |
.final | Final outcome after completion |
Worktree isolation
Use--worktree to run the loop in an isolated git worktree:
Resume from checkpoint
If a loop gets interrupted (crash, network issue, restart), resume from the last checkpoint instead of starting over:Choosing your coding agent
The Ralph loop works with any CLI-based coding agent. Configure which agent runs each phase:Loop configuration
Fine-tune loop behavior inralph.config.cjs:
Ralph loop vs bash scripts
| Aspect | Bash script | Ralph loop (Wiggum) |
|---|---|---|
| Execution | Single undifferentiated retry loop | 5 isolated phases with checkpoints |
| Spec quality | Manual prompt | AI-generated from codebase context |
| Error recovery | Restart from scratch | Phase-level retry |
| Monitoring | Terminal output | TUI with phase tracking and token usage |
| Agent support | Hardcoded to one agent | Any CLI agent (Claude, Codex, Gemini, etc.) |
| Resume | Not supported | Checkpoint-based resume |

