← All posts

AI tool reviews › Ways of working

What is the Ralph loop? Trying the ralph-loop plugin

The Ralph loop, or Ralph Wiggum technique, feeds an AI coding agent the same prompt until the work is done. How the official plugin works, and what I saw.

If you follow what people write about AI coding agents, you’ll run into the name Ralph fairly often. Posts explaining the “Ralph Wiggum technique” turn up all over, and Claude Code’s official plugin list includes one called ralph-loop. Perhaps it seems a little odd at first that a cartoon character’s name ended up on a developer tool.

The Ralph loop is a technique where you keep feeding an agent the same prompt until the work is done. Developer Geoffrey Huntley introduced it in a blog post on July 14, 2025, and in its purest form, he says, it’s one line of shell that feeds the same prompt file to an agent forever. Anthropic turned the technique into a Claude Code plugin, ralph-loop, and put it in its official marketplace. A plugin is a bundle that adds features such as commands and hooks to Claude Code, and a hook is a command Claude Code runs on its own at a set moment. According to Claude Code’s official plugin list statistics, the plugin had 199,259 unique installs as of October 16, 2026, which put it 15th of the 315 on the list.

Where the name and the original loop come from

The name comes from Ralph Wiggum, the character from The Simpsons. When Ralph comes home bruised from falling off the slide, Huntley says, you put up a sign telling him to slide down, not jump. In the same way, you tune the agent by adding a sign to the prompt every time it makes a mistake. He also calls the technique “deterministically bad in an undeterministic world,” meaning its defects can be spotted and fixed through the prompt.

The post keeps saying to give each round one thing to do. That’s because you only have about 170k tokens of context window, and the more of it you use, the worse the results get. And since every round starts with a new context window, he says to have the agent write down what the next round needs to know in the plan file and the docs. Of course, Huntley also says engineers are still needed. He adds that he himself wouldn’t use Ralph in an existing codebase, and that it works best for getting a new project about 90% of the way there.

The official plugin first arrived in the Claude Code repository on November 16, 2025, under the name ralph-wiggum, and on January 6, 2026, it was renamed to ralph-loop. The commit that renamed it gives legal guidance to avoid trademark concerns as the reason.

What’s in the plugin and how one round runs

ralph-loop has no skills or MCP servers. It’s three commands, one Stop hook, and one setup script. The commands are ralph-loop to start a loop, cancel-ralph to stop it, and help to explain it, and since they’re plugin commands, they carry the plugin’s name in front, as in /ralph-loop:ralph-loop. Only the one-line description of each command sits in context day to day, so the statistics above estimate 46 to 89 tokens per turn, and 1,136 to 1,732 tokens when you call a command. The Stop hook, though, runs every time Claude finishes a response in a session where the plugin is on, and it exits right away when no loop is running.

When you start a loop, the setup script creates a state file called .claude/ralph-loop.local.md in the current folder and writes down the round count, the round limit, the promise phrase, and the prompt. After that, every time Claude finishes a response, the Stop hook checks, in order, whether the round limit has been reached and whether Claude’s last text in the transcript file contains the promise phrase wrapped in a promise tag. If either is true, it deletes the state file and lets Claude stop. Otherwise, it bumps the round count and sends the same prompt back. If you run the setup script and the hook by hand, without Claude, you can see exactly that.

bash ralph-loop/scripts/setup-ralph-loop.sh "Fix the first failing test." \
  --completion-promise "ALL TESTS PASS" --max-iterations 3 > /dev/null
printf '%s\n' '{"role":"assistant","message":{"content":[{"type":"text","text":"One test still fails."}]}}' > t.jsonl
echo '{"session_id":"","transcript_path":"t.jsonl"}' | bash ralph-loop/hooks/stop-hook.sh
{
  "decision": "block",
  "reason": "\nFix the first failing test.",
  "systemMessage": "🔄 Ralph iteration 2 | To stop: output <promise>ALL TESTS PASS</promise> (ONLY when statement is TRUE - do not lie to exit!)"
}

According to the Claude Code hooks docs, when a Stop hook returns "decision": "block", Claude doesn’t stop, and it receives the reason as the reason it should keep going. ralph-loop puts the original prompt, unchanged, in that spot, so Claude gets the same instructions again in the same session, along with the files it already changed and the whole conversation so far. cancel-ralph stops a loop by deleting this state file. Also, the hook checks the round limit before it checks for the promise, so if the promise shows up in the last allowed round, the record says the loop ended on the round limit.

What happened when I ran it headless

Now let’s try it with a real agent. For the test, I wrote slugify(), which turns a post title into a URL slug, plus three tests. The first version only lowercases the title and swaps spaces for hyphens, so two of the tests fail. Following Huntley’s principle, the prompt asks the agent to fix only one failing test at a time. That way the work can’t finish unless the loop feeds the prompt back in. Instead of installing the plugin, I loaded the downloaded folder for this run only with --plugin-dir.

TASK='Run python3 -m unittest. If a test fails, fix only the first failing test in slug.py, then run the tests again. Reply with <promise>ALL TESTS PASS</promise> only if every test passes.'
claude -p "/ralph-loop:ralph-loop \"$TASK\" --completion-promise \"ALL TESTS PASS\" --max-iterations 3" \
  --plugin-dir ../claude-plugins-official/plugins/ralph-loop --model haiku \
  --allowedTools "Edit" "Bash(python3 -m unittest*)" --max-budget-usd 1 \
  --output-format stream-json --verbose --include-hook-events < /dev/null > with.jsonl

