The simplest practitioner version of a long-running agent: a bash for loop that re-prompts the agent until the work is actually done. Popularised by Geoffrey Huntley (who named it after Ralph Wiggum from The Simpsons — “me fail English? that’s unpossible”) and Ryan Carson. Anthropic adopted the same idea in their scientific-computing post.

The reference implementation is literally a bash script.

The loop

while not done:
    1. Pick the next unfinished task from a list (prd.json or equivalent)
    2. Build a prompt with the task, the relevant context, and any persistent notes
    3. Call the agent
    4. Run tests or other checks
    5. Append what happened to progress.txt
    6. Update the task list (done, failed, blocked)
    7. Go back to step 1

That’s it. No frameworks, no orchestrator, no message bus. A JSON file, a text file, and a shell loop.

Why it works

The reason is the same reason every long-running harness works: state lives outside the agent’s context.

  • prd.json is the plan
  • progress.txt is the lab notes
  • AGENTS.md is the rolling rulebook
  • the codebase + git history is the world the agent acts on

The agent itself is amnesiac, but the filesystem isn’t. Each iteration starts fresh and reads enough state from disk to keep going. The loop’s only job is refusing to stop.

This is the same file-as-state pattern from Context Window Management Strategies and Long-Running Agents - Initializer + Coding Pattern — just stripped to its minimum.

The “are you really done?” use

Ralph’s most common smaller use is as a liar detector: when the agent claims it’s finished, the loop kicks the agent back into context with the current state and asks if it’s really done. Anthropic’s scientific-computing harness uses this explicitly — a for loop that re-prompts on every “task complete” claim until the agent actually checks its own work and the answer survives challenge.

This is the cheapest possible defence against the premature-victory failure mode: instead of trusting the model’s self-grade, you make it earn the right to stop by surviving another full pass.

Compound Product: stacked Ralph loops

Ryan Carson’s Compound Product extends the idea by chaining multiple Ralph loops:

  • An analysis loop reads daily reports
  • A planning loop emits a PRD
  • An execution loop writes the code

This is roughly the open-source version of Anthropic’s planner / generator / evaluator triad — and of Cursor’s planner / worker / judge split. Different teams independently arrived at separate the role that decides what to do from the role that does it from the role that checks it. (See Long-Running Agents.)

Relationship to other patterns

  • Long-Running Agents - Initializer + Coding Pattern — Anthropic’s two-prompt pattern is the productised, opinionated version of Ralph. The init agent writes the artifacts the loop reads; the coding agent’s session bootstrap is the first half of each Ralph iteration.
  • Brain Hands Session Split — Anthropic’s Managed Agents is Ralph with the bash script replaced by a session log and a sandbox manager. Same shape, production-grade plumbing.
  • Cursor Planner Worker Judge — Cursor’s three-role architecture is Compound Product with the loops promoted to first-class roles.

Note

“You can build a working long-running agent in an evening with a bash script and a JSON file. Most of what Google and Anthropic have productized is the work of making this pattern recoverable, secure, and observable at scale.” — Addy Osmani

The bash version is not a toy. It’s the load-bearing pattern under all the productised versions.

OpenAI’s explicit citation

OpenAI’s Codex team explicitly names the Ralph Wiggum loop as the pattern they use to drive PRs to completion (see Harness Engineering at OpenAI):

“To drive a PR to completion, we instruct Codex to review its own changes locally, request additional specific agent reviews both locally and in the cloud, respond to any human or agent given feedback, and iterate in a loop until all agent reviewers are satisfied. Effectively this is a Ralph Wiggum Loop.”

This is the primary-source confirmation that the bash-script pattern is the same shape as the production-grade pattern. OpenAI’s version replaces the bash loop with agent-to-agent review orchestration, but the core mechanic (re-prompt until satisfied, state lives in artifacts the agent reads on each iteration) is identical to Huntley’s original.

When to use it

  • Personal projects, weekend prototypes, or any context where you control the machine the loop runs on.
  • As a test of whether long-running pays off for your task before you invest in a managed runtime.
  • As the outermost loop wrapping a more sophisticated harness — even Claude Code workflows benefit from a Ralph-style “are you really done?” wrapper for overnight runs.

When not to

  • Anything multi-tenant, anything touching production credentials, anything where the audit trail matters. Ralph has no identity story, no session log, no sandbox — those are exactly what Managed Agents and the Gemini Enterprise Agent Platform add.

Sources

  • Long-Running AI Agents — clearest explanation of the Ralph loop in context
  • Harness Engineering at OpenAI — Building a 1M-LOC Product with Codex — OpenAI’s explicit citation of the Ralph Wiggum loop in their production harness