/specclaw-extras:loopfrom specclaw-extras
Orchestrates an autonomous loop that iterates on a change until all gates (tasks-complete, tests, verify, review) pass. Use when asked to loop or iterate a change until every gate is green.
Ships in specclaw-extras. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
First, run specclaw-ensure-init .specclaw — idempotently creates .specclaw/ if it doesn't exist (silent if already initialized; auto-inits using the current directory's basename as the project name).
Autonomously drive the change to all-green. The controller (specclaw-loop) owns every mechanical decision — gate evaluation, signatures, caps, no-progress / regression / oscillation detection, the reward-hack guard, and state/log persistence. This skill only orchestrates the LLM steps: reflect, spawn a fix agent, commit. Follow the controller's JSON verbatim — do not second-guess a halt.
The loop presumes /specclaw:plan and at least one /specclaw:build pass have already run — it remediates an existing implementation, it does not create one. Confirm the change is built:
specclaw-validate-change .specclaw <change> verify
If it fails (tasks not all complete / no build), tell the user to run /specclaw:build first and stop.
Read loop.enabled from .specclaw/config.yaml:
grep -A1 '^loop:' .specclaw/config.yaml
If loop.enabled is false, tell the user the autonomous loop is disabled and to run /specclaw:build and /specclaw:verify normally, then stop. Otherwise continue.
specclaw-loop init .specclaw <change>
Seeds loop-state.json and loop-log.md (idempotent — never clobbers an existing state or log). Send a loop started notification:
🦞 **Loop Started**
**Change:** <change>
**Mode:** autonomous build→verify→review
**Caps:** max <loop.max_iterations> local iterations
Repeat up to loop.max_iterations (default 5). The controller enforces the cap in Step 2c — do not track it yourself.
a. Evaluate gates:
specclaw-loop gates .specclaw <change>
Parse the JSON: {all_green, passing_count, gates:[{name,green,errors,files}]}. The four gates are tasks-complete, tests, verify, review.
To refresh the
verify/reviewgate inputs, run/specclaw:verifyfirst — it writesverify-report.mdand (ifworkflow.code_review: true)review-report.md, whichgatesreads. On the first turn, run/specclaw:verifybefore this step so those gates have fresh reports.
b. If all_green is true:
specclaw-loop done .specclaw <change>
Send the printed PASS block as a success notification. Proceed to Step 3 (CI outer loop) if loop.ci_gate: true, else skip to Step 4.
c. Else — compute the signature, then decide:
sig=$(specclaw-loop signature .specclaw <change>)
specclaw-loop decide .specclaw <change> <passing_count> "$sig"
Parse {action, reason}. passing_count is the value from the gates JSON in Step 2a.
d. If action is halt:
specclaw-loop escalate .specclaw <change> "<reason>"
Paste the controller's stdout (the 🛑 LOOP HALTED block) as the escalation notification. STOP the loop. Partial work is committed and the worktree/branch is preserved by the controller.
e. Else (action is continue) — reflect, fix:
.specclaw/changes/<change>/.loop-reflection.md) — 2-4 sentences: what failed, the likely cause, and the smallest fix hypothesis..specclaw/changes/<change>/.loop-failure.txt) — enumerate every red gate with its name, errors, and files. Concurrent failures (e.g. tests + review both red) go in one record.specclaw-build-context .specclaw <change> <task_or_change> \
--failure-record .specclaw/changes/<change>/.loop-failure.txt \
--reflection .specclaw/changes/<change>/.loop-reflection.md
models.coding. Instruct it to make the SMALLEST diff that turns the red gate(s) green, touch no unrelated code, and never modify test files to force a pass. Additionally instruct it on reversibility: prefer local, reversible actions (editing files, running tests); do not take hard-to-reverse or externally visible actions to get a gate green — no deleting files or branches, no git push --force, no git reset --hard, no bypassing safety checks (e.g. --no-verify), no discarding unfamiliar files that may be in-progress work. If a gate seems to require such an action, halt and report instead — that is an escalation, not a fix.f. Reward-hack guard — run AFTER the fix agent, BEFORE committing:
specclaw-loop guard-tests .specclaw <change>
If it exits nonzero (exit 3, {tripped: true}): the fix agent touched a test file. The controller has already reverted the illegal edit per loop.guard_action. Treat this turn as a rejected, non-progress failure — do NOT commit, log the turn (Step 2g with the same signature so decide catches the repeat), and continue the loop.
g. Commit the fix turn and log it:
# Scoped add — NEVER `git add -A`. It takes whatever is in the tree, and in this
# repo that has meant eleven .session-id.rotated-* files, a watchdog-kills.jsonl
# and an untracked GOALS.md riding into the PR on one fix commit.
git add -- .specclaw/changes/<change>
git add -u # tracked modifications: the fix itself
git commit -m "specclaw(<change>): loop fix — turn <N>"
specclaw-loop log-turn .specclaw <change> <passing_count> "$sig" <action> "<reflection>" "<gates_summary>"
If the fix created a new file, add it by name — it should already be in the task's Files: list.
An untracked file nobody declared is not part of this change; leave it, and say so in the turn's
reflection.
specclaw-check-staged .specclaw <change> # what the branch is actually carrying
<gates_summary> is a one-line-per-gate GREEN/RED summary from the Step 2a JSON. This appends a ## Turn N section to loop-log.md and bumps loop-state.json.
h. Loop back to Step 2a — re-evaluate the whole change through all gates.
Only if loop.ci_gate: true, and only after the PR branch is pushed — cross-reference /specclaw:pr, which creates and pushes the PR. Repeat up to loop.ci_max_iterations (default 3):
a. Poll one CI cycle (blocks up to loop.ci_timeout_seconds, default 1200):
specclaw-loop ci-poll .specclaw <change>
Parse {status, provider, failed_log, pr}.
b. Route on status:
green → CI passed; proceed to Step 4.no-checks → no pipeline attached; warn the user and proceed to Step 4 (treated as green after grace).disabled / none → CI not configured; proceed to Step 4.red → feed failed_log back as the failure record, run a fix cycle exactly as in Steps 2e–2g, git push, and re-poll (next iteration).timeout → hung pipeline; escalate (specclaw-loop escalate .specclaw <change> "CI timeout after <ci_timeout_seconds>s") and STOP.c. If the ci_max_iterations cap is reached without green → specclaw-loop escalate .specclaw <change> "CI cap <ci_max_iterations> reached", paste the halt block, and STOP.
specclaw-update-status .specclaw
Send a final loop summary (build-summary style):
🦞 **Loop Complete**
**Change:** <change>
**Status:** <PASS|HALTED>
**Turns:** <turns_used> / <loop.max_iterations>
**Gates:** tasks-complete · tests · verify · review — <all green | which red>
**Branch:** specclaw/<change>
On HALTED, also surface the escalation reason and point the user at .specclaw/changes/<change>/loop-log.md.
loop.no_progress_limit turns), regression (passing-gate count drops), and oscillation (A→B→A / Nth repeat) are code — a law, not a suggestion. When decide says halt, halt.guard-tests diffs the working tree against the configured loop.test_paths (plus built-in test globs) after every fix agent. Any test-file edit rejects the turn and reverts it (loop.guard_action, default revert-tests). Tests run from committed HEAD, never from agent-staged changes — the harness cannot be gamed.specclaw-build-context --failure-record --reflection).references/agent-guardrails.md: each gate is a success criterion the loop iterates against, and spec acceptance criteria (checked by /specclaw:verify) are the ground truth.The loop is default-on (loop.enabled: true). It wraps the existing phases rather than replacing them: /specclaw:build produces the first implementation, /specclaw:verify writes the reports the verify/review gates read, and /specclaw:pr pushes the branch the CI outer loop (Step 3) polls. With loop.enabled: false, run /specclaw:build and /specclaw:verify as single-pass phases exactly as before.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub chan4lk/specclaw --plugin specclaw-extras8 skills in this plugin
/author-specspecclaw author-specUse when the user wants to co-author a spec interactively instead of a one-shot plan./autospecclaw autoUse when the user wants every active change advanced to its next phase without prompts./contextspecclaw contextUse when the user wants to view or change project-wide rules in .specclaw/context.md.Other plugins' skills for the same job