PromptMake
2026-08-29·15 min read

Claude Code Loop Commands: Safe Verify Loops Without Runaway Agents

A claude code loop guide: /goal and /loop command text, verify criteria, turn caps, and safe patterns so agents stop instead of burning tokens on runaway loops.

claude code loopclaude codeloop commandsverify criteriaturn capsagent loopsprompt engineering

Generate Claude Code loop commands

Goals, verify criteria, and turn caps — copy-paste text only.

Try Loop Prompt Generator →

A claude code loop is a structured command you paste into Claude Code so the agent repeats work until verify criteria pass or a turn cap stops the session. The command names the goal, lists checks the agent can run, and sets a maximum iteration count. Without those three parts, agents drift, refactor unrelated files, or burn tokens on repeat failures. This guide covers /goal and /loop patterns, paste-ready skeletons, verify blocks, turn caps, and runaway prevention. PromptMake at https://promptmake.net/loop-prompt-generator generates loop command text only. It does not execute loops or run shell commands on your machine. You copy output into Claude Code and supervise there. Loop engineering theory lives in loop-engineering-explained on this blog.

What a claude code loop command contains

Every safe loop command has three blocks: goal, verify, and turn cap. Optional fourth block: scope fences that name directories, read-only files, and behaviors that must not change.

The goal block states what must be true when the loop ends. Write it so a reviewer can say pass or fail without reading chat history. Weak goals like improve the module invite the agent to pick its own finish line.

The verify block lists checks the agent runs before claiming success. Strong verify lines use shell commands and file paths: npm test exit 0, grep count for TODO in src/, diff against spec section 3. Weak verify asks the agent to ensure quality with no command.

The turn cap sets the maximum agent iterations in one loop. Each turn may read files, edit, run tools, and report status. Omitting a cap is how runaway agents happen on stuck tasks.

Claude Code loop commands are copy-paste text. PromptMake outputs that text. No runtime on PromptMake servers executes your repo commands.

Goal block: observable outcomes

Good goal examples: all unit tests in packages/api pass without changing public API signatures; docs/install.md lists every CLI flag from bin/cli.ts with one example; TypeScript build completes with zero errors in src/.

Include scope fences in the goal when refactors touch shared code: only edit files under packages/ui, do not rename exported types, do not bump dependency versions.

One goal per loop. Bundle refactor plus docs plus deploy into three sequential loops with separate caps instead of one mega-loop.

Verify block: evidence the agent can collect

Order verify checks from cheap to expensive. Run eslint before full integration suite. Read one config file before scanning the whole monorepo.

Use imperative verbs: Run, Assert, List, Compare, Grep. One check per line.

Add negative verify when regressions are common: assert file X still exists, assert package.json version unchanged, assert no new files under migrations/ without explicit approval.

Turn cap and escalation line

Typical caps for small tasks: 8 to 12 turns. Multi-file refactors with tests: 15 to 20 with narrow per-turn scope.

Always add an escalation instruction: if turn cap reached, output blocker summary, list checks that passed and failed, stop without further edits.

Log cap hits in your team notes. Frequent hits mean verify is too strict, goal is too vague, or cap is too low.

/goal and /loop command patterns in Claude Code

Claude Code accepts loop-style commands in the terminal session. Public docs and release notes use /goal and /loop as entry points for bounded iteration. Exact slash spelling can shift by CLI version. Treat the pattern as structured brief plus bounded repeat, not as magic autonomy.

A typical paste shape opens with the slash command, then goal paragraph, then numbered verify list, then turn cap line, then optional scope fences. You run the command once. The runtime handles turns until verify passes or cap triggers.

Loops use the same model as your Claude Code session. As of mid-2026, Claude Fable 5, Claude Opus 5, and Claude Sonnet 5 are common for long coding tasks. Haiku 4.5 suits narrow verify-heavy loops with small edits.

Loops are session-scoped. They differ from Agent Skills, which are reusable SKILL.md packs with description triggers. Use loops for one ticket with a finish line. Use skills for standing expertise that loads when tasks match.

Example: fix failing tests loop command

Goal: make npm test pass for packages/api without changing exported function signatures.

Verify: run npm test --workspace packages/api, exit code must be 0; run eslint packages/api/src, zero errors; no new eslint-disable comments added.

Turn cap: 12. If cap hit, summarize failing tests and stop.

Scope: edit only packages/api/src and packages/api/tests. Do not touch packages/web.

