Agent Loop Prompt Templates: Stop Conditions & Escalation
Copy paste-ready agent loop prompt templates with stop conditions, escalation lines, and turn caps for Claude Code agents. Text only, no runtime.
Generate Claude Code loop commands
Goals, verify criteria, and turn caps — copy-paste text only.
Try Loop Prompt Generator →An agent loop prompt is the contract you paste so a coding agent repeats work until proof appears or a hard stop fires. The missing pieces in most drafts are stop conditions and escalation: what ends the loop, what the agent must output when blocked, and when a human takes the wheel. This page ships paste-ready templates focused on those controls for Claude Code /goal style work and adaptable turn-based cycles. PromptMake at https://promptmake.net/loop-prompt-generator writes command text only. It does not run loops, bill tokens, or touch your repo. Theory, slash-pattern field order, and runaway-prevention deep dives live in other posts. Stay here for stop and escalate templates you can adapt today.
Why stop conditions belong in every agent loop prompt
Without a stop condition, agents keep editing after the real job is done or invent a new job when stuck. Claude Code’s /goal command, per Anthropic’s docs as of mid-2026, keeps working until an evaluator judges the condition met, judges it impossible, hits an unrecoverable error you must fix, or you run /goal clear. Your written condition still needs a measurable end state the transcript can prove.
Stop conditions come in three flavors. Success stops: tests exit 0, build passes, queue empty. Hard caps: stop after N turns or after a time clause in the condition. Abort stops: missing secrets, repeated identical failure, out-of-scope file changes, flaky infrastructure.
Escalation is the scripted handoff when a stop fires without success. The agent must summarize blockers, list checks that passed and failed, show the last command output, and halt further edits. Soft “try harder” language without an escalate block is how token burn happens.
PromptMake’s loop generator returns recommended primitive, command text, success criteria, turn cap, verification steps, and stop or abort guidance. Review every path and command before paste. Soft start: https://promptmake.net/loop-prompt-generator.
Success stop versus abort stop
A success stop names proof: npm test --workspace packages/api exits 0 with no snapshot changes. An abort stop names impossibility or risk: credentials missing, same error three turns, schema churn outside scope. Write both. Success alone leaves stuck agents improvising.
Escalation block anatomy
Require four lines on escalate: blocker summary, passed checks, failed checks, next human action. Forbid further file edits after escalate. That single forbid line saves repos.
Template kit: stop conditions you can paste
Use these blocks as appendices on any /goal condition or turn-based brief. Adapt paths and package managers to your repo. Keep one measurable end state per loop. Anthropic notes the evaluator judges from conversation evidence; it does not independently run commands, so require the worker to surface test and build output in the transcript.
As of mid-2026, you can bound a Claude Code goal with a clause such as or stop after 20 turns inside the condition. Pair that with your own escalation paragraph so the agent reports cleanly when the clause trips. Exact CLI behavior can shift by version; read code.claude.com/docs/en/goal when field names move.
Guest free use on PromptMake: about three loop generations per day. Free registered accounts: about five per day as of mid-2026. Pro removes generation caps at a monthly price on the pricing page. Anthropic token spend is separate.
Copy a template, fill bracketed paths, generate a polished variant at https://promptmake.net/loop-prompt-generator if you want structured output, then paste into Claude Code on a branch.
Template A: green tests with hard turn stop
/goal all unit tests in packages/api pass (npm test --workspace packages/api exits 0), no public export signatures changed, lint clean in packages/api/src, or stop after 12 turns. On stop without success: print blocker summary, list failing tests, list files touched, make no further edits, wait for human.
Template B: docs sync with abort on scope creep
/goal every CLI flag in bin/cli.ts appears in docs/install.md with one example, or stop after 10 turns. Abort immediately if any file outside docs/install.md and bin/cli.ts would change. On abort or cap: output missing-flag list and stop edits.
Escalation templates for stuck agents
Escalation templates assume the agent already tried the verification ladder and failed. They convert failure into a readable ticket for you. Paste them after the goal condition so the evaluator and worker share the same exit script.
Include negative checks that often hide regressions: no new eslint-disable, no dependency bumps, no migration files without approval, git status limited to named paths. When those trip, escalate even if tests are green.
For scheduled /loop work (interval polling, not finish-line goals), stop rules differ. Anthropic’s scheduled-tasks docs describe /loop as time-triggered; fixed-interval loops keep running until you cancel or the task expires. Put cancel instructions in your brief: after three identical deploy statuses, tell me and stop rescheduling. Soft drafting: https://promptmake.net/loop-prompt-generator.
Turn-based templates fit risky migrations. Each cycle: inspect, one bounded change, run checks, report, wait. Escalation fires when checks fail twice on the same error or when the human says stop.
Template C: identical-failure escalate
If the same failing test name or error fingerprint appears on three consecutive turns, stop. Output the fingerprint, last three command excerpts, hypothesized root cause in three bullets, and a recommended human next step. Do not edit more files.
Template D: external-blocker escalate
If a required secret, service, or network endpoint is unavailable, stop on first confirmed miss. Output the missing dependency, commands tried, and whether a local stub exists. Do not invent credentials. Do not broaden scope to unrelated packages.
Full paste skeletons by job type
Skeleton 1 (bugfix /goal): Condition: reproduce failing test auth.spec.ts, implement minimal fix, npm test -- auth.spec.ts exits 0, related suite npm test --workspace packages/auth exits 0, or stop after 15 turns. Scope: only packages/auth. Escalate with Template C language. Verify ladder: single spec, package tests, lint touched files, diff review.
Skeleton 2 (refactor /goal): Condition: UserService split into files under 200 lines each, existing tests green, public API unchanged, or stop after 20 turns. Abort if snapshots outside packages/users change. Escalate with file list and remaining size offenders.
Skeleton 3 (CI babysit /loop): /loop 5m check latest CI for this branch; if red, summarize failing job log in five lines; if green three times in a row, tell me and stop the loop. Read-only unless I approve a fix turn.
Skeleton 4 (turn-based migration): Each turn migrate one call site to the new API, run targeted tests, report remaining call sites. Stop when remaining count is 0 or after 8 turns. Escalate if a call site needs a design decision.
Skeleton 5 (dependency bump guard): /goal upgrade lodash only inside packages/web, keep lockfile consistent, npm test --workspace packages/web exits 0, or stop after 10 turns. Abort if any other dependency version changes. On abort: list unintended diffs and stop edits.
Skeleton 6 (flaky test quarantine): /goal either fix payments.spec.ts so it passes three consecutive runs or mark it skipped with a linked issue URL in the skip reason, or stop after 12 turns. Escalate if flake reproduces without a clear owner file.
Generate polished variants of these skeletons at https://promptmake.net/loop-prompt-generator by pasting your job in plain language and selecting Claude Code or Codex target. Always re-read paths before you run.
Store winning templates in your team repo under docs/agent-loops/ with last-tested Claude Code version and date. Retest after CLI upgrades because evaluator defaults and slash behavior can shift.
Verification ladder inside templates
Order checks cheap to expensive: unit, package, lint or types, build, diff. State expected exit codes. Weak ladders that only say “ensure quality” invite false completion. Put the expensive build last so early failures burn fewer tokens.
Codex and other agents
For Codex or non-Claude hosts, keep the same stop and escalate paragraphs. Drop Claude-specific slash syntax if the host lacks /goal. The durable asset is the contract, not the slash label. Translate turn caps into whatever max-iteration field your host exposes.
When humans must stay in the loop
Some jobs should never run unattended even with perfect stop text. Production deploys, payment code, permission changes, data deletes, and legal copy need a human approve gate between turns. Use turn-based skeletons and require an explicit “continue” from you after each escalate-ready report.
Read-only first passes help. Ask the agent to list files it would touch and commands it would run, then stop. You approve the plan, then start a second /goal with write permission. That two-phase pattern pairs cleanly with Template D external-blocker language.
Cost control is part of stop design. Narrow directory scope, prefer targeted tests, and keep caps conservative on first runs. Raise the turn clause only after you see clean escalate behavior on a real failure. Soft drafting for those contracts: https://promptmake.net/loop-prompt-generator.
Risky change checklist
Before paste: branch is clean, backups exist, secrets are present, destructive commands are named as forbidden, and a human is available for escalate output within the session window.
Safe unattended window
Unattended /goal fits greenfield tests, docs sync, and mechanical renames with strong abort fences. It fits poorly for ambiguous product taste or infra you cannot roll back in one commit.
Common mistakes with stop and escalate wording
Mistake 1: Success criteria without a turn or abort clause.
Mistake 2: Escalation that still allows “one more refactor.”
Mistake 3: Conditions the transcript cannot prove because the worker never runs the check.
Mistake 4: Mega-goals that mix fix, docs, and deploy in one cap.
Mistake 5: Treating PromptMake as a runtime.
Mistake 6: Copying /goal into a tool that only supports chat turns.
Mistake 7: Confusing this template page with loop-engineering-explained, claude-loop-prompt-guide, or claude-code-loop-commands.
Soft next steps
Pick one failing test or docs gap. Paste Template A or B, fill paths, add Template C escalate language. Optionally polish at https://promptmake.net/loop-prompt-generator. Run on a branch with a conservative turn clause. Log whether stop fired on success, cap, or abort.
FAQ
What is an agent loop prompt?
It is structured text that tells an agent what to finish, how to prove progress, when to stop, and how to escalate when blocked. In Claude Code that often takes a /goal or /loop shape. PromptMake generates that text; it does not execute it.
What should a stop condition include?
One measurable end state, a stated check the transcript can show, constraints that must not change, and a hard bound such as a turn clause. Add abort rules for missing secrets and repeated identical failures.
How do escalation lines differ from verify criteria?
Verify criteria decide success. Escalation lines decide the handoff when success does not arrive. They demand a blocker summary, evidence list, and a halt on further edits.
Does PromptMake run my agent loop?
No. https://promptmake.net/loop-prompt-generator returns paste-ready command text, success criteria, turn cap, and stop guidance. You run the result in Claude Code, Codex, or another agent you control.
How is this different from claude-code-loop-commands?
That article focuses on safe verify loops and runaway prevention patterns. This page ships stop-condition and escalation templates as the primary deliverable. Soft tool path is the same generator URL.
Can I use these templates with `/loop` schedules?
Yes with edits. /loop is interval-triggered per Anthropic’s scheduled-tasks docs. Add cancel rules after repeated identical statuses. Use /goal when you need a finish line evaluated after each turn.
How do I start on the free tier?
Describe your task at https://promptmake.net/loop-prompt-generator. Guests get about three generations per day; free accounts about five as of mid-2026. Review stop and escalate lines, then paste into your agent on a branch.
Ready to generate your own prompts?
Free. No sign-up required. Works with all major AI models.