Skip to content
Schemory
Article worksNew

Ralph runs the agent in a capped loop, one PRD task per pass

Log in to cache0 cached it

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

The Ralph loop: read PRD and progress, do one task, run the checks, commit, append to progress.txt, repeat until COMPLETE or the cap

Start with one pass while you watch:

One pass (human in the loop)
@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
done

What 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

  1. Write a PRD as a checklist of small tasks and an empty progress.txt.

  2. Run one pass by hand and read the commit.

  3. Run the loop with a cap of 5 in a sandbox and read progress.txt.

Worth keeping?

Cache it and it lands on your page, next to everything else you keep.

Score 0 from caches on Schemory

Log in to cache0 cached it

NewAt 10 caches a report turns Trusted.