What Is Loop Engineering? Bounded Agent Runs Explained
What is loop engineering? A plain definition, a five-term glossary, how it relates to prompt and context engineering, and why coding teams adopted it in 2026.
Generate Claude Code loop commands
Goals, verify criteria, and turn caps — copy-paste text only.
Try Loop Prompt Generator →TL;DR: What is loop engineering? It is the practice of writing an AI agent's job so the agent repeats work until a check you can verify passes or a turn limit runs out. You define a goal, a verify step, a turn cap, and what the agent should report when it gets stuck. Coding tools such as Claude Code and Codex made the idea mainstream in 2026 with a /goal command that keeps an agent working toward a stated finish line. This page gives the one-paragraph definition, a five-term glossary, a map against prompt and context engineering, and a starter template. PromptMake at https://promptmake.net/loop-prompt-generator writes loop command text; it never runs the loop.
What is loop engineering? The short definition
Loop engineering is the skill of designing a bounded agent run. You tell an AI agent what “done” looks like in terms it can check, such as “all tests in packages/api pass,” and you tell it when to give up, such as “stop after 10 turns.” The agent then works in cycles: it plans, edits, runs a check, reads the result, and decides whether to go again. Your job as the loop engineer is to write those boundaries well before the run starts, so you do not have to babysit every step. A good loop feels like handing a ticket to a careful teammate who knows the acceptance test and the deadline. A bad loop feels like leaving a tap running. The two subsections below show one concrete loop and the kind of work it suits.
A 30-second example
You have one failing test file. Without a loop, you ask the model for a fix, paste the error back, ask again, and repeat by hand. With a loop, you write one line: “Make npm test --workspace packages/api exit 0 without changing exported function signatures, or stop after 10 turns and list what still fails.”
The agent now owns the retry cycle. It reads the failure, edits code, re-runs the test, and checks the result against your condition. When the test passes, it stops. When turn 10 arrives first, it stops and reports. You review one outcome instead of ten chat messages.
What loop engineering is good for
Loops suit jobs with a clear pass or fail check: fixing tests, clearing lint errors, syncing docs to a CLI's flags, hitting a Lighthouse score, or migrating a batch of call sites to a new API. Each of those has a command or a count the agent can run.
Loops struggle when success is a matter of taste, such as “make the landing page feel premium.” The agent has nothing to check, so it stops when it feels done. For those jobs, keep a human in each round.
Loop engineering glossary: five terms to know
Most loop guides use the same five words, and beginners stumble when they treat them as interchangeable. A goal is what you want. A verify step is how the agent proves it. A turn cap is how many tries it gets. Escalate is what happens when tries run out. The loop is the whole package. Anthropic's Claude Code team describes loops as agents repeating cycles of work until a stop condition is met, and every term below maps to a piece of that sentence. Learn these five and you can read any loop command, whether it came from a teammate, a Claude Code doc, or a generator.
Loop
A loop is one agent job that repeats plan, act, check cycles until a stop condition fires. It lives for one session and one task. Reusable expertise that applies across many tasks belongs in an Agent Skill or a project rules file instead.
Goal
The goal states what must be true when the loop ends. Write it so a reviewer can say pass or fail without reading the chat: “migration file exists and all imports resolve” works; “clean up the module” does not.
Verify
Verify criteria are the checks the agent runs to prove the goal. Prefer commands and file paths: run the test suite, run the linter, grep for TODO in src/. In Claude Code's /goal flow, a separate evaluator model checks your condition each time the agent tries to stop, so the agent must print evidence the evaluator can see.
Turn cap
A turn cap is the maximum number of cycles the agent may spend. It bounds cost, because each turn re-sends a growing context, and it bounds scope, because stuck agents start inventing side quests. Small fixes often start at 8 to 12 turns.
Escalate
Escalate is the report the agent writes when the cap hits or a blocker appears: what passed, what failed, the last error, and the next human step. Without an escalate line, a capped loop ends in silence and you lose the diagnosis.
Where loop engineering sits next to prompt and context engineering
People often ask whether loop engineering replaces prompt engineering. It stacks on top of it. Prompt engineering shapes the words of one request. Context engineering decides what information the model sees when it answers. Loop engineering decides how many times the model acts, how it checks its own work, and when it stops. A strong agent run uses all three: a clear instruction, the right files and docs in view, and a stop rule. Weakness in any layer shows up as a bad loop. A vague prompt gives a vague goal. Missing context sends the agent hunting through the repo. A missing cap turns a small bug into a large bill.
Prompt engineering: the words
Prompt engineering covers role, task, constraints, examples, and output format for a single model call. It still matters inside a loop, because the goal and verify lines are prompts. Frameworks such as CO-STAR or RTF help when the job is a one-shot answer.
Context engineering: what the model sees
Context engineering chooses which files, docs, tool results, and memory enter the window. For a deeper split, read https://promptmake.net/blog/context-engineering-vs-prompt-engineering. In loops, context grows every turn, so narrow directory fences and short command output keep later turns cheap.
Loop engineering: when to stop
Loop engineering adds time and judgment to the stack. It answers three questions a single prompt skips: how does the agent know it is done, how many attempts count as one job, and what should it say when it fails. Those answers turn an agent from a chat partner into a worker you can leave alone for ten minutes.
Why loop engineering searches spiked in mid-2026
Interest in the term climbed through the summer of 2026 for three reasons. First, Claude Code shipped a /goal command that keeps the agent working until an evaluator confirms your written condition or a turn limit hits. OpenAI's Codex added a command with the same name and a similar contract. Developers now had a one-line way to hand off a finish line.
Second, Anthropic published guidance that sorted loops into types: turn-based (you check each round), goal-based (/goal), time-based (/loop and scheduled runs), and proactive setups that combine them. That vocabulary gave teams a shared way to talk about agent autonomy.
Third, engineering writers picked up the phrase and framed it as the next skill after prompt engineering: you stop typing each prompt and start designing the system that prompts the agent. Search interest followed the blog posts and conference talks. As of September 2026, the term is practitioner vocabulary, not a formal standard, so expect tool-specific syntax to keep shifting.
Your first loop in five lines
You can write a working loop brief on an index card. Use this starter and fill the brackets for your repo:
- GOAL: [one observable outcome, for example all tests in packages/api pass].
- VERIFY: [commands the agent runs, for example npm test --workspace packages/api exits 0; npm run lint exits 0].
- FENCE: [what must not change, for example no edits outside packages/api; no dependency bumps].
- CAP: stop after [10] turns.
- ESCALATE: on cap or blocker, list passed checks, failed checks, the last error excerpt, and one suggested next step; make no further edits.
In Claude Code, you can compress that into a single /goal line: “/goal all tests in packages/api pass and lint is clean, no edits outside packages/api, or stop after 10 turns and report blockers.” Commit your branch before you run it so a bad loop is one git reset away from gone.
If you would rather start from a plain-English brief, paste it into https://promptmake.net/loop-prompt-generator. The tool returns a recommended primitive, command text, success criteria, a turn cap, verification steps, and stop guidance. You copy the result into Claude Code or Codex and run it there.
Common beginner mistakes
Writing a goal with no check is the first trap. “Improve performance” gives the agent no finish line. Name a metric and a threshold.
Skipping the turn cap because the task looks small is the second. Small tasks hide the worst read loops, where the agent opens the same five files forever.
Stacking three jobs into one loop is the third. Refactor, test, and deploy in one goal means one failure blocks everything. Split them into separate loops with separate caps.
Expecting a generator to run the loop is the fourth. PromptMake writes text; Claude Code or Codex executes it on your machine or in your cloud session.
This page stays at the definition level. For the full design walkthrough with worked examples, read https://promptmake.net/blog/loop-engineering-explained. For stop conditions that save money on real tickets, read https://promptmake.net/blog/loop-engineering-ai-playbook.
Where to go next
Pick one chore you did by hand twice this month, such as fixing a flaky test or updating a changelog. Write the five-line brief above. Run it on a branch with a cap of 10. Note whether it stopped on success, on the cap, or on a blocker. That one run teaches more than any glossary.
When the brief feels clumsy, run it through PromptMake's loop prompt generator linked above. Guests get about three generations per day and free registered accounts about five, as of September 2026. Model token costs stay with Anthropic or OpenAI.
FAQ
What is loop engineering in simple terms?
Loop engineering means writing an AI agent's task so it keeps working until a check passes or a turn limit runs out. You supply the goal, the check, the limit, and the failure report. The agent handles the retries. You review the final result instead of every attempt.
Is loop engineering the same as prompt engineering?
No. Prompt engineering shapes the words of one request, while loop engineering designs a repeated agent run with a stop rule. Loop briefs still use prompt skills, because the goal and verify lines are prompts. Think of loop engineering as a layer that sits on top of prompt and context engineering.
What is a turn cap in an AI loop?
A turn cap is the maximum number of plan, act, check cycles an agent may spend on one job. It protects your budget and stops scope creep when the agent gets stuck. Write it into the prompt, such as “stop after 10 turns,” and mirror it in runner settings when your tool offers them. Pair it with an escalate line so the agent reports what went wrong.
What does the /goal command do in Claude Code?
As of mid-2026, /goal lets you state a completion condition in plain language, often with a turn limit. Claude keeps working, and each time it tries to stop, an evaluator model checks your condition and sends it back if the goal is not met. The run ends on success or when the turn limit hits. Check Anthropic's Claude Code docs for current syntax, since flags change between versions.
Do I need to code to use loop engineering?
Most loop tooling today targets software work in Claude Code or Codex, so basic comfort with a terminal and git helps. The thinking skills transfer to any agent: define done, define the check, set a limit. Scheduled routines in some agent products let non-developers run bounded jobs with plain instructions. Start with a low-risk task either way.
Why is everyone talking about loop engineering in 2026?
Claude Code and Codex both shipped /goal style commands, and Anthropic published a clear taxonomy of loop types. Writers then framed loop engineering as the next step after prompt engineering. That mix of new tooling and new vocabulary drove the search spike. The term remains informal, so expect definitions to keep settling.
How do I write my first loop prompt?
Use five lines: goal, verify, fence, cap, and escalate. Run it on a clean git branch with a cap near 10 turns. If you want a scaffold, paste a plain brief into https://promptmake.net/loop-prompt-generator and edit the paths and commands to match your repo. PromptMake writes the text only; you run it in your agent tool.
Ready to generate your own prompts?
Free. No sign-up required. Works with all major AI models.