How to Write Loops with Claude Code

ingve1 pts0 comments

How to Write Loops with Claude Code - Karan Bansal

In July, Gergely Orosz asked X: can you share 'loops' you regularly use? I read the full thread across July 13-14: 182 replies at that point (it has kept growing since), about thirty on topic, and exactly one that linked a loop you could actually run, a config.ts in a repo. Everyone else described theirs in prose, down to the odd /loop one-liner, or dismissed the term ("a fancy word for cron jobs," 56 likes). The sharpest reply summarized the discourse: "Someone posts about loop engineering. Another developer asks what is it? They don't explain it. Repeat."

The question existed because in June, Boris Cherny, the creator of Claude Code, said the thing that launched a thousand blog posts: he doesn't prompt Claude anymore. He writes loops, and the loops prompt Claude. Within a week the idea had a name (loop engineering), a viral tweet past eight million views, and a wave of "complete guides" that were mostly the same two quotes reworded. Orosz later wrote his thread up himself, "based on ~210 replies, mostly from X and LinkedIn". It is a survey, not a build manual: it maps what people say they run, its loop lines arrive as quotes (Huntley's bash, OpenAI's /goal example, one engineer's flaky-test /loop), and half the analysis sits behind the paywall.

This post is the artifact that thread was missing: seven loops in the order to learn them, with the exact invocation, the check that decides done, the kill switch, and what survives your session. Then the unflattering parts: cost (a real $6,000 receipt), failures (with incidents), security. Everything comes from official docs, harness source, or my own transcripts; Method says which is which.

TL;DR

A loop is a trigger, a prompt, and a termination check.

Claude Code ships six primitives, differing on two axes: what fires the next iteration, and what survives your session (only committed files; Routines, per-account in the cloud, are the exception).

Learn them as a ladder; a seventh loop composes the six: /goal → /loop → bounded bash → Stop hooks → dynamic workflows → routines → the stack.

The termination check is the whole game: an agent graded on its own claims lies its way out, so verification must be a command that runs, not a vibe.

Cost is your wake interval versus the cache window. Unattended loops run in a container with hard caps. The only loop your team can inherit is the one you commit.

Type your first loop in the next 60 seconds

Open Claude Code in any repo with tests and type:

/goal all tests pass and lint exits 0; or stop after 20 turns<br>Claude keeps taking turns; a second model grades the condition after each one; /goal clear kills it. That is a loop. The other six are what it grows into, and this table is the menu:

I want to…Reach for

watch a loop work while I approve each step/goal Loop 1<br>re-check something on a timer while I work/loop 15m Loop 2<br>leave it building unattended, boundedbash loop.sh (Ralph)Loop 3<br>make "done" mean the tests actually rana Stop hookLoop 4<br>fan one task out across many files or agentsa dynamic workflowLoop 5<br>hand my team a loop they can runa dynamic workflow saved as /Loop 5<br>run it while my laptop is closed/schedule (a Routine)Loop 6<br>compose all of it into one machinethe stackLoop 7

Reference:<br>what survives your session<br>stop your loop from lying<br>add or remove the human<br>the $6,000 loop<br>how loops fail<br>before you leave it overnight<br>when not to loop

One provenance note, because it says something about this wave: the famous quote circulates in three wordings pinned to the wrong videos, so I checked the captions of all three recordings. It was said once, at Acquired Unplugged on June 2, at 11:42:

"I don't prompt Claude anymore. I have loops that are running. They're the ones that are prompting Claude and kind of figuring out what to do. My job is to write loops."<br>Boris Cherny, creator of Claude Code

A month earlier, at Sequoia's AI Ascent, he had described the loops themselves: one babysitting PRs, one keeping CI healthy, one clustering Twitter feedback every 30 minutes. Five days after the June quote, Peter Steinberger's paraphrase became the eight-million-view tweet; most people are quoting a paraphrase of a clip.

What a loop actually is

Cherny tells it as abstraction levels: you wrote code in an IDE, then you prompted agents (five or ten in parallel if you were aggressive), and now a small piece of automation decides what to tell the agent next until a condition holds. Code, then agent, then loop. Now the deflation: the technique is nearly a year older than the buzzword, and in its purest form it is one line of bash. July 2025, Geoffrey Huntley, the Ralph technique:

while :; do cat PROMPT.md | claude ; done

Feed the same prompt to the agent forever. Context resets every pass; the only memory is the files and git history the last pass left behind. Huntley delivered an MVP for a $50k contract on $297 of tokens this way, and documented everything that goes...

loop claude loops code prompt goal

Related Articles