Skip to content

Autonomous loop (Ralph, governed)

The Ralph loop (popularized by Geoffrey Huntley) is the simplest agentic-coding pattern there is:

Terminal window
while :; do cat PROMPT.md | claude -p; done

Re-run the agent over and over; each pass makes a little more progress, using files as memory, until the job is done. It’s effective — and unsafe on its own, because an unsupervised loop will happily build the wrong thing at full speed.

SpecForge turns that raw loop into governed autonomy. It already has everything a good loop needs, plus the one thing the raw loop lacks — a stop the human controls:

Ralph loop needs SpecForge provides
A durable ledger of progress tasks.md — a checklist of [ ]/[x] tasks, each traced to a requirement
File-based memory the committed specforge/ store (state.md, audit.md, artifacts)
A resume point /specforge:resume — “find the first unchecked item and continue”
A safety rail the gate — code edits are blocked until a human approved the spec + plan

In-session — Claude works the task list one task at a time:

/specforge:loop

Headless — the classic outer loop, gate-checked and iteration-bounded:

Terminal window
"${CLAUDE_PLUGIN_ROOT}/scripts/ralph-loop.sh" 25 # re-invokes `claude` per task until done

The headless runner refuses to start unless the spec + plan are approved, bounds itself with a max-iteration cap, and bails out when it stops making progress or a blocker is recorded.

  1. Nothing runs before approval — the loop inherits the gate.
  2. It executes a contract, not a vibe — it follows tasks.md; it can’t invent scope.
  3. It’s fully auditable — every ticked task and every stop is written to state.md / audit.md.
  4. It stops, it doesn’t spin — ambiguity becomes a recorded blocker and a halt, not a wrong guess at machine speed.

The pitch in one line: the Ralph loop’s speed, with a gate that keeps a human in the loop.