Ralph repository describes an autonomous AI agent loop that repeatedly drives AI coding tools to implement user stories from a PRD until all quality checks pass. The loop spawns a fresh AI instance each iteration and preserves state through git history, progress.txt, and prd.json, enabling incremental, auditable progress across runs.
Prerequisites and setup
Ralph relies on one of two supported AI coding tools:
- Amp CLI — https://ampcode.com (default)
- Claude Code — https://docs.anthropic.com/en/docs/claude-code
Additional tooling includes jq and a git repository for the project. Files and skills can be copied directly into a project or installed globally into Amp/Claude skill directories. Example installation snippets live in the repo; the main runner is a shell script at scripts/ralph/ralph.sh.
Workflow
The intended workflow is structured and iterative:
- Generate a PRD using the
prdskill; the output is saved totasks/prd-[feature-name].md. - Convert the markdown PRD to a machine-actionable
prd.jsonvia theralphskill. - Run the loop with the shell script:
- Using Amp (default):
./scripts/ralph/ralph.sh [max_iterations] - Using Claude Code:
./scripts/ralph/ralph.sh --tool claude [max_iterations]
- Using Amp (default):
Each iteration follows a single-story lifecycle:
- Create a feature branch (from PRD
branchName) - Pick the highest-priority story with
passes: false - Implement that story
- Run typechecks and tests
- Commit if checks pass
- Mark the story
passes: trueinprd.json - Append learnings to
progress.txt - Repeat until all stories pass or the max iteration count is reached
Key files and components
ralph.sh— the bash loop that spawns fresh AI instances (supports--tool ampor--tool claude)prompt.md,CLAUDE.md— prompt templates for Amp and Claude Codeprd.json— structured user stories withpassesstatusprogress.txt— append-only learnings for future iterationsskills/prd/,skills/ralph/— PRD generation and conversion skillsflowchart/— interactive visualization source
Critical concepts for reliable runs
- Each iteration is a fresh AI instance. The only persistent memory is commits,
progress.txt, andprd.json. - Right-sized stories. Tasks must be small enough to fit a single context window (e.g., add a DB column, update a UI component). Large tasks should be split.
- Feedback loops matter. Reliable typechecks, tests, and CI are required; broken CI compounds across iterations.
- AGENTS.md updates. After each iteration, the loop updates
AGENTS.mdso future AI instances (and humans) inherit discovered patterns and gotchas. - Browser verification for UI stories. Frontend acceptance criteria should include browser verification via the dev-browser skill.
Visualization, debugging, and customization
An interactive flowchart lives at https://snarktank.github.io/ralph/. The repo includes commands for inspecting state (e.g., using jq on prd.json, viewing progress.txt, and checking recent git commits). Prompts can be customized to include project-specific quality checks, codebase conventions, and common pitfalls. Ralph also archives previous runs under archive/YYYY-MM-DD-feature-name/.
References
Ralph builds on the Ralph pattern from Geoffrey Huntley: https://ghuntley.com/ralph/. Additional links in the repo point to Amp documentation (https://ampcode.com/manual) and Claude Code docs (https://docs.anthropic.com/en/docs/claude-code).
Original source: https://github.com/snarktank/ralph