Example: sync docs to CLI flags loop command

Goal: update docs/install.md so every flag in bin/cli.ts appears with one usage example.

Verify: extract flag names from bin/cli.ts; compare to headings in docs/install.md; missing flags list must be empty.

Turn cap: 8. If cap hit, list missing flags and stop.

This loop rewards grep and structured reading over broad rewrites.

Example: typecheck cleanup loop command

Goal: reduce TypeScript errors in src/components to zero without changing runtime behavior.

Verify: run npx tsc --noEmit, zero errors in src/components; run npm test -- --testPathPattern=components, exit 0.

Turn cap: 15. Scope: src/components only, no dependency upgrades.

Split type fixes across loops when error count exceeds fifty. One loop per subdirectory keeps verify honest.

Step-by-step: write and run your first loop command

Pick a task you did manually twice this month. Manual repeat signals a loop might pay off.

Step 1: Write the goal as one falsifiable paragraph. If you cannot audit it in thirty seconds, rewrite.

Step 2: List verify checks the agent can run without asking you. Prefer commands over judgment.

Step 3: Set turn cap from task size. Add escalation line for cap hits.

Step 4: Commit or stash risky work. Git checkpoint before destructive loops.

Step 5: Paste into Claude Code. Watch the first two turns. If the agent skips verify order, tighten wording.

Step 6: Save the winning command in team docs with project name, date, and cap hit notes.

PromptMake https://promptmake.net/loop-prompt-generator scaffolds goal, verify, and cap from a plain-language brief. Output is text you edit for repo paths, then paste into Claude Code.

Drafting from a one-sentence brief

Brief example: fix flaky test in user.service.spec.ts, verify jest exit 0, cap 10.

The generator expands that into structured blocks. You replace placeholder paths with real ones, add scope fences if the task touches shared modules, and paste.

Guest users on PromptMake get about three generations per day per path. Registered free users get about five. Quotas are separate from /text and /skills paths.

Supervising the first run

Stay in the terminal for turns one and two. Confirm the agent runs verify in order. If it edits before running tests, add explicit wording: run verify step 1 before any file edit.

If verify passes early, the loop should stop. If the agent keeps iterating after pass, your verify wording may be ambiguous. Name exit conditions clearly.

When cap hits, read the blocker summary before raising the cap. Often the goal needs splitting, not more turns.

Preventing runaway agents

Runaway agents happen when goals are vague, verify cannot run, or turn caps are missing. They also happen when mega-loops bundle unrelated jobs so the agent never reaches a clean verify pass.

Symptom 1: repeated reads of the same file with no edits. Fix: narrow goal scope, add per-turn deliverable, lower cap.

Symptom 2: scope creep into unrelated directories. Fix: add scope fences with allowed paths, negative verify for forbidden dirs.

Symptom 3: token burn on a failing test suite. Fix: verify tagged subset first, full suite only on human approval after subset passes.

Symptom 4: agent declares success without running verify. Fix: reorder command text so verify is mandatory before completion message. Restate: do not claim done until all verify lines pass.

Symptom 5: infinite retry on impossible task. Fix: turn cap plus escalation. Never omit cap because the task feels small.

Cost and safety fences

Name commands that require human approval before run: deploy, migrate production, force push, rm -rf.

Cap shell-heavy verify when CI is slow. Allow local lint plus unit subset in loop verify, full pipeline on merge.

For database tasks, fence environment: staging only unless user names production explicitly in the goal.

When to stop looping and ask a human

Stop when cap hits twice on the same goal with different approaches. Stop when verify requires credentials the agent lacks. Stop when the goal conflicts with repo policy discovered mid-loop.

Escalation output should list: goal restated, verify results per line, files touched, recommended next human action.

Do not raise cap above 25 without splitting the goal. Large caps on vague goals are the main runaway pattern.

Loop commands vs Agent Skills

Agent Skills are folder-based SKILL.md packs with description triggers. Claude loads them when your task matches. Skills teach repeatable workflows across sessions.

Loop commands are one job, one session, one finish line with explicit verify and cap.

Use a skill when many tasks share tools and patterns: release checklist, security review, migration playbook.

Use a loop command when today's ticket has a verify bar: tests green, doc synced, type errors zero.

PromptMake generates Skills config on https://promptmake.net/skills and loop command text on /loop-prompt-generator. Pick the product that matches reuse horizon.

