An agent already runs a loop: model, tool, result, repeat. Loop engineering is building the loop around it: what starts a run, what state it reads, how its work is checked, what it writes down and when it stops to ask a person. You stop typing each prompt and start designing the system that decides when a prompt is needed.
Separate the inner loop from the outer loop
- Inner loop
- The agent doing the work: the model calls tools until it ends its turn or a guard stops it. See the agent loop.
- Outer loop
- The system that oversees it: triggers, state, verification, evals and human review.
- Loop engineering
- Designing the outer loop so the work moves when nobody is at the keyboard.
"Loops" was the word of the AI Engineer World's Fair in June 2026. The Latent Space recap puts the shift in exactly these terms: leading engineers now sit in an outer loop, overseeing mostly autonomous work in an inner loop, and building that outer loop is the human engineer's job. Boris Cherny, who leads Claude Code at Anthropic, said the same thing more bluntly that month: he no longer prompts Claude; loops he wrote do (collected with similar quotes in Cobus Greyling's write-up).
- work moves only while you type
- you re-explain context each time
- you are the verifier, by eye
- a schedule or event starts the run
- state carries context across runs
- tests and a checker verify; you review what is flagged
See where it sits: context, harness, loop
- Contextwhat one call should carry
- Harnesswhat one session can see, touch and check
- Loopwhat happens across sessions, with nobody watching
Each layer assumes the one below it. A loop around an agent with no tests to run, no permissions and no instructions file automates confusion faster. Get the layers in order: context engineering, then harness engineering, then the loop.
Assemble the parts of a loop
| Part | Job | In Claude Code |
|---|---|---|
| Trigger | start a run without you | /loop, scheduled tasks, GitHub Actions |
| Goal | a checkable end condition | /goal, a Stop hook |
| Isolation | parallel agents that don't collide | git worktrees, isolation: "worktree" |
| Knowledge | no run starts from day one | CLAUDE.md, skills |
| Connectors | act on real systems | MCP servers |
| Checker | the maker doesn't grade its own work | a subagent, tests, workflows |
| State | remember across runs | a state file, git, the issue tracker |
Every part except the trigger and the state already exists in a good harness. That is why loops are cheap to build once the harness is right, and miserable to build before.
Choose the trigger
/loop 5m check whether the deploy finished and tell me what happened
/loop check CI on my PR and address any review comments # Claude picks the interval
/loop 20m /review-pr 1234 # re-run a skill
/goal every call site compiles and npm test passes # turn after turn until true
/schedule # a cloud task: nightly, on API call or GitHub event
| Option | Runs on | Use it for |
|---|---|---|
/loop | your machine, open session | polling a deploy or a PR; at least 1 minute apart, expires after 7 days |
| Desktop task | your machine, no open session | recurring work that needs local files |
| Cloud task | Anthropic's cloud, fresh clone | nightly or event-driven runs with the laptop shut; at least 1 hour apart |
/goal | the current session | keep going turn after turn until a condition holds |
From the Claude Code docs on scheduled tasks, cloud tasks (research preview, formerly "routines") and /goal, read 21 October 2026.
Prefer events to polling where you can: a run started by a pull request or a CI failure does work every time, while a poll mostly finds nothing. Outside Claude Code the same trigger is a cron job or a queue consumer calling the Agent SDK.
Split the maker from the checker
- 02:00 triggernightly cloud task
- Read statewhat was open last run
- Fan outone worktree subagent per new PR
- Checkera second agent checks each review against the diff
- Act or flaglabel, approve, or brief a human
A nightly PR triage loop is the standard example. The maker reviews the PR; a separate checker, with different instructions and ideally a stronger model or higher effort, verifies the review is consistent with the diff and the tests. The implementer never grades its own homework, and that is what lets you walk away. Anthropic's long-running harness found the same failure without it: agents marked features done before testing them end to end. Claude Code's dynamic workflows run this fan-out-and-cross-check pattern across many subagents.
Write state the next run can trust
# LOOP STATE: pr-triage (updated 2026-10-21 02:14 UTC by run #212)
## In progress
- #4411 refactor auth middleware: checker found 2 failing tests; retry 1 of 2
## Done since last run
- #4402 docs typo: labelled, approved, merged (trivial-safe rule)
- #4407 bump lodash: CI green, approved; waiting for a maintainer to merge
## Needs a human (read these first)
- #4409 changes billing rounding; tests pass but the spec is ambiguous. Brief below.
## Tried and failed (do not repeat)
- #4398 auto-rebase: conflicts in schema.prisma; left for the author
A loop without state is a scheduled prompt: it redoes finished work and forgets its own decisions. A state file answers three questions on every read: what is in progress, what was tried and failed, and what is waiting for a human. Keep it short, rewrite it each run rather than appending forever, and commit it or keep it in the tracker, so a crashed run can resume (see agent durability).
Budget the loop before it runs
A loop multiplies whatever one run costs. Take a poll every 30 minutes, 48 runs a day. A full Sonnet 5.5 run that reads 30,000 tokens and writes 2,000 costs about $0.08. Gate it with a Haiku 5.5 check (5,000 in, 200 out) that starts the full run only when there is work, say 6 times a day:
Illustrative token counts; prices per million tokens: Sonnet 5.5 $2 in / $10 out, Haiku 5.5 $0.10 / $0.50. Caching the stable prompt prefix cuts both further.
Three rules follow. Triage cheaply and escalate only on work (tiered routing). Put a token or dollar ceiling on every run and log spend per run (agent cost control). And alert on a run that costs ten times the median: that is a stuck inner loop, not a busy day.
Keep a human in the outer loop
- Verification is a claim
- A checker raises confidence; it is not proof. Sample the loop's decisions and audit them.
- Comprehension debt
- The loop ships faster than you understand. Read the state file and the merged diffs on a schedule.
- Cognitive surrender
- The loop lets you stop exercising judgement. Build it like someone who intends to stay the engineer.
All three come from Greyling's write-up, and the World's Fair recap reports speakers split on whether loops are ready for unattended use at all. The design rule is concrete: every loop needs a hand-off path that it actually uses, and irreversible actions (a merge to main, an email to a customer, a refund) go through an approval gate, not a confidence threshold. The patterns for that gate are in approval gates.
A loop that never hands off: if "needs a human" has been empty for two weeks, it is either accepting nothing risky or everything. A maker that checks itself. State appended forever until it no longer fits in context. Polling every five minutes with a full agent run. No per-run cost ceiling. A loop built before the harness has tests it can run.
“How would you run this agent continuously in production?” Separate the loops. The inner loop has step, cost and time guards. The outer loop has a trigger (prefer events), a state store, an independent verifier, per-run budgets and alerts, and an approval gate for irreversible actions. Then say how you would know it is drifting: sampled audits and evals on its decisions (agent evaluation).
Your nightly loop's state file has had no "needs a human" items for three weeks, and merges are up. Good news?
Not necessarily. Either the loop only touches trivial work, or it is approving things it should flag. Sample its merged decisions, check the checker's pass rate, and make sure ambiguous specs and risky areas have a rule that forces a hand-off.
A loop polls GitHub every 5 minutes and starts a full agent run each time. The bill is high and most runs find nothing. What two changes do you make?
Trigger on events (a new PR, a CI failure) instead of polling, and where you must poll, run a cheap check first (a small model, or plain code) that starts the full agent only when there is work. Then cap the cost of each run.
Why should the checker be a different agent from the maker, and not just "the same agent, asked to review"?
The maker's context is full of its own reasoning and it tends to confirm its own work. A checker with a fresh context, different instructions (the spec and the tests, not the maker's plan) and ideally a stronger model or higher effort catches what the maker talked itself past.
- The inner loop is the agent calling tools; the outer loop (trigger, state, verification, hand-off) is what you engineer.
- Build it on a working harness: tests to run, permissions, instructions.
- Prefer event triggers; in Claude Code use
/loop,/goal, scheduled tasks or GitHub Actions. - A separate checker and a short, rewritten state file make unattended runs trustworthy.
- Budget per run, gate with a cheap model, and route irreversible actions to a human.