Free playbooks in your inbox
analysis · Claude Code Loops

Are You a Loop Engineer or Still Babysitting Claude Code?

Find out whether you are doing loop engineering or still babysitting Claude Code, with two numbers from your own sessions. The rung audit scores turns per finished task and how often you repeat yourself, and it never parses a transcript file.

From the youcanbuildthings catalog ▸ Build-tested

Hello builders,

The day you hand Claude Code a task and come back to finished work is the day you stop being the bottleneck on your own repo. Most of us are further from that day than we think, because we remember the sessions that went well and forget the ones where we explained the package manager three times. Ask what is loop engineering and you’ll get twenty definitions, so I’ll give you one sentence and a scorer that tells you which rung you actually work on.

The best objection I’ve read came from someone who has built agents for a decade. u/fabkosta said he knows how agents, LLMs and agentic SDLC work, and still asked: “What is different here from iterative software development best practices already known for decades? … Am I missing something?” Seventy-three comments later, nobody had answered him properly.

So what is actually different? Here is the answer he was owed. A loop is iterative development where the iteration is run by something that cannot be trusted to report its own results. For forty years the thing inside your dev loop was a compiler or a test runner, and those tools tell you when they fail. The agent does not. I learned that the expensive way, when I left a loop running overnight and woke up to a summary claiming every test passed on a build that did not compile.

Where each rung breaks

The ladder people draw goes prompt, context, harness, loop. Watch one job, a failing test you want green, fall off each rung in turn.

Loop engineering ladder, one job and four rungs: Prompt, the message, breaks on scope; Context, the memory, breaks past 5 to 10 minutes of work; Harness, the machine, breaks on unattended runs; Loop, the system, breaks on cost. Caption: a loop is a while True with an exit condition a computer evaluates.

  • Prompt, the message: it breaks on scope. Once the fix touches four files, you are the one holding the plan in your head.
  • Context, the memory: a CLAUDE.md, skills and a plan file. It breaks past 5 to 10 minutes of work, or as one explainer put it, somewhere around step nine the agent forgets what it was doing.
  • Harness, the machine: hooks, subagents and worktrees. It breaks on unattended runs, because a harness shapes how the agent works and says nothing about when it is finished.
  • Loop, the system: it breaks on cost. One reader “Drained my entire weekly limit in 2 hours just to loop ‘You’re right, I lied’.”

Each rung fixes the failure of the one below and inherits everything underneath, which is why nobody gets to skip straight to loops. And the ordering is more than a picture that went around X. Sandeco Macedo’s paper on the practice puts it plainly:

“We position loop engineering as a new layer in the progression from prompt to context to harness to loop, and we argue, against the stronger headlines, that it does not retire prompt engineering; loop and prompt are distinct tools with distinct uses.”

He calls the thing you hand the agent a loop specification, and it has five parts:

  1. a trigger
  2. a goal
  3. a verification step
  4. a stopping rule
  5. a memory

Across the fifty real loops the paper codes by hand, 70% verify in the autonomous zone of his verification ladder and 74% name their terminal states, while automated triggering and durable memory lag behind.

A loop is a while True with an exit condition a computer evaluates. Take out the exit condition, the budget and the verifier, and what’s left is the four-line joke about has_bug() that got thirty-nine upvotes.

Get your two numbers

So which rung are you on? You have an opinion, and it’s probably one rung too high. We can measure two things over your last ten sessions instead: turns per completed task, and the share of your messages that repeat something the agent was already told. High turns with a high repeat rate means you are the context rung’s memory, and you’re paying for it in your own time.

There is an obvious way to do this, and the docs close the door on it. Sessions sit in ~/.claude/projects/ as JSONL, and Anthropic warns that the entry format “is internal to Claude Code and changes between versions, so scripts that parse these files directly can break on any release.” A parser that breaks quietly keeps printing numbers long after they stop meaning anything. So we copy the file and ask the session.

Transcripts are kept for 30 days by default, so first archive each one as it ends. Both scripts need jq on your path. Save this as .claude/hooks/rung-archive.sh and chmod +x it:

#!/usr/bin/env bash
# copies each finished session; never parses it
set -euo pipefail
ARCHIVE="${HOME}/.claude/rung-audit"
mkdir -p "$ARCHIVE/transcripts"
TRANSCRIPT=$(jq -r '.transcript_path // empty')
[ -f "$TRANSCRIPT" ] || exit 0
SESSION_ID=$(basename "$TRANSCRIPT" .jsonl)
cp "$TRANSCRIPT" "$ARCHIVE/transcripts/${SESSION_ID}.jsonl"
printf '%s\t%s\t%s\n' "$(date -u +%Y%m%dT%H%M%SZ)" "$SESSION_ID" "$PWD" >> "$ARCHIVE/sessions.tsv"

Register it on SessionEnd in .claude/settings.json, merged into any hooks object you already have, then check /hooks:

{ "hooks": { "SessionEnd": [ { "hooks": [
  { "type": "command", "command": ".claude/hooks/rung-archive.sh" }
] } ] } }

Scoring uses a supported interface: we ask each session about itself through --resume. Save just this function as ~/.claude/rung-audit/score-session.sh so you can rerun it later:

score_session() {
  claude -p --resume "$1" --output-format json \
    'Answer with JSON only, no prose: {"turns": <number of times the human sent
     a message>, "completed": <number of distinct tasks brought to a finished
     state>, "reexplained": <number of human messages that repeated information
     already given earlier in this session>}' | jq -r '.result'
}

Then, from your shell, total your last ten:

source ~/.claude/rung-audit/score-session.sh
cut -f2 ~/.claude/rung-audit/sessions.tsv | tail -10 | while read -r id; do
  score_session "$id"
done | jq -s 'reduce .[] as $s ({t:0,c:0,r:0};
        {t:(.t+$s.turns), c:(.c+$s.completed), r:(.r+$s.reexplained)})
       | {turns_per_task: (.t/.c), reexplain_rate: (.r/.t)}'

Score sessions while they’re still inside the retention window, because --resume reads the live session and your archived copy can’t be scored. Each pass costs a few cents, which the JSON will show if you ask for .total_cost_usd, so your first measurement of waste already has a price on it.

What does the number mean? My heuristic, and it’s my own because nobody has published a real one: above roughly six turns per completed task with a repeat rate above about one in five, you’re on the context rung. Under three with repeats near zero, either a harness is working for you or your tasks are too small to be interesting. I trust the change more than the value. Run it today, add an exit condition, a budget and a verifier, and run it again in a month.

The number will annoy you, and that’s exactly why it’s worth having.

Now go build something this weekend!

John Cook

Why trust this? Every youcanbuildthings guide is pulled from a build-tested book: code that ran in production before it was written down.