Back to Blog

What Is the Ralph Loop? Agentic Coding, Deterministically Simple

AI Transformation Lead
  • Ralph Loop
  • Agentic AI
  • Loop Engineering
  • AI Agents
  • Agentic Programming
  • AIDLC
Recursive concentric-loop diagram illustrating the Ralph loop agentic coding technique

The most effective agentic coding technique of the last two years is also the dumbest looking. In July 2025 Geoffrey Huntley described running a coding agent inside a plain while loop and named it after Ralph Wiggum, the Simpsons character. His tagline captured the whole idea: deterministically simple in an unpredictable world. Feed an agent the same prompt over and over until the job is done. That is the Ralph loop, and it works better than techniques with ten times the machinery.

The mechanism

A Ralph loop is close to a one-liner. A shell loop spawns a coding agent, the agent reads a goal-prompt file from disk, picks one task, implements it against the codebase, and exits. Then the loop does it again. And again. The trick is what happens between iterations: each pass starts a brand new agent process with a clean context window. Nothing carries over in the model's memory. Everything that matters, the code, the progress, the decisions, lives in files and git history.

That inversion is the insight. Most agent setups treat the conversation as memory, which means they fight context rot: the window fills, the model forgets the early instructions, quality decays. The Ralph loop refuses to play. It keeps memory where memory belongs, on disk, and treats the model as a stateless worker that reads the current state, moves it forward one step, and hands off. The repository is the memory. The goal prompt is the only thing that persists.

Why "deterministically simple" beats clever

The appeal is not that the loop is smart. It is that the loop is dumb in a way that composes. A single agent run is unpredictable; it might do the right thing, might not. But run it a hundred times against a stable goal, with each run reading the accumulated progress and doing one more small thing, and the unpredictability averages out into steady advancement. You are not asking one agent to be brilliant. You are asking a stream of forgetful agents to each be slightly useful, and letting git accumulate the wins.

The results are hard to argue with. Huntley built an entire programming language this way for roughly $297 in model costs. Tools now package the pattern directly, from Vercel's ralph-loop-agent to snarktank/ralph, which runs until every item in a product requirements doc is complete.

The part everyone gets wrong

The loop is easy. The check is hard. An agentic loop is the simplest unit of useful agent work: do something, check the result, decide whether to continue or stop. The whole craft is in making the check real and defining when to stop. Skip that and the Ralph loop turns from a builder into a very expensive way to spin.

A loop with no real stopping condition either runs forever, burning tokens, or wanders off implementing things nobody asked for. The fix is the same discipline that makes any agentic work reliable: a precise goal, a verification gate the loop can actually run, and an explicit definition of done. This is why people who run Ralph loops seriously talk about loop engineering, not just loops. The engineering is in the check.

Where it fits

The Ralph loop is not a rival to spec-driven development or the AIDLC bolt. It is the same family. The goal prompt is a spec that persists across iterations. Each pass is a tiny bolt: read the state, do one thing, verify, exit. What the Ralph loop adds is a way to run that cycle unattended, letting the file system carry the memory so the model never has to.

Used with a weak check it is a toy. Used with a real verification gate and a tight goal prompt it is a genuinely new way to build software, one that trades a single clever session for a patient stream of simple ones.

For the layer that runs the loop safely, see what an agent harness is. For putting a goal prompt and a loop together into a working app, see the practical build guide, and for the unit of work underneath it all, what a bolt is.

Ralph is not smart. Ralph is relentless. In agentic coding, relentless wins.

X / Twitter
LinkedIn
Facebook
WhatsApp
Telegram
AI Engineering for B2B

Stuck between an AI pilot and a system your team can run?

I join your engineering team and build the agent layer alongside you, covering architecture, MCP integration, evals, and production deployment. When the engagement ends, your team owns the system and keeps shipping.

12+ years shipping production systems

Senior engineer turned AI specialist. React, Next.js, AWS, agent orchestration.

Dubai-based, working with B2B teams worldwide

Direct collaboration across UAE, Europe, and US time zones.

AI agent teams that ship, not demos that stall

Discovery, role design, MCP integration, evals, and production deployment.

Questions about this piece

Follow-ups readers ask most often about the argument above.

  • The Ralph loop is an agentic coding technique where a coding agent runs inside a plain while loop, reading the same goal-prompt file every iteration, doing one unit of work, and exiting. Each pass starts a fresh agent with a clean context window, and progress accumulates in files and git history rather than in the model's conversation memory. Geoffrey Huntley named it after Ralph Wiggum in July 2025: deterministically simple in an unpredictable world.

  • Because context windows fill up and degrade, while the file system and git do not. By writing state to disk each iteration and starting the next agent clean, the loop sidesteps context rot entirely. The repository becomes the memory, and the goal prompt is the only instruction that persists across passes.

  • For well-shaped, verifiable work, yes. Huntley used it to build an entire programming language for around $297 in model costs. It works when the goal prompt is precise and the loop has a real way to check progress and know when to stop. It fails when the check is weak, because an agent with no real stopping condition will loop forever or wander.

Get practical AI and engineering playbooks

Weekly field notes on private AI, automation, and high-performance Next.js builds. Each edition is concise, implementation-ready, and tested in production work.

Open full subscription page

Get the latest insights on AI and full-stack development.