AI Guides › Playbooks

The Loop Card: Objective, Check, Exit and Ceiling for Self-Running AI Work

By Nigel Guy · 7 min read

Most people who get good at prompting hit the same wall. The prompt is excellent, the first answer is decent, and then you spend the next hour typing "nearly, now fix the third one", "that broke the header", "try again". You have become the loop: the part that checks the work, decides whether it is finished and sends it round again. It feels productive because every reply is a little better, but the slowest, most easily distracted component in the system is you.

Current tools can now take that job off you. Claude Code has /goal, /loop and Stop hooks, and agent frameworks such as the OpenAI Agents SDK run a tool-calling loop with a turn limit. None of that helps if you hand the machine a vague wish. A loop with no clear finish line simply automates the "try again" habit, faster and at your expense.

The rule: never start a loop until you can write down what "done" looks like, how it will be proved, and what makes it give up. If you can't fill in those lines, write a prompt, not a loop.

The Loop Card

The Loop Card is four lines you write before anything runs. Keep it in a text file next to the work.

Line What it answers Weak version Strong version
Objective What end state are we after? "Tidy up the product pages" "Every product page has alt text on every image"
Check What evidence proves it, and who or what produces it? "Looks good to Claude" "python check_alt.py prints 0 missing and exits 0"
Exit When does it stop, whether it succeeds or fails? Not stated "Stop when the check passes, or after 15 turns, or if the same error appears three times running"
Ceiling What must not change, and what is the spending limit? Not stated "Touch only files in /products. Do not edit check_alt.py. Cap: 15 turns"

Step 1: Write the objective as a state, not an activity

"Improve", "tidy" and "optimise" are activities. They have no natural end, so a loop chasing them either stops at random or never stops. Rewrite the objective as something that is either true or false when you look at it: a count reaches zero, a file exists, a command succeeds, a list is empty.

Step 2: Make the check produce evidence, not opinions

This is the line that separates a loop from a long chat. Anthropic's own guidance on building agents stresses that agents should get "ground truth" from the environment at each step, such as tool results or code output, rather than relying on their own impression of progress.

In Claude Code, /goal uses a separate small, fast model to judge your condition after every turn. That evaluator does not run commands or read files itself; it only judges what has already appeared in the conversation. So "all tests pass" only works because Claude runs the tests and the output lands in the transcript. If your check can't be shown as text, such as "the tone feels warmer", the evaluator has nothing solid to judge.

Good checks, in rough order of reliability:

  1. A script or command with an exit code (tests, a linter, a counting script)
  2. A count or comparison against a fixed list ("all 42 SKUs in skus.csv appear in the output")
  3. A written checklist that a second model scores item by item, with the reasons shown

The working model's opinion of its own work is not on this list.

Step 3: Write the exit before the entrance

Every loop needs two ways out: success, and a sensible failure. Anthropic recommends stopping conditions such as a maximum number of iterations to keep control of an agent. The tools give you guard rails, but they are backstops, not a plan:

Tool Built-in brake (as documented at time of writing)
Claude Code /goal Clears when the evaluator judges the condition met or impossible, or on errors you have to fix (such as an exhausted credit balance). You can add your own clause, for example "or stop after 20 turns". /goal clear ends it early.
Claude Code Stop hook Your script can block Claude from stopping. Claude Code overrides the block after eight consecutive continuations; the hook input includes stop_hook_active so your script can tell it is already in a forced continuation.
Claude Code claude -p --max-turns limits agentic turns and exits with an error when reached. --max-budget-usd stops spending at a set amount (it is in US dollars, so convert your £ budget yourself).
Claude Code /loop Repeats on an interval rather than towards a condition. Recurring tasks expire seven days after creation.
OpenAI Agents SDK max_turns on the runner; exceeding it raises MaxTurnsExceeded.

Add a "stuck" rule of your own as well: the same error three times in a row means the loop should stop and report, not keep trying.

Step 4: Set the ceiling

The ceiling holds the constraints a loop is tempted to break on its way to a green light. The obvious one: the loop must not edit the check. A loop that is told "make the tests pass" and is allowed to touch the tests has an easy, wrong route to success. Claude Code's own /goal guidance suggests naming anything that must not change, such as "no other test file is modified". Add a scope (which folders) and a size (turns or spend).

Step 5: Run it once with a person watching

Your first run is a test of the card, not of the AI. Watch every turn. You are looking for three things: did the check output actually appear, did the loop try to weaken the check, and did it stop where the card said? Only after a clean supervised run should you let it run unattended, for example in Claude Code's auto mode, which approves tool calls so goal turns can carry on without you.

Worked example (hypothetical)

You run a small online ceramics shop. The site is a folder of HTML pages in a Git repository, and an accessibility review flagged that many product photos have no alt text.

First you ask Claude, in an ordinary chat, to write check_alt.py: a script that lists every <img> without a non-empty alt attribute, prints the count, and exits 1 if the count is above zero. You run it yourself and confirm it reports what you expect. Then you commit it to Git.

Your card:

In Claude Code you start it with a single condition that carries the whole card:

/goal Every <img> in /products has a descriptive alt attribute. Prove it by running python check_alt.py and showing its output: it must print "0 missing" and exit 0. Only edit .html files in /products. Do not modify check_alt.py. Base alt text only on the product title and description on each page. Stop after 15 turns, or if the same error repeats three times.

You watch the first few turns, then spot-check ten finished pages yourself. The script can count missing alt text; it cannot tell whether "blue mug" is a good description of a speckled celadon tankard. That last judgement stays with you.

What to skip

Guardrails

Sources

All 751 AI guides · JulieMango plans from £17/mo