A Claude Code skill that writes the loop — so your agent finishes the job, checks its own work, and repairs itself when it drifts.
mission ──▶ ┌──────────────────────────────────────────┐ ──▶ a lane a fresh
│ PLAN · CLAUDE · HARNESS · PROMPT │ session can drive
│ engine.mjs · LOOP.md · tick.sh · state │ autonomously, safely,
└──────────────────────────────────────────┘ for weeks
You give Claude Code a goal — "migrate the auth layer", "fix the N flagged practices", "integrate a sandbox API". harness-writer authors a complete, house-style lane: a timestamped folder a fresh session can pick up and drive on its own across many sessions, with three model layers, loops-within-loops, and adversarial gates.
It plans and writes the harness — then stops and hands it to you. You decide what runs. It never fires the first tick unprompted.
Note
This targets Claude Code specifically — its Fable/Opus/Sonnet model routing, the .mjs dynamic-Workflow runtime, and /loop + /goal. It is an authoring skill, not a general-purpose agent framework.
A one-shot prompt stops early, grades its own homework, and drifts off-mission over long tasks. A harness fixes all three — but hand-writing a good one (with honest rubrics, blind verification, and self-repair) is hard and easy to get subtly wrong. This skill encodes the doctrine so every harness you generate starts correct.
flowchart LR
A["🎯 Mission"] --> B["harness-writer<br/>(plans + authors)"]
B --> C["📁 Lane folder"]
C --> D["🔁 Driver loop<br/>(one tick at a time)"]
D --> E{"Blind<br/>verify"}
E -- pass --> F["✅ Commit locally<br/>(push = human only)"]
E -- fail --> G["🔧 One repair"]
G --> D
F --> H{"Mission<br/>done?"}
H -- no --> D
H -- yes --> I["🏁 SHIP gate<br/>(human-confirmed)"]
style B fill:#6E56CF,color:#fff
style E fill:#f59e0b,color:#fff
style I fill:#22c55e,color:#fff
| Failure mode | Symptom | The harness fix |
|---|---|---|
| Agentic laziness | stops before a multi-part task is done | state-driven loop-until-done (stop on STATE, never an iteration count) |
| Self-preferential bias | grades its own homework, passes weak work | a blind verifier in a separate context — sees artifacts + rubric + command output, never the maker's reasoning |
| Goal drift | per-task checks pass, but the mission wandered | a standing DriftGuard that checks the lane/mission, not the rubric |
Every generated harness is built as three nested loops, each owned by a different model tier:
flowchart TD
subgraph R2["🌀 Ring 2 — Mission loop · human + Fable · weeks"]
M["phase flips · triage decisions · retro"]
end
subgraph R1["🔄 Ring 1 — Driver loop · Fable · per wake-up"]
D["cheap gate → one tick → branch on return →<br/>persist state → local commit → reschedule"]
end
subgraph R0["⚙️ Ring 0 — Tick · the .mjs · one task"]
P["📝 Plan<br/>(Sonnet, rubric-first)"] --> I["🔨 Implement<br/>(Sonnet)"]
I --> V["🔍 Verify<br/>(Opus, blind)"]
V --> RP["🔧 one repair"]
RP --> GD["🛡️ Guard<br/>(Fable DriftGuard)"]
end
R2 --> R1 --> R0
style R2 fill:#1e293b,color:#fff
style R1 fill:#334155,color:#fff
style R0 fill:#475569,color:#fff
style V fill:#f59e0b,color:#fff
style GD fill:#6E56CF,color:#fff
| Role | Model |
|---|---|
| Supervisor · driver · DriftGuard · design gate | Fable (session model) |
| Blind verification · decision judging | Opus |
| Coding · research · heavy lifting | Sonnet |
flowchart LR
F["❌ Failure"] --> I["🔬 Investigate"]
I --> FX["🔧 Fix"]
FX --> R["🔒 Lock as a<br/>regression check<br/>(M1 ratchet)"]
R --> N["📈 Ratchet is<br/>non-decreasing"]
F -. "3 strikes" .-> CB["⛔ Circuit breaker<br/>(M2) → escalate"]
style F fill:#ef4444,color:#fff
style R fill:#22c55e,color:#fff
style CB fill:#f59e0b,color:#fff
| # | Mechanism | What it guarantees |
|---|---|---|
| M1 | Regression ratchet | a verified fix becomes a permanent re-runnable check; the guard set never shrinks |
| M2 | Circuit breaker | chronic failure halts + escalates after 3 strikes — never a retry-storm |
| M3 | Preflight health check | preconditions verified before work; fail-closed |
| M4 | Failure-driven repair | a failed tick enqueues a repair task; the loop closes |
| M5 | Cross-task DAG | tasks declare deps; cycles abort before any agent runs |
| M6 | Sharpened blind verify | verdict from exit codes, not prose |
| M7 | Fail-closed default | a tripped gate pauses to a human queue; never silent bypass |
Full detail in references/self-repair.md.
<slug>-harness_<YYYY-MM-DD>/
├── PLAN.md # workstreams + task ledger + human decision gates
├── CLAUDE.md # lane config · model routing · inherited non-negotiables
├── HARNESS.md # the three rings + every loop mapped to its mechanism
├── PROMPT.md # paste-into-a-fresh-session kickoff
├── harness/
│ ├── <slug>-loop.mjs # the engine (plan → implement → blind verify → repair → guard)
│ ├── LOOP.md # driver protocol (the only state writer)
│ └── tick.sh # pure-read gate → TICK | WAIT | SHIP | ERROR
└── state/
└── <slug>-state.json
classDiagram
class State {
+string phase
+Task[] tasks
+string[] done
+string[] distilledRules
+RegressionCheck[] regressionChecks
+map breakers
+Failure[] failures
+string[] triageInbox
}
class Task {
+string id
+string kind
+string status
+string[] deps
}
class RegressionCheck {
+string signature
+string command
}
State "1" o-- "many" Task
State "1" o-- "many" RegressionCheck
- 🔁 It self-repairs. Every harness ships the 7 mechanisms above.
- 🧠 It learns each run. After authoring, the skill distills new lessons back into its own doctrine and logs every change in
CHANGELOG.md. - 🚫 It refuses to fabricate. Hard rule: no figure or quote enters the doctrine without a
sources.mdentry with a URL + access status. The corrections log even documents a stat the skill once got wrong — and removed. - 🧩 It composes. Loop rings bind to deep, version-pinned playbooks (e.g. Addy Osmani's
agent-skillspack) instead of re-deriving generic prompts — seereferences/skill-rings.md. Binding is an upgrade, never a hard dependency.
As a Claude Code plugin (recommended):
/plugin marketplace add sasanksai/harness-writer
/plugin install harness-writer
Clone it yourself:
git clone https://github.com/sasanksai/harness-writer.git ~/.claude/skills/harness-writerThat's it — Claude Code auto-discovers skills in ~/.claude/skills/. Restart your session (or /reload-plugins if installed as a plugin).
Just ask Claude Code:
"write a harness for <mission>" · "build a loop for X" · "set up a lane"
sequenceDiagram
actor You
participant HW as harness-writer
participant Rev as Opus review
You->>HW: "write a harness for <mission>"
HW->>HW: scope → plan → author docs + engine
HW->>Rev: adversarial self-review (step 10)
Rev-->>HW: SHIP-READY / FIX-FIRST
HW->>HW: fix every finding, distill lessons (step 12)
HW-->>You: lane ready — pick the first move
Note over You,HW: it never runs the first tick unprompted
SKILL.md # the 12-step authoring procedure + red lines
references/
design-principles.md # distilled doctrine (the "why")
doc-templates.md # every document skeleton
mjs-template.mjs # the engine template
self-repair.md # the 7 self-repair mechanisms
skill-rings.md # loop-ring ↔ agent-skills binding map
sources.md # verified source ledger (anti-fabrication)
CHANGELOG.md # version history + distilled lessons
Doctrine distilled from public writing on agent harnesses and loop engineering — Anthropic's harness/eval guidance, Addy Osmani's Loop Engineering, Lance Martin, and others. Full ledger in references/sources.md.
MIT © 2026 Sasank Sai.R