Loop Engineering Explained: How to Build Self-Running AI Coding Agents (2026 Guide)
- 3 hours ago
- 5 min read

What Is Loop Engineering?
Loop engineering is the discipline of building small automated control systems — loops — that drive AI coding agents on your behalf, instead of you prompting the agent manually, turn by turn.
For roughly two years, working with a coding agent meant: write a prompt, read the output, write the next prompt, repeat. You held the steering wheel the entire time.
Loop engineering replaces that. You design a system once — a loop with a defined goal, a way to check the agent's work, and rules for when to stop — and let that system run the agent for you, sometimes unattended for hours.
"I don't prompt Claude anymore. I have loops running that prompt Claude and figuring out what to do. My job is to write loops." — Boris Cherny, Head of Claude Code, Anthropic
"You shouldn't be prompting coding agents anymore. You should be designing loops that prompt your agents." — Peter Steinberger
The term was popularized in 2026 by Google engineer Addy Osmani, who described it as sitting one layer above a related concept called agent harness engineering (building the environment a single agent runs inside).
Loop Engineering vs. Related Terms
Term | What It Means | Scope |
Prompt Engineering | Crafting a single, effective instruction for an AI model | One prompt, one response |
Agent Harness Engineering | Building the environment/tools a single agent operates inside | One agent's runtime |
Loop Engineering | Building the system that automatically re-prompts and verifies an agent until a goal is met | Multiple turns, autonomous, goal-driven |
Loop engineering doesn't replace prompt engineering — a loop still needs well-written prompts at each step. It replaces the human as the one repeatedly writing those prompts.
The Five Building Blocks
Every loop, regardless of complexity, is composed of five parts:
Goal — A clear, measurable definition of "done," set before the loop starts.
Prompter — Generates and sends the next instruction to the agent.
Reader — Captures and parses the agent's output (code diffs, test results, logs).
Verifier — Independently checks whether the output actually satisfies the goal.
Controller — Decides whether to stop, retry, or re-prompt with corrected context.
GOAL → PROMPTER → AGENT → READER → VERIFIER → done?
↑ |
└──────────── no ────────────┘
|
yes → STOP
The verifier is the single most important block. A loop running unattended is also a loop that can make mistakes unattended — without an independent check, the agent can simply declare itself "done" without it being true. "Done" is a claim, not a proof.
A Minimal Working Loop (Code Skeleton)
This is a simplified Python skeleton showing the five blocks in practice — not production code, but enough to see the shape.
import subprocess
MAX_ITERATIONS = 5
GOAL = "All tests in the repo pass"
def run_tests():
"""READER + part of VERIFIER: capture current state"""
result = subprocess.run(["pytest", "--tb=short"], capture_output=True, text=True)
return result.returncode == 0, result.stdout
def prompt_agent(failing_output):
"""PROMPTER: send the next instruction to the agent"""
instruction = f"Fix these failing tests:\n{failing_output}"
# call_agent() is a stand-in for your actual agent API call
return call_agent(instruction)
def loop():
for iteration in range(1, MAX_ITERATIONS + 1):
passed, output = run_tests() # VERIFIER
if passed: # CONTROLLER: stop condition met
print(f"Goal met after {iteration - 1} iteration(s).")
return True
print(f"Iteration {iteration}: tests failing, re-prompting agent...")
prompt_agent(output) # PROMPTER → AGENT
print("Max iterations reached without meeting goal. Flagging for human review.")
return False
Three things to notice:
The verifier (run_tests) is independent of the agent. The agent never gets to self-report success — the loop re-runs the actual test suite.
MAX_ITERATIONS is hard-coded. Without a cap, a buggy loop can run forever, consuming tokens with no benefit.
Failure has a defined exit. When the cap is hit, the loop stops and escalates to a human instead of looping silently forever.
Real-World Implementations
Claude Code ships a /loop command that schedules a recurring prompt on an interval — effectively turning a goal into a cron job — plus hooks that fire shell commands at points in the agent's lifecycle (on start, on file change, on completion).
Loops can be pushed to GitHub Actions, letting them keep running after a developer closes their laptop.
Practitioners report running 10–15 parallel agent loops simultaneously, each with its own persistent memory file (e.g., CLAUDE.md), sub-agents, and independent verifier — scanning sources like GitHub issues or Slack, deciding what to build, implementing it, testing it, and self-fixing failures.
Common Mistakes
1. No Stopping Condition
A loop with a vague goal ("make the code better") has no way to know when it's finished and can run indefinitely. Fix:Define a measurable goal — tests pass, a specific file exists, a metric crosses a threshold.
2. No Iteration or Budget Cap
Even with a clear goal, a loop can get stuck retrying something it's structurally unable to fix. Fix: Always set a maximum iteration count or token/compute budget, with a defined fallback (escalate to a human) when it's hit.
3. Trusting the Agent's Self-Report
If the loop accepts "I fixed it" from the agent without independently checking, broken work ships silently. Fix: The verifier must run an independent check — actual tests, a second agent acting purely as a critic, or a hard rule-based validator — never just the agent's own claim.
4. Letting Comprehension Debt Accumulate
The faster a loop ships code nobody wrote by hand, the wider the gap grows between what exists in the repository and what the team actually understands. Fix: Human review of merged changes stays in the loop regardless of how good the verifier gets. Read what the loop produced — don't treat automation as a reason to stop reading.
5. Token Cost Blindness
Loop usage patterns can vary wildly depending on whether you're token-rich or token-constrained, and an unattended loop can burn budget fast. Fix: Monitor token spend per loop run and set hard budget ceilings alongside iteration caps.
How to Get Started
Pick one repetitive, well-defined task you currently do by manually prompting an agent (e.g., "fix failing tests," "update API docs after a schema change").
Write the goal in one sentence that's objectively checkable (not "improve the code" — "all tests pass" or "linter returns zero errors").
Build the verifier first, separate from the agent. This is the part most beginners skip and the part that prevents silent failures.
Set a hard iteration/budget cap with a human-escalation fallback.
Run it on a low-stakes task before trusting it with anything production-critical.
FAQ
What is a loop engineer? A loop engineer is someone who builds automated systems that drive AI coding agents — designing the goal, verification, and control logic — rather than manually prompting the agent turn by turn.
Is loop engineering a real job title yet? It's an emerging skill and role description within AI engineering rather than a widely standardized job title, but it's being discussed by leaders at Anthropic and elsewhere as one of the fastest-growing skills in the field as of 2026.
Do I need to know prompt engineering before learning loop engineering? Yes. A loop still depends on well-written prompts at each step — loop engineering adds the orchestration layer on top of prompt engineering, it doesn't replace the need for it.
What's the difference between loop engineering and agent harness engineering? Harness engineering builds the environment a single agent runs inside (tools, context, permissions). Loop engineering sits one layer above it — building the system that repeatedly drives that agent toward a goal across multiple turns.
Can a loop run completely unattended? Technically yes, but it's risky without a strong, independent verifier and human review of merged output. An unattended loop is also an unattended source of mistakes if verification is weak.
What tools support loop engineering today? Claude Code's /loop command and lifecycle hooks, combined with scheduling via GitHub Actions, are current examples. The pattern is becoming tool-agnostic as other coding agent platforms converge on similar primitives.
References
Addy Osmani, "Loop Engineering", AddyOsmani.com, 2026
Cobus Greyling, "Loop Engineering", 2026
Lushbinary, "Loop Engineering: The Guide for AI Agents", 2026
Quotes attributed to Peter Steinberger and Boris Cherny are drawn from public posts and talks, 2026.



Comments