As the headless docs describe, putting a command name in the -p prompt runs plugin commands too. For comparison, I ran the same command without --plugin-dir, passing only -p "$TASK", and both runs used a fresh copy of the same folder. In the actual runs, I added --setting-sources local --strict-mcp-config so this machine’s personal settings stayed out, plus a 10-minute time limit. Below is the output of a script that summarizes both stream-json files round by round.

== without.jsonl
round 1  context 19,079 tokens  edit: return "-".join(title.lower().split())
         tests: FAILED (failures=1)  promise in reply: no
         Stop hook: (none)
total: 5 turns, 12.2 s, $0.0036, output 1,379 tokens
== with.jsonl
round 1  context 20,068 tokens  edit: return "-".join(title.lower().split())
         tests: FAILED (failures=1)  promise in reply: no
         Stop hook: block, Ralph iteration 2
round 2  context 23,864 tokens  edit: return "-".join(re.sub(r"[^\w\s-]", "", title.lower()).split())
         tests: OK  promise in reply: yes
         Stop hook: block, Ralph iteration 3
round 3  context 25,745 tokens  edit: (no edit)
         tests: OK  promise in reply: yes
         Stop hook: 🛑 Ralph loop: Max iterations (3) reached.
total: 12 turns, 24.9 s, $0.0065, output 3,114 tokens

Without the plugin, Claude fixed one test and stopped. With the plugin, the Stop hook fed the prompt back twice, and in round 2 all three tests passed. In exchange, it took about twice the time and cost, and the context at the start of each round grew from 20,068 tokens to 25,745. That’s because earlier rounds pile up in the same session. The run without the plugin has the same shape as one round of a shell loop, so a shell loop would have started each round fresh at a little over 19,000 tokens.

The part worth a closer look, though, is the end of round 2. Claude confirmed the tests passed and wrote the promise phrase, but the hook didn’t recognize it, so a third round ran. Round 3 changed nothing, and the loop ended on the round limit. When I fed that reply into the hook by hand, it found the promise just fine, so the matching logic wasn’t the problem. That’s why I ran it again with a copy of the hook changed to record what it read. At the end of round 1, what the hook had read from the transcript file was a sentence from before the reply that had just finished. The hooks docs also say the transcript file may not yet contain the final message at Stop time, and suggest using last_assistant_message from the hook input instead.

That traced run found the promise in round 2 and ended, but both runs with the official plugin as is (one with slightly different prompt wording) missed the round-2 promise. The same symptom has been open as issue #1682 since May 2026. Of course, a few small runs with haiku can’t be read as a benchmark.

How it differs from the shell loop and other implementations

Approach One round is It ends when
Huntley’s shell loop A new process, fresh context A person stops it
ralph-loop plugin The next turn in the same session The promise phrase or the round limit
snarktank/ralph A new process, fresh context A COMPLETE promise or the round limit (default 10)
Claude Code /goal The next turn in the same session A separate model judges the condition met

The biggest difference is whether each round starts with fresh context. The plugin’s README explains that the loop runs inside your current session, so you don’t need an outside shell loop, while Huntley’s post assumes a new context window every round. At the top of his post, he also links a video captioned as explaining why the Claude Code plugin “isn’t it.” I haven’t watched the video, so I won’t pass along its argument.

snarktank/ralph, which follows the shell-loop approach, had 22,076 GitHub stars as of October 28, 2026. Once you turn a product requirements document (PRD) into small stories in prd.json, ralph.sh starts the agent fresh each round and works through the stories one at a time. That said, when it runs Claude Code it skips every permission check with --dangerously-skip-permissions, which is worth knowing before you use it. Claude Code’s built-in /goal keeps turns going in the same session as well, but a separate small model judges the condition after every turn.

Where it fits, where it doesn’t, and what it costs

The plugin’s README says it suits work with clear success criteria that tests or linters can verify automatically, and doesn’t suit work that needs human judgment or design decisions, or work with unclear success criteria. As in the example above, a loop earns its keep when a machine can confirm the finish line.

There are costs to accept, too. The first is cost. Each round sends the whole conversation so far back in, so even three rounds read 197,025 tokens from cache, nearly three times the 70,691 of the run without the plugin.

The second is a loop that never ends. The default for --max-iterations is no limit. Claude Code does end a turn after Stop hooks block eight times in a row, but that count resets every time Claude calls a tool, so it won’t stop a loop that keeps running tests. In an interactive session, you can interrupt with Esc and then call cancel-ralph, though I checked that part only in the source and the docs.

The third is repeating the same mistake. The prompt never changes, so a misleading instruction produces the same error every round. That’s probably why Huntley, in a follow-up post, urges you to watch the loop and fix the failures you see. And the judgment that the work is done is only a sentence the model wrote. The hook never runs your tests itself.

Beyond that, the hook uses bash, jq, and perl, and the state file appears under your project’s .claude/ and is deleted when the loop ends. The license is Apache 2.0.

Installing it and a first thing to try

Anthropic’s official marketplace is registered for you the first time you open an interactive session. So inside a session, /plugin install ralph-loop@claude-plugins-official opens a review panel where you pick a scope, and from your shell you install and remove it like this (plugin install docs).

claude plugin install ralph-loop@claude-plugins-official
claude plugin uninstall ralph-loop@claude-plugins-official

If you’d like a taste before installing, you can download the official repository and load it for a single run with --plugin-dir, as in the experiment above. To start, I’d suggest a small task that has tests, a --max-iterations of about 3, and reading for yourself what changed in each round. I ran these experiments on October 28, 2026, on macOS with Claude Code 2.1.304 and ralph-loop 1.0.1 (commit f8c5e7a), and --model haiku ran as claude-haiku-5-5.

AI tools helped with the research for this post.