Some work is done in rounds: run the tests, fix the first failure, run them again. AI agents are good at this, as long as they know when to stop. This guide shows how to write that loop into a skill or agent so Claude Code, Codex and GitHub Copilot all stop at the right time, and how Skill Builder finds the places where a loop would help.
What a good loop needs
Every loop that repeats work needs four things. Leave one out and the agent either stops too early or keeps going until it runs out of context.
| Part | Question it answers | Example |
|---|---|---|
| Goal | When is it finished? | Every check in npm run check passes. |
| Check | How does each round prove it? | Run npm run check and read the first error. |
| Limit | How many rounds at most? | 3 rounds, or fewer if a round fixes nothing. |
| If not met | What happens when the limit is reached? | Ask the person whether to continue. |
The check matters most. “Make sure it looks right” lets the agent judge its own work. A command, a test or a tool call gives it something it can not argue with.
Definition of done or Completion goal?
| Block | Use it for | Example |
|---|---|---|
| Definition of done | What has to be true before the whole task is finished, and how to check it. | “Tests pass, the changelog is updated, no new warnings.” |
| Completion goal | A piece of work that repeats until it passes. | “Fix and re-run the failing tests, at most 3 times.” |
Many skills need only a Definition of done. Add a Completion goal when the skill tells the agent to try again. Try both in the block guide: change a field and watch the markdown and the checks update.
Let Skill Builder find where a loop helps
You do not have to spot loops yourself. The Checks tab looks at each skill’s and agent’s steps:
- A step that runs a check (
npm test,pytest,cargo test, a lint or type check, or “run the tests”) with nothing saying what to do when it fails. - A step that repeats until something holds, with nothing saying when to stop.
Each shows a suggestion with Add a Completion goal. One click adds the block after the steps, with the goal and the check filled in from the command. Read it, adjust the words to your project, and you are done.
Add a Completion goal by hand
- Open the skill or agent in Skill Builder.
- In the block library, add Completion goal (or press + and pick it). The (i) button next to any block explains it first.
- Fill in the fields:
- Goal: one or two sentences saying what is true when it is finished.
- Check each round: the command, test or tool call that proves it, in a code span or block.
- Rounds at most: 3 is the default. Pick fewer for slow or costly checks.
- Stop early when a round fixes nothing new: leave it on.
- If not met: the default asks the person whether to continue, and stops with a report when no one can answer (for example a run in CI).
- Open the Checks tab and fix any loop warning it shows.
It writes markdown like this:
## Completion goal
Every check in `npm run check` passes.
**Check each round:**
Run `npm run check` and read the first failure.
**Rounds:** at most 3. Stop early when a round fixes nothing new.
**If not met:** Ask the person whether to continue, with what still fails and what you would
try next. If no one can answer, stop and report instead.
What the checks look for
| Check | Shown as | Means |
|---|---|---|
loop-opportunity |
Suggestion | A step runs a check, but nothing says what to do when it fails. Add a Completion goal fixes it. |
loop-implied |
Suggestion | A step repeats until something holds, with no limit. Add a Completion goal fixes it. |
loop-no-limit |
Warning | The loop has no maximum number of rounds. Limit to 3 rounds fixes it. |
loop-limit-high |
Info | More than 10 rounds. Results rarely improve that late without a person looking. |
loop-no-goal |
Warning | The Completion goal does not say what finished means. |
loop-no-check |
Warning | Nothing proves each round, so the agent judges its own work. |
loop-check-tool-missing |
Warning | An agent’s check runs a command, but its tools can not run one. |
loop-side-effects |
Warning | The loop pushes, deploys, publishes, sends or deletes. Ask before each round, or do it once after the loop. |
loop-without-done |
Info | There is a loop but no Definition of done for the task as a whole. |
done-vague |
Suggestion | A criterion such as “it works” can not be checked. Say what proves it. |
Each finding says why it matters and where the rule comes from. See how to validate skills, agents and AGENTS.md for the rest of the checks.
The same loop in every AI tool
The Completion goal is plain markdown in the skill or agent, so Claude Code, Codex and GitHub Copilot all read it and follow it the same way. Nothing in it is specific to one tool.
What makes a loop reliable is the same everywhere: a check the AI can run, a small limit, and asking when the limit is reached. In every tool the loop is guidance the agent follows, so those three things are what keep it on track.
Separate the maker from the checker
For bigger jobs, split the work: one agent makes the change, another checks it, and a lead agent runs the rounds. The checker gets read-only tools (Read, Grep, Glob), so it can not quietly fix what it was meant to judge.
You do not have to set this up by hand. In Add, choose Template, then Evaluator–optimizer workflow under Workflows: it adds the maker skill, the read-only checker and the lead agent with the Completion goal, already linked. Undo in the message removes all three. The links are Skill reference and Agent reference blocks, which every AI tool reads.
Let Connect AI improve a skill in rounds
With Connect AI, your AI tool can run the same kind of loop on a skill in Skill Builder:
- Type
/improve-untilin Claude Code or Copilot Chat. In Codex, ask it to improve the skill with Skill Builder: it gets the same routine fromget_standards. - It measures the skill, fixes the smallest problems first, checks again (only what changed comes back), and re-runs the tests that failed.
- It stops when the skill’s goal is met, after 3 rounds, or when a round fixes nothing new.
- Skill Builder computes the before and after. The AI asks before rewording or deleting, and never saves a version on its own.
For a run with no one watching, ask for the safe mode (/improve-until with mode safe). It only applies fixes marked safe (a link, a name, a path, a loop limit), never rewords or deletes, never stops to ask, and ends with a report of what it left for you. Undo AI changes undoes it all.
To compare AI tools, run /evaluate-skill from each of them. Results are shown per tool. See how to test skills and agents.
Checklist
- The goal says what is true when it is finished, in words you could check.
- The check is a command, test or tool call, not “make sure it is right”.
- There is a limit, and it is small.
- Outward actions (push, deploy, publish, send, delete) happen once, after the loop, or ask first.
- A checker agent has read-only tools.
- The skill passes the checks in Skill Builder, and its tests pass in each AI tool you use.