Sprag

Claude Code harness: ratchet rules, evidence-gated completion, Plan-Execute-Verify

The Sprag harness for Claude Code turns repeated failures into rules that load every session, blocks "all done" reports with no evidence attached, and enforces a Plan, Execute, Verify cycle on multi-step work.

๐Ÿ…ท Harness mode

Bootstrap five engineering principles (Ratchet ยท Evidence ยท PEV ยท Structured Task ยท Default Safe Path) into CLAUDE.md with one command; the statusline scores it as ๐Ÿ…ท 5/5. When the same error keeps recurring, a ๐Ÿ…ทโš  ratchet? nudge appears so you can promote it to a rule.

sprag harness init                # this project
sprag harness init --global       # ~/.claude/CLAUDE.md โ€” every project
sprag harness check               # current score (global fallback honored)
sprag harness analyze             # run the transcript analysis manually (no hook needed); refreshes harness-state.json
sprag harness promote <N> --global|--project   # warning #N โ†’ ratchet rule (scope required)
sprag harness promote "<rule text>" --global|--project  # register your own hand-written rules the same way
sprag harness pull                # register the package's curated ratchet rules into your global ratchet (opt-in, dedupes)
sprag harness list / rm <N>       # view / delete rules (auto .bak)
sprag harness off | on            # toggle the ๐Ÿ…ท chip
โš ๏ธ harness rm โ€” checklist before deleting

The whole point of the ratchet is one-direction accumulation. Deleting rules casually means the same mistakes return.

An auto .bak is kept, but the session context that earned the rule its place is not recoverable.

๐Ÿ“ฆ compact-window โ€” pin where a 1M session compacts

Claude Code compacts when usage approaches min(autoCompactWindow, model max context). On a 1M window, with that value unset, compaction only fires near 800k โ€” and until then every request re-bills the whole context. 1M is too large; the recommendation is a 400kโ€“700k band โ€” 2โ€“3.5x a 200k session's headroom for the genuinely large pastes, with the runaway tail cut off.

Anything inside the band is left alone. 400k is the floor where the saving beats the extra compactions, and long sessions often want more room than that. Only an unset window, or one above 700k, is warned about (a smaller one is a deliberate, more aggressive choice).

200k sessions are never warned โ€” their window is already at or below 200k, so the setting cannot change anything.

sprag compact-window                       # status (model, window, value, source)
sprag compact-window set --global          # pin 500k (mid-band) in ~/.claude/settings.json
sprag compact-window set --project         # pin it in <root>/.claude/settings.json
sprag compact-window set --global --value 600k   # explicit value (100kโ€“1M)
sprag compact-window off | on              # toggle the warning

๐ŸŒฑ seed: delegation that works from the first session

The model-fitting ratchet (ratchet-model.md) starts empty. A rule exists only after route-scan has seen the same kind of work recur in your own logs and you have approved that candidate. So a fresh install delegates nothing, and keeps delegating nothing for days โ€” precisely the stretch where the savings would matter most.

seed fills that gap from presets bundled with the package.

PresetsWhat they coverFile
9 model-fittingrunning commands, lookup, status checks, questions about pasted logs, read-and-summarize โ€” each with a T2 (haiku) and a T1 (sonnet) rulepresets/model-rules.json
6 ratchetgeneral-purpose rules promoted from mistakes that actually recurredpresets/ratchet-rules.json

How they get registered: in the first session after an install or upgrade, the SessionStart hook hands the pending presets to the model, which walks the user through them one at a time. Each answer runs one of these immediately:

sprag seed                                   # pending presets + recorded answers
sprag seed accept <id> --global|--project     # register one (scope required)
sprag seed accept all --global                # when the user says "register them all"
sprag seed skip <id>                          # decline โ€” never offered again
sprag seed reset                              # clear the answers and offer everything again

More docs