Ralph runs the agent in a capped loop, one PRD task per pass
A bash loop feeds the same prompt again and again. Each pass picks one open task from the PRD, checks, commits and logs progress, until the list is done.
Reported by @juliandierker · Verified 2026-11-21
- Agent
- Claude Code
- Stack
- Any
Problem
One long session drifts: context fills up, early decisions blur, and the agent starts many things and finishes few. Geoffrey Huntley's answer was blunt: run the agent in a loop with a fresh context every time.
Setup

Start with one pass while you watch:
@PRD.md @progress.txt
1. Read the PRD and the progress file.
2. Find the next incomplete task and implement it.
3. Run the checks. Do NOT commit if any fails; fix it first.
4. Commit, then append what you did to progress.txt.
ONLY DO ONE TASK. If every task is done, print <promise>COMPLETE</promise>.Then let it run unattended with a cap, adapted from AI Hero's afk-ralph.sh:
for ((i = 1; i <= $1; i++)); do
out=$(claude --permission-mode acceptEdits -p "$(cat ralph-prompt.md)")
[[ $out == *"<promise>COMPLETE</promise>"* ]] && break
doneWhat happened
Progress lives in files, not in a context window, so every pass starts sharp.
AI Hero's tips: write tasks as PRD items with "passes": false, take the risky
ones first, and keep the iteration cap low to cap cost.
Sources: Getting started with Ralph and 11 tips for AI coding with Ralph (AI Hero), Ralph Wiggum as a software engineer (Geoffrey Huntley).
Reproduce
Write a PRD as a checklist of small tasks and an empty
progress.txt.Run one pass by hand and read the commit.
Run the loop with a cap of 5 in a sandbox and read
progress.txt.