loop-eng — Loop Engineering for Claude Code
The best model is worth less than the best loop. You stop prompting the agent;
you design the system that prompts it.
loop-eng brings Loop Engineering to Claude Code as an installable plugin:
two self-driving loops built on maker/checker separation, machine-verifiable
contracts, disk-persisted state, hard stop rules — and a Stop hook that
mechanically refuses to let a session quit while its contract is unsatisfied.
Install
/plugin marketplace add sdsrss/loop_eng
/plugin install loop-eng@loop-eng
loop-eng@loop-eng is plugin@marketplace. The qualified form is the one this
project's own release smoke runs against a real install (RELEASING.md §1), so
it is the one documented here; the bare loop-eng may resolve too, but nothing
here has verified that.
After a marketplace install the commands may resolve namespace-prefixed —
/loop-eng:autoloop and /loop-eng:polish — if the bare /autoloop /
/polish form does not resolve.
Requirements
Bash and git are the baseline. Everything below is probed at run time, and the
table says which way each probe falls: most degrade on a documented path, four
of them weaken a guard (rows 1-4, and each says so on the stream it has —
the difference between a degrade and a silent one; the one exception is
arm-contract.sh's advisory per-criterion red-check in row 3, which simply runs
unbounded), and two refuse outright rather than degrade — but each in one
place only: a missing claude CLI stops install-timer.sh, not the drivers
(they resolve it lazily and fail at run time), and bash < 4.4 stops the
unattended drivers, not the hooks. None of this belongs only in a script
comment, which is where it lived before.
| Tool |
Used by |
Absent → |
jq or python3 |
evidence-gate.sh |
the gate goes inert — it cannot parse the hook event, so it allows every write and says so on stderr (no jq or python3 available). See the note below. |
sha256sum / shasum / openssl |
arm-contract.sh, run-contract.sh |
the contract arms without a hash-lock, so post-arm drift no longer fails closed. arm-contract.sh warns at arm time. |
timeout / gtimeout |
stop-gate.sh, arm-contract.sh, unattended-autoloop.sh |
the contract runs unbounded on each stop attempt; the near-timeout fail-closed guard is inactive and the gate says so. Keep criteria.tsv fast. |
timeout / gtimeout |
unattended-polish.sh |
its wall-clock budget is unbounded and the run says so on stderr, where the scheduler's log keeps it. LOOP_ENG_MAX_MINUTES then has no effect. |
curl |
update-notify.sh |
no update-available notices. Silent by design. |
systemctl --user |
install-timer.sh, uninstall-timer.sh |
scheduling is unavailable; use cron, or LOOP_ENG_TIMER_NO_SYSTEMCTL=1 to write (and remove) the unit files only. |
claude CLI |
install-timer.sh (checked), unattended-*.sh (not checked) |
install-timer.sh refuses outright — it resolves the binary at install time and probes it under the unit's own minimal PATH, so this is a hard dependency there, not a degrade. The drivers do not check: they take ${LOOP_ENG_CLAUDE_BIN:-claude} and fail when they try to run it. Point LOOP_ENG_CLAUDE_BIN at the binary if it is not on PATH. |
| bash ≥ 4.4 |
unattended-*.sh only |
the drivers refuse to start (exit 78) rather than dying partway through — checked at run time, not just stated in a header. The hooks and their contract scripts (stop-gate.sh, evidence-gate.sh, update-notify.sh, arm-contract.sh, run-contract.sh) run on stock macOS bash 3.2, and all five are what the test-bash32 CI job covers — it runs their suites, and syntax-checks the scripts, through /bin/bash explicitly. |
An inert evidence-gate does not forfeit the completion invariant. The gate
is defense-in-depth on the write path; the stop-gate is the load-bearing one,
and it needs no JSON parser. Verified on a parser-less box: a hand-forged
{"all_green": true} in .loop/results.json is overwritten by
run-contract.sh on the next stop attempt (generated_by flips back,
all_green returns to false) and the stop is still blocked. What you lose
without a parser is the early, explanatory denial — not the guarantee.
The two loops
/autoloop <task> — drive a bounded task to completion
contract (binary acceptance criteria, verify commands)
└─> builder implements ──> checker verifies ──┐
^ │
└── full failure report, verbatim <────┘
until ALL GREEN, max 5 rounds, six stop rules
- Builder and checker are separate subagents. The checker has no
Write/Edit tools — separation is enforced by tool whitelists, not trust.
- Every claim of "done" is a checker report, never the builder's opinion.
- Six stop rules bound the loop: ALL GREEN · rounds exhausted · same root cause
twice in a row · regression · no progress for 2 rounds · capability boundary.
Any non-green stop escalates with what was tried and why more rounds won't help.
- State lives in
.loop/state.md and per-round git commits — the loop survives
context compaction and session restarts.
- The contract's checks live in
.loop/criteria.tsv (written at contract
time; the evidence-gate hook denies rewrites while the loop is armed).
Columns are TAB-separated — id<TAB>description<TAB>command. A line that
uses spaces instead parses as one field and cannot run, so arming warns and
the contract fails closed rather than going green over the criteria that
happened to parse. Every stop attempt machine-writes
.loop/results.json + .loop/evidence/<id>.log — completion is a
machine-written fact, not a model claim.
/polish [scope] [report-only] — iteratively raise code quality
numeric baseline (tests / lint / types)
└─> 4 independent review lenses (correctness, simplification,
test-coverage, consistency) — separate contexts, no cross-talk
└─> adversarial verification: a skeptic subagent tries to REFUTE
every finding; only confirmed findings enter the fix queue
└─> severity-ordered fixes (bugs get a failing test FIRST, then the fix)
└─> full regression, repeat — converges on a dry round
- Behavior-preserving by definition: anything that would change a public
contract (including deleting exported symbols) is deferred to you, not applied.
- Every improvement claim cites baseline vs. final numbers. No adjectives.
report-only mode finds and verifies without changing anything — the
required mode for scheduled runs until finding quality is proven.
How loop-eng relates to /goal and ralph-wiggum
Claude Code now ships loop primitives natively: /goal (v2.1.139+) keeps a
session working until a Haiku evaluator judges a condition met, and the
first-party ralph-wiggum plugin re-feeds a prompt until the model emits a
completion promise. loop-eng sits above that baseline:
|
native /goal |
first-party ralph-wiggum |
loop-eng |
| completion decided by |
small model reading the transcript (runs no commands) |
the working model emits a promise string |
the harness re-runs the contract's commands (run-contract.sh) |
| criteria |
one condition |
one prompt |
multi-criterion contract, per-criterion evidence log |
| builder/verifier separation |
none |
none |
enforced by tool whitelists |
| iteration bound |
until condition or manual clear |
unlimited by default |
5 rounds + 6 stop rules, bounded by default |
| completion evidence |
evaluator's yes/no |
model's self-report |
machine-written .loop/results.json + raw logs, model writes denied by a PreToolUse gate |
| state |
session-scoped |
session-scoped |
.loop/ on disk + git; survives restarts |
| unattended |
-p supported |
— |
nightly report-only polish + cross-session autoloop driver with circuit breaker and budgets |
Use /goal for single-condition supervision of interactive work; use
loop-eng when done must be a machine-verified, multi-criterion fact.
Stop-gate: enforcement, not promises
While .loop/active exists, the plugin's Stop hook re-runs the contract's
checks on every stop attempt — .loop/criteria.tsv (via run-contract.sh),
falling back to legacy .loop/verify.sh only when no criteria.tsv is present
(a criteria.tsv whose runner is missing fails closed rather than letting the
legacy script answer for it) — and blocks premature exit (exit 2 with the failure output fed back to the
model). A hard ceiling of 3 blocks
guarantees the gate can never deadlock a session, and the gate lifts itself
the moment the contract passes.
A companion PreToolUse hook (hooks/evidence-gate.sh) denies model writes
to .loop/results.json, .loop/evidence/, the armed criteria.tsv (plus
its criteria.sha256 hash-lock and, for a legacy loop, the verify.sh that
is its contract) and a .loop/backlog.md that carries any | verify: line —
that last lock is file-wide, not per-line: one such line freezes every line
in the file, ordered-list 1. [ ] items included — while the loop is armed (.loop/active
present) — via the Write/Edit tools this path is mechanically closed, so
"passes: true" can only be produced by running the command, never typed. While
armed it also denies a Bash rm/mv aimed at the whole .loop directory,
which would take the gate's marker, the hash-lock and the ledger in one
command; the refusal names the two-step form (rm .loop/active, then
rm -rf .loop). A subpath is unaffected — .loop/state.md is the
orchestrator's own scratch file and has never been guarded.
Escape hatch for humans: LOOP_ENG_DISABLE_EVIDENCE_GATE=1.
The armed contract is additionally pinned by a hash-lock: arm-contract.sh
records sha256(criteria.tsv), and run-contract.sh fails CLOSED if the live
file no longer matches — catching every write path, including Bash verbs the
gate's regex can't see. What this guarantees is that weakening an armed contract
can never pass silently; a fully adversarial model with arbitrary Bash that
rewrites both criteria.tsv and its hash-lock in lockstep is out of scope, left
to the red lines in the prompts and human review of the diff.
The hash-lock covers criteria.tsv only. A legacy loop's verify.sh has no
second layer — arm-contract.sh writes no hash for it — so its protection is
the evidence-gate alone: mechanically closed through Write/Edit/MultiEdit/
NotebookEdit, best-effort through Bash, using the same conservative verb pattern
whose limits the header of hooks/evidence-gate.sh states. Verbs outside that
pattern still reach it (ln, install, an interpreter one-liner, a path held in
a variable). Both shipped loops arm with a criteria.tsv, which is the shape
that gets the full guarantee.
A missing hash-lock used to be the quiet corner of that guarantee: with no
criteria.sha256 beside it, run-contract.sh simply skipped the integrity
check, and a lockless run looked exactly like a locked one. It no longer does.
When the loop is armed, the lock is absent, and a SHA-256 tool is available,
the run warns on stderr and stamps "contract_lock": "absent" into
results.json.
It reports the state, not a cause. Several routes lead there and the runner
cannot tell them apart: arm-contract.sh omits the lock on a machine that
cannot hash and when there is no criteria.tsv at arm time, the orchestrator's
documented last-resort arm is a bare touch .loop/active that never writes one,
and a lock removed after arming looks identical. What they share is the only
thing worth saying — the tamper check did not run, so a criteria.tsv weakened
after arming would pass unnoticed.
That is a warning, not a refusal: every one of those routes is legitimate, and
failing closed would strand a live loop whose only exit is deleting
.loop/active. The field is in the ledger rather than only on stderr because a
green contract lets the stop-gate exit 0, which discards hook output — so
"contract_lock" is what survives to the human reading the record.
Platform note: Claude Code force-allows a stop after 8 consecutive
Stop-hook blocks; loop-eng's ceiling (3) stays safely under it.
Bash compatibility: seven scripts run on stock macOS bash 3.2 — the three hooks
(stop-gate.sh, evidence-gate.sh, update-notify.sh), the two contract
scripts (arm-contract.sh, run-contract.sh) and the two timer scripts
(install-timer.sh, uninstall-timer.sh). This is tested in CI, not
asserted: a dedicated test-bash32 job runs their suites through macOS's
/bin/bash (3.2) on every push to main and every pull request, and
syntax-checks those same seven files.
The timer scripts are on that list because a macOS user runs them by hand, from
their own shell, to schedule anything at all — and they were verified under a
real 3.2.57 by hand for several releases without CI ever pinning it.
update-notify.sh belongs on that list for the plainest reason — it is a
SessionStart hook, so on a stock macOS box bash 3.2 is what runs it in every
real session. The unattended runners are the exception: they need bash ≥ 4.4
(empty-array expansion under set -u