A local harness for running Ralph (AI coding agent loops) with multiple AI backends.
Supports the following AI CLIs:
- claude - Claude Code
- codex - OpenAI Codex CLI
- gemini - Google Gemini CLI
Based on the Ralph technique by Matt Pocock. See RALPH.md for the full guide.
You should have the following AI CLI tools installed:
claude- Anthropic's Claude Code CLIcodex- OpenAI Codex CLIgemini- Google Gemini CLI
The scripts automatically configure them with appropriate flags:
- claude:
--dangerously-skip-permissions -p(print mode) - gemini:
--yolo - codex:
exec --dangerously-bypass-approvals-and-sandbox --enable web_search_request
No additional configuration needed - the scripts handle everything.
- Run setup to create symlinks:
./setup.sh - Initialize a project:
ralph-init - Edit PRD.md with your requirements
- Run one iteration:
ralph-once - Run multiple iterations:
ralph 20
cd /Users/francip/src/ralph-cli
./ralph-init.sh # In your project directory
./ralph-once.sh # Run one iteration
./ralph.sh 20 # Run 20 iterationsRun the setup script to create symlinks in ~/bin:
cd /Users/francip/src/ralph-cli
./setup.shThis creates symlinks for:
ralph-init- Project initializerralph-once- Single iterationralph- Multi-iteration mode
The script will:
- Create
~/binif it doesn't exist - Create symlinks for all Ralph commands
- Check if
~/binis in your PATH - Show instructions to add it if needed
After setup, you can run Ralph commands from anywhere:
cd ~/my-project
ralph-init # Initialize with PRD template
ralph-once # Test with one iteration
ralph 20 # Run 20 iterationsEdit .ralphrc in your project or in /Users/francip/src/ralph-cli/.ralphrc to set defaults:
# Ralph Configuration
AI_COMMAND=claude # claude, codex, or gemini
PRD_FILE=PRD.md
PROGRESS_FILE=progress.txtralph-initCreates:
PRD.md- Template for your requirementsprogress.txt- Auto-updated progress log
Run one iteration at a time to build intuition:
# Use default AI from .ralphrc
ralph-once
# Use specific AI
ralph-once claude
ralph-once codex
ralph-once geminiRun multiple iterations automatically:
# Use default AI, run 20 iterations
ralph 20
# Use specific AI (cleaner syntax)
ralph claude 20
ralph codex 10
ralph gemini 15
# Or with --ai flag
ralph --ai codex 10
# Or via environment variable
RALPH_AI=codex ralph 10The loop will:
- Read PRD.md and progress.txt
- Pick highest-priority incomplete task
- Implement it
- Run tests and type checks
- Update PRD and progress.txt
- Commit changes
- Repeat until complete or max iterations reached
The AI outputs <promise>COMPLETE</promise> when the PRD is finished.
claude
# Press Shift+Tab to enter plan mode
# Iterate on your plan
# Tell Claude: "Save this to PRD.md"ralph-init
# Edit the generated PRD.mdAny format works - markdown checklist, JSON, prose. Example:
# My Project PRD
## Goals
Build a REST API for managing todos
## Requirements
- [ ] Set up Express server
- [ ] Create Todo model
- [ ] Implement CRUD endpoints
- [ ] Add validation
- [ ] Write tests
## Technical Specs
- Node.js 18+
- Express 4.x
- Jest for testing
## Success Criteria
- All endpoints working
- Tests passing with >80% coverageThe AI will:
- Read PRD.md and progress.txt
- Pick the next unchecked task
- Implement it
- Commit changes
- Update progress.txt
Run in an isolated environment:
# Install Docker Desktop 4.50+
docker sandbox run claude ./ralph.sh 20Benefits:
- Isolated environment
- Persistent state per workspace
- Auto-injected git config
- Safe experimentation
ralph-cli/
├── .ralphrc # Configuration
├── setup.sh # Setup script (creates symlinks)
├── ralph-init.sh # Project initializer
├── ralph-once.sh # Single iteration script
├── ralph.sh # Multi-iteration script
├── RALPH.md # Original guide
├── README.md # This file
├── PRD.example.md # Example PRD
└── progress.example.txt # Example progress file
Your project:
├── PRD.md # Your requirements (created by ralph-init)
└── progress.txt # Auto-updated log (created by ralph-init)
Ralph is a simple loop:
- AI reads PRD and progress files
- AI picks next incomplete task
- AI implements the task
- AI commits changes
- AI updates progress.txt
- Repeat until complete or max iterations
The AI decides what to work on - you just provide the PRD.
Note: The scripts use the AI CLIs directly with appropriate flags for auto-approval and non-interactive mode. No additional configuration needed.
Instead of local PRD, pull from:
- GitHub Issues
- Linear tickets
- Jira backlog
- Custom API
Edit ralph-once.sh or ralph.sh to change the prompt and file sources.
Instead of committing to main:
- Create branch + PR per task
- Update external tracker
- Generate reports
Edit the prompt to change the commit strategy.
- Test Coverage - Write tests until coverage target hit
- Linting - Fix lint errors one by one
- Refactoring - Eliminate code duplication
- Bug Triage - Work through issue backlog
Edit the prompt in ralph-once.sh and ralph.sh to customize behavior.
Example for test coverage:
result=$($AI_COMMAND --permission-mode acceptEdits -p "\\
1. Run test coverage report. \\
2. Find the file with lowest coverage. \\
3. Write tests to improve its coverage. \\
4. Commit your changes. \\
If coverage is above 90%, output <promise>COMPLETE</promise>.")- Start with
ralph-onceto build intuition - Keep tasks small and focused in your PRD
- Review commits between iterations
- Use Docker sandbox for safety
- Cap iterations to prevent runaway costs
- Be specific in your PRD about acceptance criteria
- The AI works best with clear, testable requirements
Make sure you ran ./setup.sh and that ~/bin is in your PATH:
echo $PATH | grep "$HOME/bin"If not, add it:
# For bash
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
# For zsh
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.zshrc
source ~/.zshrcCheck that your git is configured:
git config user.name
git config user.emailSet them if missing:
git config --global user.name "Your Name"
git config --global user.email "your@email.com"Make sure you have the AI CLI tools installed:
# Check if installed
which claude
which codex
which geminiIf not found, install them:
- Claude: https://docs.anthropic.com/en/docs/claude-code
- Codex: Follow OpenAI Codex installation instructions
- Gemini: Follow Google Gemini CLI installation instructions
Test the commands manually:
# Test each AI
claude --help
codex --help
gemini --helpThe scripts use these exact command names. Make sure they're in your PATH.
To use a different AI CLI, you'll need to modify the scripts:
- Add your AI to the case statements in
ralph-once.shandralph.sh:
case $AI_COMMAND in
claude)
claude --dangerously-skip-permissions -p "$PROMPT"
;;
gemini)
gemini --yolo "$PROMPT"
;;
codex)
codex exec --dangerously-bypass-approvals-and-sandbox --enable web_search_request "$PROMPT"
;;
myai)
myai --auto-approve --non-interactive "$PROMPT"
;;
*)
echo "Unknown AI command: $AI_COMMAND"
exit 1
;;
esac- Update
.ralphrcwith your AI command name:
# In .ralphrc
AI_COMMAND=myaiYour custom AI should:
- Auto-approve code edits and commands
- Run in non-interactive mode and output to stdout
- Support reading files with
@filenamesyntax
Ralph technique by Geoffrey Huntley
implementation based on Matt Pocock guide
MIT
