Ralph is an autonomous AI agent loop that runs AI coding agents repeatedly until all project items are complete.
Each iteration spawns a fresh session with clean context to prevent context rot. Memory persists via git history and simple, readable files on disk.
Note
This is a fork of Ryan Carson's Ralph which he wished to preserve as a simpler script.
Based on Geoffrey Huntley's Ralph pattern.
- Redesigned skills workflows and file locations
- Run from anywhere, prompt embedded in the script
- Support for OpenCode and Claude Code
- Prettier output with process PID, CPU %, Memory, Remote Port, task wall time, total wall time
- Automatic worktree creation, no manually moving plans to worktrees
- More efficient bookkeeping (jq - much faster than the LLM)
- Adds back the original plan context, either in full or in part (split up if it's large)
- The original plan context was "lost" and Ralph was only getting the basic user story and acceptance criteria but no commentary
-
Create a plan/PRD (optional - use
ralph-prdskill or write manually):> Use the ralph-prd skill to create a PRD for user authenticationThis creates
plans/auth.mdAlternatively, you can write a PRD manually in
plans/directory. -
Convert your plans to Ralph format using the
ralph-prepskill (REQUIRED):> Use the ralph-prep skill to convert plans/auth.mdThis creates
ralph/auth/ralph.jsonand associated filesNote:
ralph-prepworks with any PRD file (created byralph-prdor written manually). -
Run Ralph: (example plan called "auth")
./ralph.sh ralph/auth
Or just
./ralph.shto use the first incomplete plan if there is only one plan or present an interactive chooser if there is more than one. -
Monitor progress:
# See Ralph's progress ./ralph.sh ralph/auth --status # See the next prompt Ralph will use - no magic! ./ralph.sh ralph/auth --next-prompt
The ralph-prd skill is optional but useful for:
- Complex features requiring detailed acceptance criteria
- Large projects where structured planning helps
- Teams who want consistent PRD format across features
For simple features, you can write PRDs manually in the plans/ directory.
Tip
The only required skill is ralph-prep, which converts any plan or PRD (manual or generated) into Ralph's execution format.
project-root/
├── plans/ # Your PRDs (created by ralph-prd skill or manually - can live anywhere, actually)
│ ├── auth.md # These files will not be modified by Ralph
│ └── dashboard.md
│
└── ralph/ # Auto-generated execution directories
├── auth/ # Project slug in this example is "auth", derived from plans/auth.md
│ ├── README.md # Primary plan description, either a simple copy of your plan or a shortened high-level view of it if split
│ ├── ralph.json # Execution config and status with user stories
│ ├── progress.txt # Simple iteration history log
│ ├── AGENTS.md # Learnings from each iteration
│ └── [domain].md # Domain-specific plans (if auto-split by the ralph-prep step)
│
└── archive/ # Completed runs
└── 2026-01-14-auth/
- One of the following AI coding tools installed and authenticated:
- Amp CLI (default)
- Claude Code
- OpenCode
- Common shell utilities:
jqfor JSON manipulation (brew install jqon macOS,apt-get install jqon Ubuntu)gitof coursesed, etc.
- A git repository for your project
Download and install ralph.sh to your PATH for easy access, although it can be invoked from anywhere.
curl -o ~/.local/bin/ralph.sh https://raw.githubusercontent.com/colinmollenhour/ralph/main/ralph.sh
chmod +x ~/.local/bin/ralph.sh
# Ensure ~/.local/bin is in PATH (add to ~/.bashrc, ~/.zshrc, or your shell's config)
export PATH="$HOME/.local/bin:$PATH"Copy the Agent Skills to your Amp or Claude config for use across all projects:
For Amp:
# From local clone
cp -r skills/ralph-prd ~/.config/amp/skills/
cp -r skills/ralph-prep ~/.config/amp/skills/
# Or via curl (no clone needed)
mkdir -p ~/.config/amp/skills/{ralph-prd,ralph-prep}
curl -o ~/.config/amp/skills/ralph-prd/SKILL.md https://raw.githubusercontent.com/colinmollenhour/ralph/main/skills/ralph-prd/SKILL.md
curl -o ~/.config/amp/skills/ralph-prep/SKILL.md https://raw.githubusercontent.com/colinmollenhour/ralph/main/skills/ralph-prep/SKILL.mdFor Claude Code and OpenCode:
# From local clone
cp -r skills/ralph-prd ~/.claude/skills/
cp -r skills/ralph-prep ~/.claude/skills/
# Or via curl (no clone needed)
mkdir -p ~/.claude/skills/{ralph-prd,ralph-prep}
curl -o ~/.claude/skills/ralph-prd/SKILL.md https://raw.githubusercontent.com/colinmollenhour/ralph/main/skills/ralph-prd/SKILL.md
curl -o ~/.claude/skills/ralph-prep/SKILL.md https://raw.githubusercontent.com/colinmollenhour/ralph/main/skills/ralph-prep/SKILL.mdIdeally you should have a solid list of user stories and acceptance criteria. The ralph-prd skill will generate these for you from
your existing plan files or from your session context. This isn't strictly required, but this system is designed to have user stories
and acceptance criteria.
Use the ralph-prd skill to create a PRD for [your feature description/files]
The skill saves output to plans/PRD-[feature-name].md.
Use the ralph-prep skill to convert the markdown PRD to a Ralph execution directory:
Use the ralph-prep skill to prepare plans/PRD-[feature-name].md
This creates ralph/[feature-name]/ with:
README.md- Primary plan (copy of source or high-level overview if split)ralph.json- User stories structured for autonomous executionprogress.txt- Iteration log initialized with header[domain].mdfiles - Domain-specific plans (only if PRD was large and split)
You are now ready to run Ralph. If you have just one plan simply run ralph.sh and watch it go!
# Run specific project
ralph.sh ralph/auth
# With options (can be combined)
ralph.sh ralph/auth -n 10 # Max 10 iterations (default 20)
ralph.sh ralph/auth --tool claude # Use Claude Code
ralph.sh ralph/auth --tool opencode # Use OpenCode
ralph.sh ralph/auth --next-prompt # Inspect the next prompt without executing the agent
ralph.sh ralph/auth --learn # Normal execution + learn on final iteration
ralph.sh ralph/auth --learn-now # Just run the learn prompt to absorb the AGENTS.md into your main AGENTS.md
ralph.sh ralph/auth --worktree # Create a git worktree for branch "ralph/auth" at `.worktrees/auth` for execution in a clean environment
# Stop a running Ralph gracefully (let it finish the current task before stopping)
ralph.sh ralph/auth --stopRun ralph.sh --help for all options.
Ralph will:
- Create a feature branch (from
branchNameinralph.json- and a worktree if--worktreeis used) - Pick the highest priority story where
passes: false - Implement that single story
- Run quality checks (lint, typecheck, tests)
- Append learnings to the
ralph/[feature]/AGENTS.mdfile - Update
ralph.jsonto mark story aspasses: true - Commit all changed files including the Ralph files
- Repeat from step 2 until all stories pass or max iterations reached (the loop)
- Remove all Ralph files in the last commit (easy to recover)
| File | Purpose |
|---|---|
ralph.sh |
The bash loop that spawns fresh AI instances |
plans/ |
Source PRDs (user-created, read-only by Ralph) |
ralph/[feature]/ |
Execution directories (auto-generated) |
ralph/[feature]/ralph.json |
User stories with passes status (the task list) |
ralph/[feature]/progress.txt |
Simple iteration history |
ralph/[feature]/AGENTS.md |
Learnings for future iterations (created on first task) |
skills/ralph-prd/ |
Optional skill for generating PRDs |
skills/ralph-prep/ |
REQUIRED skill for converting PRDs to execution directories |
flowchart/ |
Interactive visualization of how Ralph works |
View Interactive Flowchart - Click through to see each step with animations.
The flowchart/ directory contains the source code. To run locally:
cd flowchart
npm install
npm run devEach iteration spawns a new AI instance (Amp, Claude Code, or OpenCode) with clean context. The only memory between iterations is:
- Git history (commits from previous iterations)
AGENTS.md(project-specific learnings)progress.txt(history log)ralph.json(which stories are done)
Ralph pre-computes all context and injects it directly into the prompt:
- Story details, acceptance criteria, and commands are pre-computed
- Learnings from
AGENTS.mdare included in the prompt - Agents don't need to read
ralph.json(although sometimes they do anyway) - Expected overhead: ~1800-3500 tokens vs ~8000-15000 in naive approach
Each PRD item should be small enough to complete in one context window. If a task is too big, the LLM runs out of context before finishing and produces poor code.
Right-sized stories:
- Add a database column and migration
- Add a UI component to an existing page
- Update a server action with new logic
- Add a filter dropdown to a list
Too big (split these):
- "Build the entire dashboard"
- "Add authentication"
- "Refactor the API"
Each Ralph project has its own AGENTS.md file (created automatically). Agents append learnings here during execution.
To absorb learnings into the project root ./AGENTS.md:
./ralph.sh ralph/auth --learn # Absorb after all stories complete
./ralph.sh ralph/auth --learn-now # or do it later after reviewExamples of what is added to AGENTS.md:
- Patterns discovered ("this codebase uses X for Y")
- Gotchas ("do not forget to update Z when changing W")
- Useful context ("the settings panel is in component X")
Ralph only works if there are solid feedback loops:
- Typecheck catches type errors
- Tests verify behavior
- CI must stay green (broken code compounds across iterations)
Frontend stories must include "Verify in browser using dev-browser skill" in acceptance criteria. Ralph will use the dev-browser skill to navigate to the page, interact with the UI, and confirm changes work.
When all stories have passes: true, Ralph outputs <promise>COMPLETE</promise> and the loop exits.
Use --next-prompt to see exactly what context Ralph loads:
./ralph.sh ralph/auth --next-promptThis shows the full prompt, plan files, and progress context without invoking the agent.
Check current state:
# See which stories are done
ralph.sh ralph/auth --status
# See learnings from previous iterations
cat ralph/auth/progress.txt
# Check git history
git log --oneline -10The prompt should work well for general purposes but you can provide your own if your project needs different instructions like special git commit message formats or automatically creating pull requests, running code review tools, etc.
Ralph looks for prompts in this order:
--custom-prompt <file>- Explicit flag takes highest priority[ralph-dir]/.agents/ralph.md- Project-local template (if exists)- Embedded default prompt
To customize for your project:
- Run
ralph.sh --eject-promptwhich will create.agents/ralph.mdin your project directory. - Modify it for your needs, probably add it to your repo.
- Ralph will automatically use it over the embedded one for this project.
When all stories are complete, Ralph automatically removes working files in a final commit, but of course they can be recovered.
# Revert the last commit
git reset --hard HEAD^
# Recover the files without changing history
git checkout HEAD~1 -- ralph/auth/To disable cleanup: Create a custom prompt template without the cleanup instructions in the Stop Condition section.
Ralph automatically archives previous runs when you start a new feature (different branchName). Archives are saved to ralph/archive/YYYY-MM-DD-feature-name/.
A minimal test project is included to try Ralph without affecting your own codebase.
cd test-project
# Reset to initial state (creates git repo if needed - can do this multiple times)
./reset.sh
# Preview what Ralph will do
../ralph.sh --next-prompt ralph/add-math-functions
# Run Ralph (requires amp, claude, or opencode to be installed)
../ralph.sh ralph/add-math-functions --tool amp
# or
../ralph.sh ralph/add-math-functions --tool claude
# or
../ralph.sh ralph/add-math-functions --tool opencodeThe test project has 5 simple user stories that add math functions to src/math.ts. Each story is small enough to complete in a single iteration, making it ideal for testing Ralph's behavior.
- Ryan Carson's original script which he wished to preserve as a simple script.
- Geoffrey Huntley's Ralph article
- Amp documentation
- Claude Code documentation

