The loop every agent on this machine runs, in any harness. Use when starting a non-trivial task, when driving work autonomously across many steps, when resuming a session, or when the user says "loop", "keep going", "work continuously", "run the loop", "until it passes". Defines PLAN - BUILD - VERIFY - RECORD, the state file that survives a context reset, stop conditions, and the escalation boundary. Compose with ambition for sizing and outside-judge for proof.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Agent Loop?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/frankxai-agent-loop)
---
name: agent-loop
description: The loop every agent on this machine runs, in any harness. Use when starting a non-trivial task, when driving work autonomously across many steps, when resuming a session, or when the user says "loop", "keep going", "work continuously", "run the loop", "until it passes". Defines PLAN - BUILD - VERIFY - RECORD, the state file that survives a context reset, stop conditions, and the escalation boundary. Compose with ambition for sizing and outside-judge for proof.
metadata:
derived_from: poteto/pstack sequence-verifiable-units + local autonomous-loops, continuous-agent-loop
owner: Frank
status: canonical
---
# Agent loop
Same loop in Claude Code, Codex, Grok and OpenCode. The harness changes; the loop does not.
## The four phases
**1. PLAN** — `ambition` sizes the work, `spec-spine` makes it checkable. Output: an ordered list of
units where each unit is independently verifiable and small enough to finish in one pass.
**2. BUILD** — one unit at a time. Do not start unit N+1 with unit N unverified. If a unit turns out
to be two, split it and re-enter PLAN for that piece.
**3. VERIFY** — `outside-judge`. Name the rung, run the judge, record real output. A unit that
cannot be judged is not a unit; it is a wish. Return to BUILD at most twice before escalating.
**4. RECORD** — write down what changed and what the judge said, in the state file, before the next
unit. This is what makes a context reset survivable.
## State file
One per task, written to disk, not held in context:
```markdown
# <task>
goal: <one line>
judge: <the command or measurement that decides success>
units:
- [x] <unit> — PASS (<rung>, <command>) <date>
- [ ] <unit> — in progress
- [ ] <unit> — blocked: <what is needed>
decisions: <one line per real decision, with the reason>
next: <the single next action>
```
Write it as `.loop/<slug>.md` in the working repo. `next:` must always be a single action. A loop
that cannot name its next action is stuck, not finished.
## Stop conditions
The loop stops when any of these is true:
1. **Every unit passes its judge.** Done. Report with evidence, including each unit's rung.
2. **A unit failed twice at the same judge.** Stop and escalate with what you tried and what the
failure actually was. Do not thrash.
3. **A step needs a decision only Frank can make** — money, credentials, publish, merge, delete,
or a product call. Stop, state the exact decision and your recommendation.
4. **The next action is ambiguous.** Stop. An ambiguous `next:` is a PLAN failure, and continuing
makes it worse.
5. **Two consecutive units produced no change in the judge's output.** That is spinning. Stop.
## Escalation boundary
The loop may do anything reversible on its own: read, write in the working repo, run tests, run
read-only commands, restart a dev server it started. It may not spend money, push to a protected
branch, publish, deploy, delete data, or touch credentials. Those become one line in the handback.
## Handback format
One batch, not a drip:
```
DONE <units passed, with judge rungs>
CHANGED <files, one line each>
BLOCKED <the decisions needed, each with a recommendation>
NEXT <what you would do if nobody answered>
```
## Why this beats a longer prompt
A loop with a state file and a judge can survive a context reset and a model swap. A long prompt
cannot. That is the whole point: the loop is the asset, the harness is disposable.