Loops Are Not a Way to Avoid Judgment
What running a brownfield migration on an agent loop actually took: four gates, a stateless driver, an adversarial skeptic, and where human judgment still had to sit — and why the bottleneck moved from attention to judgment.
What I described in How I Use Claude Code was agentic engineering, the term Andrej Karpathy suggested. I plan the architecture to write better specs, and I review every diff like a senior reviewing a junior’s PR. It works, but I am the bottleneck. Every commit the agent makes needs my attention as it happens. Review time replaced typing time; the work still moves only as fast as I review.
Loop engineering is a way to move that bottleneck.
Why loops, and why now
Boris Cherny, head of Claude Code: “I don’t prompt Claude anymore. I have loops running that prompt Claude… My job is to write loops.” Addy Osmani coined the term in June 2026: “Loop engineering is replacing yourself as the person who prompts the agent. You design the system that does it instead.”
I came at this from a lightning talk by Valerii Iatsko, a Google software engineer who has been hardening loops one failure at a time. He starts where the technique started.
Ralph is one line in its purest form:
while :; do cat PROMPT.md | claude-code ; done
The driver consults no state, has no stop condition, and no gate. It worked, which is the surprising part and the reason anyone took it seriously.
What it costs is PR #513, a run he cites. In August 2025 a team pointed a Ralph loop at their own frontend, and six hours produced +19,392/−1,367 across 131 files. It never shipped. A change that size never reached review, and while it sat, main kept moving until, in Iatsko’s words, “the conflicts outgrew the refactor.” The PR was closed without merging. The team’s fix was to run the loop once a night, with a diff small enough to review over coffee and merge the same morning.
Why is this a thing now and not a year ago? Two things changed, and only one of them is tooling.
The models crossed a threshold. What matters now isn’t raw intelligence. It’s staying on task for hours. A year ago, an agent left alone for an hour drifted. Today’s frontier models can work through a long task on their own, gathering context, building and verifying their own work before they answer. That is the precondition for a loop: an iteration only means something if the agent can hold a goal long enough to finish a unit of work.
The second change is tooling. Ralph’s one-liner had none of the pieces that make a loop safe; you built each one yourself and maintained it forever. Claude Code and Codex now ship them: automations, worktrees, skills, connectors and sub-agents. The stop condition comes built in too. In Claude Code, /goal keeps the agent working until a condition you wrote holds. Each time it tries to stop, a separate model checks that condition, and it reads the transcript, not the work.
Both changes matter, but they do different jobs. Better models are why a loop is worth running. Each iteration can now finish a real unit of work. They don’t decide whether that work ships. A new model wouldn’t have saved PR #513. It would have produced the same unreviewable diff, only faster. What that run lacked was outside the model: a pace set by how fast people could review and merge what it produced.
Everything that broke — for them then, and for me since — was harness, which is everything around the model. As Osmani puts it, loop design is harder than prompt engineering, not easier, because the leverage point moved from the prompt to the system around it.
flowchart LR
subgraph A["agentic engineering"]
a1[spec] --> a2[agent implements] --> a3["human reviews EVERY diff<br/>(real-time attention)"] --> a2
end
subgraph B["loop engineering"]
b1[design the loop + gates once] --> b2["loop: read state → build →<br/>check → record"] --> b2
b2 --> b3["human judgment at DESIGNED gates:<br/>rulings · merge"]
end
A -->|"the bottleneck relocates"| B
What I actually built
Some context first. Cusflux collects tariff data from seventeen countries, each with a legacy crawler pipeline. We are migrating them onto a shared collection framework: one crawler runtime and one CLI for all seventeen. This is exactly the work a loop suits: recurring and checkable. Every migration passes four gates, in this order:
- Unit tests
- Test crawl: a small live crawl against the real government site
- Database diff: the new output compared row by row with what production holds: rows added, removed or changed, where an unexplained removal or rate change blocks the merge
- Skeptic: an adversarial re-verification in a fresh session
Osmani describes an agent as a model plus a harness: files, tools, memory, skills, sandboxes, permissions, observability and recovery. Mine took its shape from the work.
The work is brownfield. Seventeen legacy pipelines whose real behavior nobody wrote down. That is why the database diff compares the new output with what the legacy pipeline actually loaded, rather than with a specification: that data is the only surviving record of what the pipeline does.
Trust lives in repo artifacts, not in any agent’s memory. Every iteration starts with an empty context and rebuilds its picture of the work from files committed to the repo. Before touching code it reads three of them:
- Playbook: the migration procedure, including the rules the loop may not change without a written human decision.
- Status table: one row per country. Its key column says where that country stands: not started, in progress, blocked or migrated. The loop reads it to decide whether to work on a country at all, and again to decide when to stop.
- Brief: a country’s record of what its data does and every decision taken about it.
The empty start is deliberate. Each iteration can see only what the last one committed, so its claim to be done can be checked.
The stronger reason is answerability. An agent that runs for hours makes real decisions along the way, and most of them leave no record. Osmani puts the cost of rebuilding that chain afterwards at “hundreds or even thousands of human hours,” which in practice means nobody does it. So committing the state isn’t only how a stateless loop resumes. It is the only way anyone can answer for what the loop did, and it has to be designed in from the start.
Around all this runs the driver, a bash loop like Ralph’s one-liner with a stop condition added. It never merges, never loads data into production and never runs the skeptic. It only decides when to stop. Here is what it checks first:
# scripts/migration_loop.sh — the two signals
claims_migrated() {
grep -Eq "^\|\s*$COUNTRY\s*\|[^|]*\|\s*migrated\s*\|" "$WT/docs/migration/status.md" \
&& (cd "$WT" && python scripts/check_migration_status.py --check)
}
The loop stops cleanly only when two signals agree. The status table says whether the country is migrated, and a separate script checks that claim against the code. Either signal alone is the unverified “done” the playbook warns about. Even together, they only read files the session wrote. So when both agree, the driver runs the unit tests itself. If they fail, the loop ends there with a message that a human is needed. Another iteration couldn’t fix them, because the migration skill stops working on a country once its status says migrated.
The session that builds never verifies its own work. Verification runs as /verify-migration, in a fresh session with no memory of the build. It re-runs the database diff itself. It runs the code under review over the crawl’s raw records again and checks that the result matches the stored evidence. Then it builds records meant to break that code. The skeptic’s own instructions, quoted from the skill file:
You are the skeptic, not the maker. Your job is to DISPROVE this migration. […] A model grading its own work gets agreeable — you are not grading your own work; act like it.
The four gates are not four copies of the same check. Each one looks at what the gate before it let through, and each has caught at least one thing the gate before it passed.
Failures are what turn the loop into a feedback system instead of a pipeline. When the unit tests or the test crawl fail inside a session, the work goes back into the loop with the failure written down. The next iteration starts from a written finding instead of someone’s memory. When the database diff or the skeptic fails, the work comes to me, in writing. The loop ends before either of those two runs.
The forward path (read state, choose, run, check, record) is the easy part to automate. The paths back are harder, because without a mechanism each of them ends with a human noticing something. Documentation drifts until someone reads it. A crawl keeps failing after the site changes, and only its retry counters show it. So most of what I built is not the loop. It is a mechanism for each return path, in the place where a person would otherwise be:
- a checker that fails the tests when the status table disagrees with what is actually in the repo
- a circuit breaker that stops a run when its failures come in a burst, instead of letting it burn through its retries
- a merge check that fails unless the skeptic’s newest verdict is a PASS on the latest commit
- a watcher that tells me when a long crawl ends or stalls, so I don’t have to go and look
Read the diagram below for its shape, not for the individual boxes:
flowchart TB
subgraph loop["driver — migration_loop.sh (fresh session each iteration)"]
A["fresh agent<br/>claude -p /migrate-country"] --> B{"unit tests +<br/>test crawl green?"}
B -->|not yet| A
B -->|"blocked on a genuine<br/>human decision"| J["record it (brief + status)<br/>and STOP"]
B -->|green| C["flip status.md row<br/>(same commit as evidence)"]
C --> D{"two-signal stop:<br/>row says migrated AND<br/>check_migration_status --check"}
D -->|"no, iter < MAX"| A
D -->|yes| R{"driver re-runs<br/>the unit tests"}
R -->|pass| E["exit 0 — handoff line to human"]
R -->|fail| R2["exit 1 — human needed"]
D -->|MAX_ITER| F["exit 1 — for long-crawl<br/>countries this IS completion:<br/>build half done, ops track next"]
end
J --> K["human rules (written,<br/>dated, in the brief)"] --> A
E --> G["skeptic: /verify-migration<br/>fresh context, prove-wrong"]
F --> G2["ops track: full crawl +<br/>database diff"] --> G
G --> H{"check_skeptic_verdict.py:<br/>newest verdict PASS<br/>at branch HEAD?"}
H -->|no| G
H -->|yes| I["human: merge<br/>('automate the merge last,<br/>once it's boring')"]
X["return paths (mechanized, not noticed):<br/>status checker · circuit breaker"] -.-> loop
W["watcher: tells me when<br/>the full crawl ends or stalls"] -.-> G2
The misconceptions
Building this cured me of the following beliefs:
“Loop engineering means removing the human.” The loop I built has human decisions designed into it. China’s build ran in a day and stopped for me four times, each time on purpose:
- a proposal run that drafted the brief, built nothing, and waited for my rulings on eight open questions about the data
- the go-ahead to launch
- a ruling in the middle of the run, on 38 rate strings the validator refused
- the order to start the full crawl
So a human is still involved. What changed is where my judgment goes: into a few decisions planned in advance, instead of into watching for alarms.
Those decisions weren’t yes or no. Osmani lists six possible answers: ship, block, redirect, narrow the response, add a guardrail, or reject. Saying yes to the full crawl was easy. The decisions that took real thought were the other kinds: one added a guardrail the loop has to respect from then on, one marked the country blocked until I ruled, and one narrowed how much of the site a crawl covered. So my job isn’t approving the work. It’s deciding what kind of answer the evidence calls for.
“Write the rule down and the loop will follow it.” A rule nothing enforces is only a preference. The skill every iteration starts from says it plainly: “Never run collection load / --load during a migration.” I didn’t trust that sentence, so the driver also passes a deny rule, Bash(* --load*), on the command line. But the deny rule only checks the command’s spelling. Python’s argument parser accepts any unambiguous prefix of a flag, so collection run --country chn --scope 01 --l --db-e prod parsed as a load into production, matched no deny rule, and matched the rule that allows collection run. I enforce the rule in the program itself. It rejects shortened flags. A crawl started with --load stops before it begins unless the environment variable COLLECTION_ALLOW_LOAD is set to 1. The loop can’t set it, because the driver blocks any command that names the variable. Here is the check:
# utils/collection/__main__.py
def _require_load_authorization() -> None:
if os.environ.get(LOAD_AUTHORIZATION_ENV) != "1":
raise CollectionLoadError(
f"collection run --load writes to the database and is refused unless "
f"{LOAD_AUTHORIZATION_ENV}=1 is set in the environment. Run the crawl "
f"without --load, then load the finished run deliberately: "
f"collection load --run-id <run-id> --db-env <env>."
)
“‘Done’ means done.” When the loop says a country is done, that is only a claim, and I still have to check it. Twice, a later gate showed the work was not finished. On indonesia, the database diff caught crawl loss that the run’s own validation had accepted: 2,173 rows missing from five headings. A heading is a four-digit product category and the unit a crawl is divided into. A country has about 1,300 of them, each holding tens to hundreds of tariff rows. On china, the skeptic independently reproduced every number of a technically perfect migration, and failed it anyway, on record-keeping rather than on data.
What it produced, and what it cost
Two of my four gates wait for a human to start them. Checks belong inside the loop, where they produce evidence. The decision that the evidence supports belongs outside the loop, with me. The database diff and the skeptic are checks, but they run on the full crawl, and what a full crawl turns up in tariff data usually needs a decision. Some tariff rates come in shapes no one could list ahead of time, and some mean nothing until a person decides what they mean: 68¢/head, 10.2%+93.10 EUR/100 Kg, 238% but not less than 30.8¢each, 5% or 4.17 baht/kg, prohibited, See 9822.04.01-9822.04.03. Only the full crawl shows every shape a source uses, and the validator rejects any shape it hasn’t seen, so each new one waits for my ruling.
The checks inside the loop are weaker than they look. The loop runs the unit tests and the test crawl inside the session, so the model decides whether they passed. Between iterations, the driver checks a stop condition. It asks whether the work is finished and never whether the work is right. The driver runs it after the session ends, so in that sense it is independent. But it reads only what the iteration it judges has written. It confirms that the files exist and that the status table matches them. Once the stop condition holds, the driver re-runs the unit tests, but not the test crawl. The test crawl is long and live, so it stays in the session, where the model decides whether it passed.
Inside that boundary, on indonesia, one iteration produced a full migration and four commits in about two hours, and the next woke, verified it, and correctly stood down. I am not publishing a rate for that: build time is a property of each country’s site rather than of the loop.
Judgment arrived in one batch, which is the only reason any of this pays. On china, a validator refused 38 rate strings — currency-and-unit text no shared pattern could adjudicate without guessing. My playbook says that the validator should never be edited inside a migration without my written, dated decision, and the skeptic returns FAIL if a migration edits it without one. The loop followed that rule: it wrote up both options with a recommendation, marked the country blocked, and stopped. Its own log line was “stopped rather than inventing the decision.” In the same session it also found and fixed a real handler bug, and its log drew the distinction: “a real bug (not a business decision).” The next iteration started fresh, read the committed files, found no ruling, and stopped within two minutes.
I read all thirty-eight and ruled once; the loop implemented the ruling and revalidated against already-collected data without re-crawling anything. Thirty-eight is a batch one person reads in a sitting. Set it beside the 19,392 lines this essay opened with and the whole argument is in two numbers, sized either side of what a human absorbs in one go. The same design produced 114,075 changed rates at indonesia’s final gate. The diff that produced them runs itself; a person only starts it. What isn’t automated is sorting those rows into explained categories in writing before anything ships. That sorting is the judgment the evidence exists to feed.
Lost data looks the same as no data. When a heading comes back with no data, the handler can’t tell why. The heading may really be empty, or its page may have failed to load, for example after a network error. It records both the same way. China’s first full crawl reported every heading done and validation passing, but seven headings had come back empty, and 1,632 rows were missing. The database diff is the gate built to catch this: those rows would have shown up as removed, and every removed row has to be explained before a country counts as migrated. A second full crawl, which I had started to time the new four-worker setting, finished before the first one did, so comparing the two exposed the loss before the diff ran. I decide once, ahead of time, which headings really have no data, so that validation fails on any other heading that comes back empty, before the database diff runs. That check runs in the loop’s test crawls as well as in the full crawl.
The last gate blocked on two rows nobody could account for. At china’s merge the skeptic re-executed every figure from disk rather than reading my summary, down to a census of all 500,484 accepted rate strings, and reproduced every one of them. It returned FAIL anyway. The database diff showed 65 description rows removed. The brief explained them by class, but one class claimed fourteen codes and listed only twelve. The other two were explained only in my working notes, in a folder git ignores, so after the merge nobody could have found them. Unexplained removals block. The data was probably fine, and nothing established that it was, so I cured it: the full listing moved into the brief. The re-run passed.
Human is always in the loop
Loop engineering didn’t remove me from the loop. It moved me out of the inner one. Inside it, agents investigate, implement and verify. Outside it, I decide, verify, approve and own the result. Only evidence should cross that line. The database diff produces it after every full crawl. I explain what it shows, and only then does the skeptic check my explanations.
Outside the inner loop, Osmani names four loops a person belongs in. My work falls into those four, not into reviewing every diff:
- Constraints: the playbook, the invariants, the rules the loop cannot edit.
- Sampling: how much of the output the gates and the skeptic actually look at.
- Audit: what evidence gets kept, and whether the record of it is worth anything.
- Ownership: which part of the production boundary is mine — the rulings and the merge.
Everything in the inner loop is verifiable instead of trusted. That is the entire trade.
One step before every merge is human on purpose. The faster a loop ships code I didn’t type, the faster the code I don’t understand piles up. So every migration pull request carries a PR Contract, a fixed form that asks what changed and why, what each gate showed, which parts the loop generated, and where rows could silently drop. I fill it in, never the agent that built the migration, because writing the answers is the comprehension test.
The bottleneck didn’t disappear. It moved from my attention to my judgment. Loop engineering is the practice of spending that judgment where it matters.