Skip to main content

Loops and Harnesses

info

This content was developed with AI assistance and is regularly reviewed for accuracy.

Snapshot: October 2026. Model names, prices, and product features change monthly; What's New in AI is the maintained chronology.

In short: Loop engineering is the practice of designing the system that prompts an AI agent, on a schedule or a trigger, instead of typing every prompt yourself. Where a playbook is a repeatable process you run with AI, a loop is a process the agent runs on its own: it finds the work, does it, checks the result, records what happened, and decides what to do next. The harness is everything you build around the model to make that loop trustworthy. This section explains the pattern, names the first-party primitives that implement it in 2026, walks through loops you can run unattended, and ends with the recipe for recognising when you should not build one.

Why loops live inside AI Agents​

Playbooks and loops are two halves of one idea: turning AI from a thing you chat with into a thing that does work for you. The rest of the AI Agents track teaches what an agent is, how to build one, and how to keep it safe. Loops are what you do with that agent once you stop sitting beside it.

PlaybooksLoops
Who drivesYou, step by stepThe system, on a trigger
ShapeA repeatable workflow you followA self-running process that prompts the agent
Best forTasks you do yourself, better and fasterWork that should happen without you present
You writeA good brief and the next briefThe loop that writes the briefs, and the checks that grade the results

The bridge between the two is a scheduled prompt. If you have built the report in Automate a Weekly Report with AI, you have already built a one-turn loop: a trigger, an action, and a place the result lands. This section adds the parts that make a loop safe to leave alone: evaluation, stop conditions, and memory.

What changed in 2026​

For about two years, getting work out of an agent meant writing a prompt, reading the reply, and writing the next prompt, holding the tool the whole time. During 2026 that flipped. Coding agents became capable enough to run multi-step work for hours, so the bottleneck moved from model capability to orchestration design: deciding what to prompt, when, and whether the result is good enough.

Several 2026 vendor and consultancy blogs credit Addy Osmani with popularising the term "loop engineering" by June 2026, building on remarks from Peter Steinberger and from Anthropic's Boris Cherny, who leads Claude Code. Cherny's line, as widely quoted: "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." That attribution comes from secondary sources, and the term has no formal definition yet. What it names is real, and it has first-party names you can look up: Claude Code ships /loop (re-run a prompt on an interval), /goal (keep working until a completion condition holds), Routines (cloud runs on a schedule or an event), Stop hooks, and budget flags. Anthropic's engineering blog calls the scaffolding around a model a harness. This section uses "loop engineering" as the umbrella label and those terms for the parts.

Loop engineering did not replace earlier skills; it wraps them. Prompt engineering asks what do I ask? Context engineering asks what does the model need to know? Loop engineering asks who decides what to ask, when, and whether the answer is good enough?

The vocabulary you'll meet​

A handful of terms recur across the docs and blog posts practitioners read in 2026. The foundations pages define each in context; here is the short form.

  • Agent loop: the cycle of find work, do it, check it, record it, decide what's next.
  • Harness: "the scaffolding of prompts, agents, tools, and orchestration around a model", in Anthropic's March 2026 definition.
  • Planner, generator, evaluator: the three roles a harness splits work into, so the agent that produced the work is not the one grading it.
  • Stop condition: the rule that ends a loop, on success, budget, repeated failure, or escalation; /goal and Stop hooks implement it.
  • Context reset versus compaction: starting a fresh agent with a structured handoff file, versus summarising the current context in place.

Two product terms matter as well. A Routine is a Claude Code run that happens in the cloud on a schedule, an API call, or a GitHub event, using your claude.ai connectors. A /loop is session-scoped: it re-runs a prompt while the session lives and expires after seven days so a forgotten loop cannot run forever.

Foundations​

Start here to understand what a loop is and how to keep one safe before you build one.

GuideWhat you'll learnTime
What Is Loop Engineering?The shift from prompts to loops, and when a loop is (and is not) the right tool10 min
Anatomy of an Agent LoopThe six parts every reliable loop needs, mapped to /loop, /goal, Routines, and Stop hooks, plus the harness vocabulary15 min
Loop Guardrails and SafetyBudget flags and caps, sandboxing, approvals that resist fatigue, observability, and the token cost of agent teams15 min

Recipes​

Concrete, copyable loops. Each follows the same step-by-step format as a playbook, but the end result runs itself. The third recipe is the one most sections skip: how to tell when you should not build a loop at all.

RecipeWhat it doesSetup
The Overnight Coding LoopAn agent that picks up a queued task, implements it, tests it, and opens a pull request, with guardrails so it stops safely60-90 min
The Research and Monitoring LoopA scheduled loop that watches a topic and delivers a sourced digest on its own45-60 min
When a Workflow Beats a LoopA decision recipe for choosing a deterministic workflow or a one-turn scheduled prompt instead of an agent loop30 min

How to use this section​

  1. Read What Is Loop Engineering? and Anatomy of an Agent Loop first. They are short and everything else builds on them.
  2. Read Loop Guardrails and Safety before you let anything run unattended. A loop without a stop condition is a way to spend money fast.
  3. Run When a Workflow Beats a Loop against the task you have in mind. If it says "workflow", believe it.
  4. Pick a recipe that matches a real task and build it with that task, not with the example.

Loops reward starting small. Your first loop should do one narrow thing, with a tight budget and a human checkpoint, and earn more autonomy only after you have watched it behave. The agent you run inside it is covered in Claude Code: Your AI Coding Agent, and the checks that make its results trustworthy are covered in Evals for Agents.

Next steps​

Continue to: What Is Loop Engineering?