Ralph runs Claude Code in a loop until a backlog of stories is done. Each
iteration is a fresh claude -p (clean context); state persists on disk via
prd.json, progress.txt, and git history — so context never degrades across
iterations.
- From a project, drop the template in:
ralph-init(copies this dir to.ralph/). - Create and edit the backlog:
cp .ralph/prd.example.json .ralph/prd.json— list small, independently-verifiable stories, each"passes": false. - Work on a throwaway branch/worktree:
gwt new ralph/<name>. - Run:
./.ralph/ralph.sh [max_iterations].
- Unattended runs should use API billing (
ANTHROPIC_API_KEY) so they draw from the Agent-SDK/API budget instead of burning the interactive subscription's session/weekly caps. Each iteration is capped with--max-budget-usd(default$5; override viaCLAUDE_MAX_USD). - Always run in a sandbox/worktree and review the diff before merging.
- The flags here are a starting point — confirm them against
claude -p --helpfor your CLI version. For sanctioned unattended automation, prefer Anthropic's Claude Code Routines; the communityralph-loop-setupplugin is a maintained alternative to this hand-rolled loop.