Documentation Index
Fetch the complete documentation index at: https://mintlify.com/snarktank/ralph/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Theralph.sh script is the core orchestrator that runs AI coding tools (Amp or Claude Code) repeatedly until all PRD items are complete. Each iteration spawns a fresh AI instance with clean context.
Usage
Basic Examples
Command-Line Options
Selects which AI coding tool to use for iterations.Valid values:
amp- Uses the Amp CLI (default)claude- Uses Claude Code
--tool amp--tool=amp
The script will exit with code 1 if an invalid tool name is provided.
Maximum number of iterations Ralph will run before stopping.Specified as a positional numeric argument. If all tasks complete before reaching the maximum, Ralph exits early with code 0.
How It Works
Initialization
Whenralph.sh starts, it:
- Parses command-line arguments to determine tool and max iterations
- Validates the tool choice (must be ‘amp’ or ‘claude’)
- Checks for branch changes and archives previous runs if needed
- Initializes progress tracking in
progress.txt
Archive Management
Ralph automatically archives previous runs when the branch name changes:The branch name is read from
prd.json and tracked in .last-branch. When a new branch is detected, the previous run’s files are copied to the archive directory before starting the new run.Iteration Loop
Each iteration:- Displays iteration number and selected tool
- Spawns a fresh AI instance:
- Amp: Runs
cat prompt.md | amp --dangerously-allow-all - Claude Code: Runs
claude --dangerously-skip-permissions --print < CLAUDE.md
- Amp: Runs
- Captures all output (stdout and stderr)
- Checks for completion signal (
<promise>COMPLETE</promise>) - Continues or exits based on completion status
Completion Detection
The script searches each iteration’s output for the completion signal:Exit Codes
All tasks completed successfully before reaching max iterations.Ralph detected the
<promise>COMPLETE</promise> signal in the output.One of the following occurred:
- Invalid tool name provided (not ‘amp’ or ‘claude’)
- Reached max iterations without completing all tasks
- Check
progress.txtfor the current status
File Structure
Ralph interacts with several files in its script directory:| File | Purpose |
|---|---|
prd.json | Task list with user stories and completion status |
progress.txt | Append-only log of learnings and context |
prompt.md | Prompt template fed to Amp |
CLAUDE.md | Prompt template fed to Claude Code |
.last-branch | Tracks the last branch name for archive detection |
archive/ | Directory containing archived runs |
Environment Variables
The script uses these internal variables:The script uses
set -e to exit immediately if any command fails, ensuring errors don’t compound across iterations.Dependencies
Required commands:jq- For parsing JSON inprd.jsonamporclaude- The selected AI coding toolbash- Version 4.0+ recommendedgit- For commit operations (used by AI tools)
Output Format
Ralph produces structured console output:Advanced Usage
Running in CI
Custom Tool Integration
To add support for a different AI tool, modify the iteration loop inralph.sh:
Troubleshooting
Script exits immediately with “Invalid tool”
Check that you’re using exactlyamp or claude (lowercase) as the tool name:
No output during iterations
Ensure the AI tool is installed and authenticated:Archive not created on branch change
Verify that:prd.jsoncontains a validbranchNamefield- The branch name actually changed between runs
- You have write permissions in the archive directory

