AI & automation · Guide
What is loop engineering, and when should an AI agent run in a loop?
Loop engineering is the design of the cycles in which an AI agent works on its own until a stop condition is met: what triggers the loop, how the agent checks its own result, when it stops and how much it may spend. It is an informal term that spread in mid-2026 among users of AI coding agents.
Master TimmUpdated on 6 min read
On this page
Where the term came from, and why it is still informal
The name appeared in June 2026 among users of AI coding agents. On June 7, Addy Osmani published a post defining loop engineering as no longer being the person who prompts the agent and designing the system that does it instead, crediting the shift to remarks by Peter Steinberger and Boris Cherny.
At the end of the same month, Anthropic's Claude blog opened a guide to loops by noting how much talk there is about loop engineering, or designing loops instead of prompting, and defined loops as agents repeating cycles of work until a stop condition is met.
There is no official definition, and the term overlaps with others: Osmani places the loop one floor above the harness, and LangChain treats loop engineering as a simple version of a graph. What is worth keeping is the practice behind the name.
The loop inside the agent and the loops around it
Every agent already runs an inner loop: it gathers context, acts through a tool, checks the result and repeats until there is nothing left to do. In the Claude Agent SDK, each round is a turn, and the loop ends when the model answers without calling a tool. Loop engineering is mostly about the outer loops, which decide when that cycle starts again.
| Kind of loop | What triggers it | When it stops |
|---|---|---|
| Turn-basedThe cycle of a requested task | A person sends the request | The agent finishes or needs more context |
| Goal-basedThe agent keeps going until it meets a target | A verifiable target, such as /goal in Claude Code | The target is met or the attempts run out |
| Time-basedThe same task at intervals | An interval or a schedule, such as /loop and /schedule | The work is done or someone cancels it |
| ProactiveThe agent reacts to events with nobody watching | An event or a schedule, running in the cloud | The task ends or hits its set limit |
With /goal, each time the agent tries to stop, an evaluator model checks the condition and sends it back to work until the goal is met or the set number of turns runs out.
What a well-designed loop needs
A loop without a success criterion stops too early or never stops. The posts that spread the term agree on a few pieces.
- A verifiable target: What done means, stated so a test or an evaluator can check it, such as a green suite or a minimum Lighthouse score.
- Automated verification: Tests, linters and the manual checks written down as a skill, so the agent can check its own work end to end.
- A stop condition and a cap: A maximum number of turns and a cost budget per run.
- Isolation: Each run in its own git worktree, so two agents never touch the same files.
- State outside the conversation: A progress file or a task board that the next run reads when it starts.
- A reviewable output: The result ends in a pull request or a report, never straight in production.
Zorbit, an own product of Master Timm, follows this design for AI coding agents: it schedules runs by cron or as a DAG, runs each task in a git worktree through to a pull request and audits the cost and tokens of every run.
When a business should use loops, and when not
Loops pay off when the work repeats and a machine can check the result. Without both conditions, a loop just automates uncertainty.
- Good candidates: Fixing tests until the suite passes, updating dependencies with CI green, daily issue triage, chasing a performance target with a defined number.
- Poor candidates: Tasks with no definition of correct, product decisions, changes that depend on someone from the business.
- Small tasks: A simple request needs neither a loop nor several agents; sometimes a smaller, cheaper model does the job.
- Actions with effects outside the repository: payments, customer e-mails or production changes need human approval inside the loop, not afterwards.
Outside code, the same design shows up in autonomous AI agents with scheduled tasks, such as OpenClaw and Hermes Agent, which we set up with permissions, channels and memory under control.
The risks of leaving an agent in a loop
Osmani sums up the problem in one line: a loop running unattended is also a loop making mistakes unattended. The risks are known, and so are the controls.
- Cost: Every round consumes tokens, and a long or too-frequent loop multiplies the bill; the interval should follow how often the data changes, and a per-run budget ends the loop at the limit.
- Victory declared too early: With weak verification, the agent marks the task done when it is not; the target needs a test that can really fail.
- Code nobody has read: The faster the loop ships, the wider the gap between what is in the repository and what the team understands; human review of the pull request stays mandatory.
- Broad permissions with nobody watching: An autonomous loop runs with least privilege, no production secrets and an allowlist of commands.
Related service
AI Software Automation
Coding agents on your team, with specs and quality gates.
Free first conversation · Reply within 1 business day
See also: AI & LLM Engineering and AI Business Process Automation.
Frequently asked questions
What is the difference between an agent loop and a cron job?
A cron job runs the same script every time; an agent loop runs a model that decides the steps on each round and checks the result before it stops. Cron can be the trigger of a time-based loop, but what happens inside each run changes with what the agent finds.
Does loop engineering replace harness engineering?
No: the loop runs inside a harness. The harness defines what the agent can do and how a mistake is stopped; the loop defines when it works, for how long and when it stops. A loop on top of a weak harness just repeats mistakes faster.
How do you keep a loop from overspending?
With an explicit cap on every run: a maximum number of turns and a cost budget. In the Claude Agent SDK, max_turns and max_budget_usd end the loop with an identifiable error result, and traces show the tokens and cost of each round so you can tune the interval and the model.
Can a loop run with no human review at all?
It can run with nobody watching, but its output should not reach production without review. The safe design lets the agent work alone up to the pull request or report and leaves the decision to accept it to a person, along with any action that leaves the repository.
Sources
Master Timm · Updated on