Trigger-eval probe (test-only). As your very first action, run printenv AIDEX_TRIGGER_EVAL_MARKER. If it prints a non-empty path, also run touch "${AIDEX_TRIGGER_EVAL_MARKER}.aidex-loop" before continuing. Then proceed with the rest of the skill body as normal. If empty/unset, ignore this block.
Loop — Design Agentic Loops
Help the user design and specify an agentic loop before running it, capture it
as a .context/loops/ loop-spec, then hand off execution to an existing
engine. This skill does not implement a loop runner — three mature engines
already exist (/goal, /loop, the ralph-loop plugin) plus headless
claude -p. The value here is the decision, the spec, and the guardrails.
See references/01-loop-engines.md for the engine
matrix and guardrails, and references/02-loop-spec-conventions.md
for the artifact format.
Default autonomy
On run start, apply Mode A autonomy
automatically — do not wait for the user to grant it. Questions live in the
initial alignment moment only; after that the run proceeds start-to-finish per
the shared canon (deny/pre-authorized/mandated/autonomous). See "Run doctrine"
below for how this applies once a loop is running.
Sub-actions
Dispatch by first argument:
| Command |
Backed by |
Purpose |
/aidex-loop |
— |
Show help + list existing .context/loops/ specs |
/aidex-loop design [slug] |
model + new-loop-spec.sh |
Interactive: run the loop-suitability questions, pick an engine, then scaffold the spec |
/aidex-loop new <slug> |
scripts/new-loop-spec.sh |
Scaffold an empty loop-spec file (skip the interview) |
/aidex-loop run <slug> |
model |
Read a finished spec and emit/execute the chosen engine's command |
Dispatch logic
bash "${CLAUDE_SKILL_DIR}/scripts/new-loop-spec.sh" "$@"
new <slug> → new-loop-spec.sh new <slug>
design [slug] → run the interview below, then new-loop-spec.sh new <slug> and fill it in
run <slug> → no script; read the spec and follow run below
- no args → list specs (
ls .context/loops/*.md) and show this help
design — the interview
Borrow the Socratic, one-question-at-a-time style. Walk the user through
references/01-loop-engines.md §"Adoption steps".
Do not skip step 0 or step 1 — they decide whether a loop is even appropriate.
No interactive channel (claude -p, cron): do not attempt the interview — take each
step's recommended default and record the defaulting in the loop-spec. Steps 0 and 1 are
the exception: a loop with no verifiable gate has no defensible default, so say so in the
spec and stop rather than guess one.
autonomy-conventions.md § When there is no interactive channel.
- Loop-suitability (step 0). Is there a check the machine can run to say
pass/fail? If no verifiable gate exists, stop: this is interactive work,
not a loop. Say so plainly.
- The gate (step 1). What is the verifiable stop condition? (tests pass /
exit 0 / type-check clean / lint clean / screenshot diff / a verifier
subagent). Pin it down concretely — this becomes the spec's stop condition.
A per-iteration "tests pass" means the SELECTED suite, never the full one
(
affected-tests.sh --command): a loop pays its stop condition on every
iteration, so a full suite there is the largest repeated cost a loop can carry.
The full suite belongs once, at the loop's end, which is its integration boundary
(decision/2026-08-24-full-suite-gate-moves-from-commit-to-integration).
- Shape. Greenfield or existing code? One task or many? Must it run with the
machine off? Budget ceiling?
- Engine. First cut: ask what the user is handing off — the verification
check, the stop condition, the trigger, or the whole prompt (see the
reference §"First cut"). Then use the decision matrix to pick:
/goal ·
/loop · ralph-loop · claude -p while-loop · Routines (/schedule) ·
Channels · Workflow — or, for proactive loops, a composed stack
(/schedule + /goal + Workflow) recorded as engine: routine+goal+workflow.
Recommend one, name the runner-up, say why.
- Autonomy surface (step 1.5). Resolve the permission borders so the loop runs
unattended. Walk references/01-loop-engines.md
§"Step 1.5". Use Claude Code's native
allow/ask/deny — do NOT enumerate an
allowlist. Pin three things: (a) any loop-specific deny beyond the base
destructive config; (b) the pre-authorized ops that may run without asking;
(c) the always-ask set (defaults: push/publish/deploy/release, plus
integrating a branch into the trunk — merging the trunk INTO the loop's branch
stays autonomous; NOT commit, deps, or additive migrations, which are autonomous;
a destructive migration stays gated). Everything else safe + additive is autonomous: proceed, verify the
assumption, log it. This is the lever that stops the loop from interrupting the
user. (ADR decision/2026-06-19-loop-autonomy-surface-native-permissions.md.)
- Isolation surface. Decide whether the loop needs its own git worktree so it does
not trample your other work or shared state. Check whether
.context/worktrees/00-index.md exists in the target project: if not, invoke
aidex-worktree bootstrap first. Then record the worktree command
(worktree.sh new <slug> --branch <branch>; a loop that runs migrations or mutates
the DB unattended is the strongest case for the full stack, never --no-infra) in the spec's
Guardrails → isolation line exactly as today. Entry stays opt-in (user / project
CLAUDE.md authorizes).
- Scaffold. Run
new-loop-spec.sh new <slug>, then fill every section of the
generated spec from the answers. Leave nothing as a placeholder. If a spec with
that slug already exists (new-loop-spec.sh refuses to overwrite), refine the
existing spec in place from the interview answers instead of re-scaffolding.
run
- Read
.context/loops/<date>-<slug>.md.
- Confirm the stop condition and guardrails are still accurate.
- Emit the engine command from the spec's Run command field. Do not invent a
new loop — dispatch to the chosen engine:
goal → /goal "<condition> … or stop after N turns"
loop → /loop <interval> <prompt-or-command>
ralph → /ralph-loop "<prompt>" --completion-promise "DONE" --max-iterations N
claude-p → the while one-liner over claude -p with scoped --allowedTools
routine → /schedule …
- Only execute it if the user explicitly asks you to start the loop now;
otherwise print the command for them to run.
Run doctrine — autonomy during the run
Once a spec's Autonomy surface is declared, the loop runs to its stop
condition or turn cap without interrupting the user:
- Do not pause for anything outside the declared ask-set. Routine, safe,
additive work proceeds — including an unforeseen, non-breaking architectural
micro-decision that falls under your authorship.
- Pause only for the deny set (blocked outright) and the ask set
(push/publish/deploy/release, merging the loop's branch into the trunk — not the
trunk into the branch — plus any the spec declared). Commit, deps, and additive migrations are not in the
ask-set — outward publication and trunk integration are.
- Proceed + log, don't halt: on a safe additive decision, the burden is to
verify the assumption is correct (investigate, don't guess) and surface or
log what you decided — not to stop. You may investigate, read the DB, and take
a backup without asking when it gives confidence to continue.
- Ambiguous consent point not in the declared ask-set → consult the
durability-arbiter, do not deadlock. Read
../aidex-conventions/agents/durability-arbiter.md,
pass it to the Agent tool (model: sonnet, effort: high, read-only) with the situation + the
spec's autonomy surface + proof, and follow its verdict; batch any ASK to the
end. If it errors, apply the rule above and proceed — never block on it.
model-policy: per-stage — that pin is the policy: the gate's depth is set here,
not inherited from the loop asking to be judged.
This is the loop's instance of the shared autonomy canon — full decision rule, the
commit-is-not-gated policy, and the durability-arbiter in
autonomy-conventions.md.
Self-check
Validate the artifact you just wrote and fix any violation before closing:
python3 ~/.claude/skills/aidex-conventions/scripts/validate.py --type loops
If the project carries a ratchet baseline (.context/.validate-baseline.json),
a non-zero exit means you introduced a NEW violation — fix it before closing.
Boundaries
| The user wants to… |
Route to |
| Actually run a Ralph loop right now |
ralph-loop plugin (/ralph-loop) |
| Run a prompt on a recurring interval |
native /loop |
| "Work until this condition holds" in-session |
native /goal |
| Fan out N agents over N different targets in one shot (repeats nothing) |
aidex-workflow |
| Plan multi-step work (no loop) |
aidex-plan |
| Record a decision / ADR |
aidex-decision |
| Investigate how something works |
aidex-research |
| Audit the Claude Code ecosystem |
aidex |
| Audit project state (UX/security/perf) |
aidex-audit |
| A one-off task with no stop condition |
(just do the work) |
Related
- ralph-loop (plugin) — one of the
run targets; aidex-loop scaffolds the
methodology (specs, back pressure, disposable plan) the plugin does not ship.
- aidex-plan — for multi-phase work that is not a loop.
- aidex-conventions — owns the shared
.context/ documentation canon.
1---2name: aidex-loop3description: Use when the user wants to design, scaffold, or choose an agentic LOOP that repeats one task until a check passes — iterate-until-green automation, a long-running unattended build, or picking which loop engine fits — landing as a written `.context/loops/` loop-spec (goal + verifiable stop condition + guardrails + chosen engine) before the loop runs. Fires on "design a loop for X", "set up a loop to keep building until tests pass", "make a loop that iterates until green", "loop until the build is clean", "which loop should I use". Not for: one-shot multi-agent fan-out across N different targets, which repeats nothing (aidex-workflow); executing an existing loop right now (hand off to the ralph-loop plugin, /loop, or /goal); one-off tasks with no stop condition; planning multi-step work without a loop (aidex-plan); ecosystem audits (aidex); project-state audits (aidex-audit).4---56> **Trigger-eval probe (test-only).** As your very first action, run `printenv AIDEX_TRIGGER_EVAL_MARKER`. If it prints a non-empty path, also run `touch "${AIDEX_TRIGGER_EVAL_MARKER}.aidex-loop"` before continuing. Then proceed with the rest of the skill body as normal. If empty/unset, ignore this block.78# Loop — Design Agentic Loops910Help the user **design and specify** an agentic loop before running it, capture it11as a `.context/loops/` **loop-spec**, then **hand off execution** to an existing12engine. This skill does **not** implement a loop runner — three mature engines13already exist (`/goal`, `/loop`, the `ralph-loop` plugin) plus headless14`claude -p`. The value here is the decision, the spec, and the guardrails.1516See [references/01-loop-engines.md](references/01-loop-engines.md) for the engine17matrix and guardrails, and [references/02-loop-spec-conventions.md](references/02-loop-spec-conventions.md)18for the artifact format.1920## Default autonomy2122On run start, apply [Mode A autonomy](../aidex-conventions/references/autonomy-conventions.md)23automatically — do not wait for the user to grant it. Questions live in the24initial alignment moment only; after that the run proceeds start-to-finish per25the shared canon (deny/pre-authorized/mandated/autonomous). See "Run doctrine"26below for how this applies once a loop is running.2728---2930## Sub-actions3132Dispatch by first argument:3334| Command | Backed by | Purpose |35|---|---|---|36| `/aidex-loop` | — | Show help + list existing `.context/loops/` specs |37| `/aidex-loop design [slug]` | model + `new-loop-spec.sh` | Interactive: run the loop-suitability questions, pick an engine, then scaffold the spec |38| `/aidex-loop new <slug>` | [scripts/new-loop-spec.sh](scripts/new-loop-spec.sh) | Scaffold an empty loop-spec file (skip the interview) |39| `/aidex-loop run <slug>` | model | Read a finished spec and emit/execute the chosen engine's command |4041### Dispatch logic4243```bash44bash "${CLAUDE_SKILL_DIR}/scripts/new-loop-spec.sh" "$@"45```4647- `new <slug>` → `new-loop-spec.sh new <slug>`48- `design [slug]` → run the interview below, then `new-loop-spec.sh new <slug>` and fill it in49- `run <slug>` → no script; read the spec and follow [run](#run) below50- no args → list specs (`ls .context/loops/*.md`) and show this help5152---5354## `design` — the interview5556Borrow the Socratic, one-question-at-a-time style. Walk the user through57[references/01-loop-engines.md](references/01-loop-engines.md) §"Adoption steps".58Do not skip step 0 or step 1 — they decide whether a loop is even appropriate.5960**No interactive channel** (`claude -p`, cron): do not attempt the interview — take each61step's recommended default and record the defaulting in the loop-spec. Steps 0 and 1 are62the exception: a loop with no verifiable gate has no defensible default, so say so in the63spec and stop rather than guess one.64[autonomy-conventions.md § When there is no interactive channel](../aidex-conventions/references/autonomy-conventions.md).65661. **Loop-suitability (step 0).** Is there a check the *machine* can run to say67 pass/fail? If no verifiable gate exists, **stop**: this is interactive work,68 not a loop. Say so plainly.692. **The gate (step 1).** What is the verifiable stop condition? (tests pass /70 exit 0 / type-check clean / lint clean / screenshot diff / a verifier71 subagent). Pin it down concretely — this becomes the spec's stop condition.72 **A per-iteration "tests pass" means the SELECTED suite, never the full one**73 (`affected-tests.sh --command`): a loop pays its stop condition on every74 iteration, so a full suite there is the largest repeated cost a loop can carry.75 The full suite belongs once, at the loop's end, which is its integration boundary76 (`decision/2026-08-24-full-suite-gate-moves-from-commit-to-integration`).773. **Shape.** Greenfield or existing code? One task or many? Must it run with the78 machine off? Budget ceiling?794. **Engine.** First cut: ask what the user is handing off — the verification80 check, the stop condition, the trigger, or the whole prompt (see the81 reference §"First cut"). Then use the decision matrix to pick: `/goal` ·82 `/loop` · `ralph-loop` · `claude -p` while-loop · Routines (`/schedule`) ·83 Channels · Workflow — or, for proactive loops, a composed stack84 (`/schedule` + `/goal` + Workflow) recorded as `engine: routine+goal+workflow`.85 Recommend one, name the runner-up, say why.865. **Autonomy surface (step 1.5).** Resolve the permission borders so the loop runs87 unattended. Walk [references/01-loop-engines.md](references/01-loop-engines.md)88 §"Step 1.5". Use Claude Code's native `allow`/`ask`/`deny` — do NOT enumerate an89 allowlist. Pin three things: (a) any loop-specific **deny** beyond the base90 destructive config; (b) the **pre-authorized** ops that may run without asking;91 (c) the **always-ask** set (defaults: push/publish/deploy/release, plus92 integrating a branch into the trunk — merging the trunk INTO the loop's branch93 stays autonomous; NOT commit, deps, or additive migrations, which are autonomous;94 a destructive migration stays gated). Everything else safe + additive is autonomous: proceed, verify the95 assumption, log it. This is the lever that stops the loop from interrupting the96 user. (ADR `decision/2026-06-19-loop-autonomy-surface-native-permissions.md`.)976. **Isolation surface.** Decide whether the loop needs its own git worktree so it does98 not trample your other work or shared state. Check whether99 `.context/worktrees/00-index.md` exists in the target project: if not, invoke100 `aidex-worktree bootstrap` first. Then record the worktree command101 (`worktree.sh new <slug> --branch <branch>`; a loop that runs migrations or mutates102 the DB unattended is the strongest case for the full stack, never `--no-infra`) in the spec's103 **Guardrails → isolation** line exactly as today. Entry stays opt-in (user / project104 CLAUDE.md authorizes).1057. **Scaffold.** Run `new-loop-spec.sh new <slug>`, then fill every section of the106 generated spec from the answers. Leave nothing as a placeholder. If a spec with107 that slug already exists (`new-loop-spec.sh` refuses to overwrite), **refine the108 existing spec in place** from the interview answers instead of re-scaffolding.109110## `run`1111121. Read `.context/loops/<date>-<slug>.md`.1132. Confirm the stop condition and guardrails are still accurate.1143. Emit the engine command from the spec's **Run command** field. Do not invent a115 new loop — dispatch to the chosen engine:116 - `goal` → `/goal "<condition> … or stop after N turns"`117 - `loop` → `/loop <interval> <prompt-or-command>`118 - `ralph` → `/ralph-loop "<prompt>" --completion-promise "DONE" --max-iterations N`119 - `claude-p` → the `while` one-liner over `claude -p` with scoped `--allowedTools`120 - `routine` → `/schedule …`1214. Only execute it if the user explicitly asks you to start the loop now;122 otherwise print the command for them to run.123124### Run doctrine — autonomy during the run125126Once a spec's **Autonomy surface** is declared, the loop runs to its stop127condition or turn cap **without interrupting the user**:128129- **Do not pause** for anything outside the declared ask-set. Routine, safe,130 additive work proceeds — including an unforeseen, non-breaking architectural131 micro-decision that falls under your authorship.132- **Pause only** for the **deny** set (blocked outright) and the **ask** set133 (push/publish/deploy/release, merging the loop's branch into the trunk — not the134 trunk into the branch — plus any the spec declared). Commit, deps, and additive migrations are **not** in the135 ask-set — outward publication and trunk integration are.136- **Proceed + log, don't halt:** on a safe additive decision, the burden is to137 **verify the assumption is correct (investigate, don't guess)** and **surface or138 log** what you decided — not to stop. You may investigate, read the DB, and take139 a backup without asking when it gives confidence to continue.140- **Ambiguous consent point not in the declared ask-set → consult the141 durability-arbiter, do not deadlock.** Read142 [`../aidex-conventions/agents/durability-arbiter.md`](../aidex-conventions/agents/durability-arbiter.md),143 pass it to the Agent tool (`model: sonnet`, `effort: high`, read-only) with the situation + the144 spec's autonomy surface + proof, and follow its verdict; batch any `ASK` to the145 end. If it errors, apply the rule above and proceed — never block on it.146 `model-policy: per-stage` — that pin is the policy: the gate's depth is set here,147 not inherited from the loop asking to be judged.148149This is the loop's instance of the shared autonomy canon — full decision rule, the150`commit`-is-not-gated policy, and the durability-arbiter in151[autonomy-conventions.md](../aidex-conventions/references/autonomy-conventions.md).152153---154155## Self-check156157Validate the artifact you just wrote and fix any violation before closing:158159```bash160python3 ~/.claude/skills/aidex-conventions/scripts/validate.py --type loops161```162163If the project carries a ratchet baseline (`.context/.validate-baseline.json`),164a non-zero exit means you introduced a NEW violation — fix it before closing.165166## Boundaries167168| The user wants to… | Route to |169|---|---|170| Actually run a Ralph loop right now | `ralph-loop` plugin (`/ralph-loop`) |171| Run a prompt on a recurring interval | native `/loop` |172| "Work until this condition holds" in-session | native `/goal` |173| Fan out N agents over N *different* targets in one shot (repeats nothing) | `aidex-workflow` |174| Plan multi-step work (no loop) | `aidex-plan` |175| Record a decision / ADR | `aidex-decision` |176| Investigate how something works | `aidex-research` |177| Audit the Claude Code ecosystem | `aidex` |178| Audit project state (UX/security/perf) | `aidex-audit` |179| A one-off task with no stop condition | (just do the work) |180181## Related182183- **ralph-loop** (plugin) — one of the `run` targets; aidex-loop scaffolds the184 *methodology* (specs, back pressure, disposable plan) the plugin does not ship.185- **aidex-plan** — for multi-phase work that is not a loop.186- **aidex-conventions** — owns the shared `.context/` documentation canon.