Automated loop that feeds Claude Code a plan and executes it one phase at a time.
Copy the files from this repo into a folder named ralph/ at the root of the repo where you want to use the loop.
Each project lives in its own folder under ralph/projects/:
ralph/
├── loop.sh # Shell script that runs the Claude Code loop
├── PROMPT.md # Prompt template ({{DESIGN_FILE}}, {{PLAN_FILE}} are substituted)
├── DESIGN.md # Guide for writing design documents
├── PLAN.md # Guide for writing execution plans
├── REVIEW.md # Guide for post-execution code reviews
├── ADDRESS.md # Guide for fixing review findings
├── logs/ # Auto-created directory with per-iteration logs
└── projects/
└── <project-name>/
├── design.md # Design specification (created first during planning)
├── plan.md # Execution plan with phases and checkboxes
└── review.md # Post-execution review (written after all phases complete)
Ralph projects follow a four-phase lifecycle: Design → Execute → Review → Address. Each phase has a guide document and produces an artifact in the project folder.
Create the design specification first. Use ralph/DESIGN.md as the guide:
Create a design for <feature description>. Use @ralph/DESIGN.md as context.
The design captures the what and why — architecture, locking analysis, edge cases, and trade-offs. It ends with Open Questions for the user to resolve interactively. The design is ready when all questions are marked _Resolved_.
Output: ralph/projects/<name>/design.md
Create the execution plan from the finalized design. Use ralph/PLAN.md as the guide:
Create a plan for @ralph/projects/<name>/design.md. Use @ralph/PLAN.md as context.
The plan captures the how — phased steps with checkboxes, code sketches, and test tasks. Then run it:
./ralph/loop.sh <project-name> # Run the loopThe loop executes phases autonomously, recording observations and committing after each one.
Output: ralph/projects/<name>/plan.md (with all checkboxes marked and observations filled)
After all phases complete, request a review. Use ralph/REVIEW.md as the guide:
Review the changes performed as part of the @ralph/projects/<name>/plan.md.
Use @ralph/REVIEW.md as context.
The review reads the design, plan, observations, all changed files, and git diffs. It produces a verdict with findings categorized as Critical, Important, or Trivial, plus a design compliance checklist and test coverage assessment.
Output: ralph/projects/<name>/review.md
After the review, fix any findings that need attention. Use ralph/ADDRESS.md as the guide:
Fix the findings in @ralph/projects/<name>/review.md. Use @ralph/ADDRESS.md as context.
Claude reads each finding, implements the fix, builds to verify, and appends a > **Resolution:** blockquote to the finding in the review document — preserving the original finding text. Findings are processed sequentially to avoid file conflicts.
Output: Updated ralph/projects/<name>/review.md (with resolutions appended to each finding) + code fixes
- No design doc needed: Bug fixes, simple configuration changes, UI-only tweaks. Put a "Design Decisions" section directly in the plan.
- No plan needed: One-off tasks that don't need phased execution.
- Always review: Any project that used the automated loop should be reviewed before merging.
-
Create your project under
ralph/projects/<name>/with at leastdesign.mdandplan.md. -
Run the loop:
./ralph/loop.sh <project> # Run until all phases complete (max 50) ./ralph/loop.sh <project> 10 # Run at most 10 iterations
Example:
./ralph/loop.sh partitioned-history-db
The loop manages a feature branch for each project:
- Start: Creates a
ralph/<project-name>branch from the current branch - During execution: Each phase is committed on the feature branch with a
Phase N:prefix - Completion: Merges back to the starting branch with
--no-ff, preserving the full phase-by-phase history ingit log --graph
If interrupted, re-run the same command — the loop detects the existing feature branch and resumes. The base branch is stored in ralph/projects/<name>/.base-branch (gitignored).
main ─────────────────────────────────●── merge commit ──▶
╱
ralph/my-project ── Phase 0 ── Phase 1 ── Phase 2
- The loop substitutes project paths into
PROMPT.mdand pipes it to Claude Code - Claude reads the plan and finds the next unchecked phase
- Executes that single phase (code changes, builds, tests)
- Records discoveries in the Observations section of the plan
- Marks the phase complete and commits (prefixed with
Phase N:) - Outputs
RALPH_PHASE_COMPLETE(loop continues) orRALPH_ALL_COMPLETE(loop stops) - On
RALPH_ALL_COMPLETE: merges the feature branch back with--no-ff
--dangerously-skip-permissionsis required for autonomous operation- Max iterations acts as a safety net
- Ctrl+C to abort at any time
- Logs are saved per project and iteration for review