Quick Reference¶
Everything you need at a glance. Bookmark this page.
CLI commands¶
ralph run my-ralph # Run loop forever (Ctrl+C to stop)
ralph run my-ralph/RALPH.md # Can also pass the file path directly
ralph run my-ralph -n 5 # Run 5 iterations
ralph run my-ralph -n 1 --log-dir logs # Single iteration with output capture
ralph run my-ralph --stop-on-error # Stop if agent exits non-zero or times out
ralph run my-ralph --delay 10 # Wait 10s between iterations
ralph run my-ralph --timeout 300 # Kill agent after 5 min per iteration
ralph run my-ralph --dir ./src # Pass user args to the ralph
ralph scaffold my-task # Scaffold a ralph from template
ralph scaffold # Scaffold in current directory
ralph --version # Show version
Full flag descriptions and examples → CLI reference
Directory structure¶
That's it. A ralph is a directory with a RALPH.md file. See Getting Started to create your first one.
RALPH.md format¶
---
agent: claude -p --dangerously-skip-permissions # (1)!
commands: # (2)!
- name: tests
run: uv run pytest -x
- name: lint
run: uv run ruff check .
- name: git-log
run: git log --oneline -10
args: [dir, focus] # (3)!
---
# Prompt body <!-- (4) -->
{{ commands.git-log }} <!-- (5) -->
{{ commands.tests }}
{{ commands.lint }}
Your instructions here. Use {{ args.dir }} for user arguments. <!-- (6) -->
- Required. The full shell command to pipe the prompt to.
-penables non-interactive mode,--dangerously-skip-permissionslets the agent work autonomously. - Optional. Each command runs every iteration and its output fills the matching
{{ commands.<name> }}placeholder. - Optional. Declares positional argument names. Named flags (
--dir,--focus) work without this —argsis only needed for positional usage. - Everything below the
---frontmatter is the prompt body. It's re-read from disk every iteration, so you can edit it while the loop runs. - Replaced with the command's stdout + stderr. Only commands with a matching placeholder appear in the assembled prompt.
- Replaced with the
--dirvalue from the CLI. Missing args resolve to an empty string.
Frontmatter fields¶
| Field | Type | Required | Description |
|---|---|---|---|
agent |
string | yes | Full agent command (piped via stdin). See agent configuration for supported agents. |
commands |
list | no | Commands to run each iteration |
args |
list | no | User argument names. Letters, digits, hyphens, and underscores only. |
credit |
bool | no | Append co-author trailer instruction to prompt (default: true) |
Command fields¶
| Field | Type | Default | Description |
|---|---|---|---|
name |
string | (required) | Identifier for {{ commands.<name> }}. Letters, digits, hyphens, and underscores only. |
run |
string | (required) | Shell command to execute (supports {{ args.<name> }} placeholders). Commands starting with ./ run from the ralph directory; others run from the project root. |
timeout |
number | 60 |
Max seconds before the command is killed |
No shell features in commands
Commands are run directly, not through a shell — pipes (|), redirections (>), and chaining (&&) won't work in the run field. Use a script instead: run: ./my-script.sh (scripts starting with ./ run from the ralph directory).
Placeholders¶
Command placeholders¶
- Replaced with the
testscommand's stdout + stderr, regardless of exit code. -
Replaced with the
git-logcommand's output. Only commands referenced by a placeholder appear in the assembled prompt — unreferenced commands still run but their output is excluded. -
Unmatched placeholders resolve to empty string
- Must be
commands(plural)
For details on placeholder resolution, see How it Works.
User argument placeholders¶
- Replaced with the
--dirvalue from the CLI. Missing args resolve to empty string. -
Replaced with the
--focusvalue from the CLI. -
Pass via
ralph run my-ralph --dir ./src --focus "perf"or--dir=./src(named flags) - Or positionally:
ralph run my-ralph ./src "perf"(requiresargs:in frontmatter) - Mixed:
ralph run my-ralph --focus "perf" ./src— positional args skip names already provided via flags --ends flag parsing:ralph run my-ralph -- --verbose ./srctreats--verboseas a positional value- See CLI reference → User arguments for full details on flag and positional parsing
ralph placeholders¶
{{ ralph.name }} <!-- (1) -->
{{ ralph.iteration }} <!-- (2) -->
{{ ralph.max_iterations }} <!-- (3) -->
- Ralph directory name (e.g.
my-ralph). - Current iteration number (1-based).
-
Total iterations if
-nwas set, empty otherwise. -
Automatically available — no frontmatter configuration needed
- Useful for progress tracking, naming logs, or adjusting behavior near the end of a run
- See How it Works for more on the loop lifecycle
The loop¶
Each iteration:
- Re-read
RALPH.mdfrom disk - Run all commands in order, capture output
- Resolve
{{ commands.* }},{{ args.* }}, and{{ ralph.* }}placeholders - Pipe assembled prompt to agent via stdin
- Wait for agent to exit
- Repeat
Stopping the loop¶
| Action | What happens |
|---|---|
Ctrl+C (once) |
Finishes the current iteration gracefully, then stops |
Ctrl+C (twice) |
Force-kills the agent process and exits immediately |
p |
Toggle live peek of the agent's stdout (on by default in an interactive terminal — press to silence, press again to resume) |
P (shift+p) |
Open full-screen peek — scroll the entire activity buffer. j/k line, space/b page, g/G top/bottom, q or P exits |
-n limit reached |
Stops after the specified number of iterations |
--stop-on-error |
Stops if agent exits non-zero or times out |
Live editing¶
- The prompt body is re-read from disk every iteration — edit the prompt while the loop runs (frontmatter is parsed once at startup)
- HTML comments (
<!-- ... -->) are stripped from the prompt — use them for notes to yourself
Common patterns¶
Minimal ralph¶
---
agent: claude -p --dangerously-skip-permissions
---
Read TODO.md and implement the next task. Commit when done.
Self-healing with test feedback¶
---
agent: claude -p --dangerously-skip-permissions
commands:
- name: tests
run: uv run pytest -x
---
{{ commands.tests }}
Fix failing tests before starting new work.
Read TODO.md and implement the next task.
Parameterized ralph¶
---
agent: claude -p --dangerously-skip-permissions
args: [dir, focus]
---
Research the codebase at {{ args.dir }}.
Focus area: {{ args.focus }}.
Debug a single iteration¶
Run on a branch¶
More patterns and real-world examples → Cookbook
Next steps¶
- Getting Started — set up your first ralph end-to-end
- How it Works — what happens inside each iteration
- Cookbook — copy-pasteable ralphs for common tasks
- Troubleshooting — common issues and how to fix them