Do not put unbounded repeat instructions inside SKILL.md unless you also embed verify and cap language. Skills without bounds can behave like runaway loops when mis-triggered.

Common claude code loop mistakes

Mistake 1: Vague goals. The agent optimizes for chat completion, not your definition of done.

Mistake 2: Verify criteria the agent cannot execute. Ensure UX feels good has no command.

Mistake 3: No turn cap. Cost spikes on stuck tasks.

Mistake 4: Mega-loops that bundle refactor, tests, docs, and deploy.

Mistake 5: Confusing loop text generation with loop execution. PromptMake outputs copy-paste commands only.

Mistake 6: Skipping git checkpoint before destructive loops.

Mistake 7: Using loops for one-line edits. Human keystrokes are cheaper.

Mistake 8: Copying loop commands from another repo without editing paths and test commands.

Model and tooling notes for mid-2026

Claude Code sessions commonly run Claude Fable 5 for narrative-heavy doc loops, Claude Opus 5 for hard refactors, and Claude Sonnet 5 for balanced speed and quality. Haiku 4.5 fits verify-heavy tight loops when edits are small.

OpenAI Codex-class tools and Cursor agents use different loop metaphors. Principles transfer: goal, verify, cap. Command syntax does not.

Gemini 3.1 Pro and GPT-5.6 Sol can draft loop command text in chat, but Claude Code execution stays on Anthropic tooling.

Read Anthropic release notes when field names or slash commands shift. This guide describes mid-2026 patterns.

When to use PromptMake for loop command text

Use the loop generator when you know the task but not the command shape. Paste a plain brief with goal hints and verify commands you already use.

Use it when onboarding juniors. They learn structure from output before writing from scratch.

Use it when verify lists grow long. The tool keeps ordering consistent.

Do not use it expecting autonomous runs. Copy output, open Claude Code, paste, supervise.

Open https://promptmake.net/loop-prompt-generator. Guests get about three generations per day without signup. Registered free accounts get about five per day on that path.

Soft next steps

Pick one recurring ticket from your backlog. Write goal, verify, and cap on paper. Generate scaffold text at https://promptmake.net/loop-prompt-generator, edit paths, run in Claude Code once with supervision.

After three real loops, compare cap hit rate and wall time against your manual baseline. Tune verify before you raise caps.

Read loop-engineering-explained on this blog for the broader design discipline. Stay on this page for paste-ready command patterns and runaway prevention.

FAQ

What is a claude code loop?

A claude code loop is a bounded agent task in Claude Code defined by goal, verify criteria, and a turn cap. You paste a /goal or /loop style command. The agent iterates until checks pass or the cap forces escalation. It is structured command text, not unbounded autonomy.

What are verify criteria in a loop command?

Verify criteria are commands or checks the agent must pass before claiming success: test exit codes, file diffs, linter output, grep results. They turn vague goals into evidence a human can audit. Order checks from cheap to expensive so the agent does not burn turns on full suites before lint passes. Strong verify lines name exact commands and expected signals, not subjective quality judgments.

How do turn caps prevent runaway agents?

Turn caps limit how many agent iterations run in one loop. When the cap hits, a well-written command forces a blocker summary instead of silent token burn. Omitting a cap is the most common runaway mistake.

Does PromptMake run claude code loops for me?

No. PromptMake generates loop command text at https://promptmake.net/loop-prompt-generator. You copy output into Claude Code, which executes the loop on your machine. PromptMake has no loop runtime.

What is the difference between /goal and /loop?

Both names refer to bounded iteration patterns in Claude Code. Exact slash spelling can vary by CLI version. Focus on the structure: goal block, verify list, turn cap, scope fences. Read Anthropic docs for your installed version.

How is this different from loop engineering explained?

Loop engineering explained covers the design discipline: goals, verify, caps as concepts. This article focuses on claude code loop command text, paste examples, and preventing runaway agents. Use both when building a team loop practice.

Can I use loop commands with GPT-5.6 Sol or Gemini?

The goal-verify-cap principles transfer to any agentic coding tool. Claude Code slash patterns are Anthropic-specific. PromptMake loop output targets Claude Code wording. Adapt commands if you run another host.

What is a good starting turn cap for a claude code loop?

For small fixes, start with 8 to 12 turns. For multi-file refactors with tests, 15 to 20 with narrow scope. Log cap hits and adjust. Always include an escalation line when the cap is reached.

Ready to generate your own prompts?

Free. No sign-up required. Works with all major AI models.

Related articles