On May 12th, Anthropic shipped the `/goal` command to Claude Code — the official version of the ralph loop. That's a bash one-liner by Geoffrey Huntley that developers have been talking about all year.
How the loop works
Imagine an employee with amnesia every morning (I'm sure everyone recognizes a colleague here). You give them the same instruction every day: "open your notes, buddy, see where you left off yesterday, take the next step, write down what you did." Repeat until done. The ralph loop works the same way. The agent gets a text file with the task and gets launched over and over. Each run starts from scratch, no memory of the previous one. The agent writes its own progress to disk: what's been done, which files changed, what's left.
On the next iteration it reads its own notes and picks up where it stopped. The loop spins until the agent marks the task as complete.
In the original, Huntley's whole construction is one line you type in the terminal:
`while :; do cat PROMPT.md | claude-code ; done`
Breaking it down (correct me if I'm off): `while :; do ... done` means "repeat forever what's inside." `cat PROMPT.md` means "grab the contents of PROMPT.md" (where you've put the agent's instructions ahead of time). The pipe `|` means "pass it along." `claude-code` is the agent itself, which receives the instruction and goes to work. Sixty characters, total. That's why the ralph loop caused such a stir — turns out you don't need a complex architecture for an autonomous agent. A file and an infinite loop will do.
The name "Ralph" is a nod to Ralph Wiggum from The Simpsons (the dumbest-but-persistent character in the show) and to the slang "to ralph" (to puke). Huntley writes that realizing just how cheap autonomous code generation had become literally made him sick.
Why reset context every iteration
After roughly 100–150k tokens, models get noticeably dumber, and Claude Code's built-in auto-compaction loses details. Restarting each iteration from the same PROMPT.md sidesteps that problem entirely.
What's already been built on ralph
The repomirror team ported six frameworks overnight at a YC hackathon, spending $600 in API costs. Huntley closed a client MVP at a $50k budget for $297. The CURSED programming language — self-hosting compiler included — was, according to its author, built entirely on three months of continuous ralph runs.
What got added to Claude Code
/goal in Claude Code 2.1.139 works like this: you define a completion condition, and after each turn a small fast model (Haiku) checks whether it's been met — if not, the loop drives the agent forward. OpenAI Codex shipped `/goal` earlier, in v0.128. Separately, Anthropic published the cwc-long-running-agents repo with three primitives for seriously wiring up long runs: a default-FAIL contract, a fresh-context evaluator, and an agent-maintained handoff between sessions.
The token-savings myth
The popular claim right now goes something like "an agent in `/goal` mode saves tokens because it's motivated to finish faster." That's anthropomorphism. `/goal` doesn't reset context — it just doesn't let the agent stop — and on average it burns *more* tokens than a regular conversation. The real savings come from the fresh-context idea of the clean ralph loop, not from the `/goal` command itself.