All Recipes

Harness Engineering: an environment for an autonomous agent

A harness-engineering hub: a five-layer environment, the four-phase route a task travels, barriers vs conventions, and the lessons-ledger as the autonomy core. With an interactive explorer and a series map — how to set up any project so a coding agent runs a task from framing to push with almost no supervision.

AdvancedAI DevOps30 minClaude Code, AGENTS.md, ExecPlan, pre-commit, CI
1

A harness is an environment, not a prompt

A harness isn't a prompt or a beefier model. It's the environment around the agent: a set of sources of truth it reads at the start and along the way. Same idea as the harness-engineering lesson, but the lens is the development process itself, not the in-app loop — how to get a project into a state where a coding agent runs a task with almost no supervision. The environment is built from five layers — from the global (how you work with an agent at all) to the project-specific (the rules of this exact repo) and cross-session memory. The more layers in place, the less the agent improvises and the rarer it breaks for no reason.
Personal playbook (global)
Your collaboration rules (R1..RN), loaded every session
Process skills / recipes
Brainstorm, plan, TDD, verify — how to run recurring procedures
Project contract (AGENTS.md)
Working rules, Definition of Done, the lesson retrieve rule
ADR + roadmap
Recorded decisions and where you are in building the harness
Cross-session memory
Learned preferences; frequent ones → candidates for playbook/lessons
Layers go in bottom-up by cost of adoption, not by importance. A personal playbook and ADRs are cheap and meet no resistance — start there; sensors and the ledger cost more and come later.
2

Four phases: how a task travels from framing to push

A harness turns a 'task' into a four-phase route: A — framing & scope (one thread = one task, check recipes, a plan if needed); B — design (sketch before code, ADRs for decisions, read the boundary's lessons); C — implementation loop (TDD, run sensors, live-update, /wrong, escalation); D — close (verify, ritual, doc-sync, commit, handoff). It's not a strict 0→24 line. The human plugs in at exactly four points — give the task, approve the sketch, say 'wrong', say 'commit'. The agent drives the rest. Play with the explorer below: filter by phase, open step details, and run the scenarios — big feature, bugfix, docs edit, correction, escalation.

Agent Harness — a universal template

STACK- & AGENT-AGNOSTIC

Give the agent not just a task but an environment that guides it: the contract (what to read), the living plan (what not to forget), sensors (what may not ship), lessons (what not to repeat), the closing ritual. Every step either reads a source of truth or writes an artifact. The human plugs in at 4 points: give the task · approve the sketch · say "wrong" · say "commit".

The R-codes in the step cards are rules Claude Code accumulated from corrections across different projects; I collected them into one personal playbook and wired it globally, so they load every session. Each code shows its meaning inline.

🟥 BARRIERenforced mechanically (pre-commit/CI)🟦 CONVENTIONrests on the agent's discipline🟨 CONDITIONALfires only on a trigger
PHASE A · Framing & scope · step 1/24

Task arrives

🟦 CONVENTIONwho: 👤actionrule: one thread = one task · R1
R1brevity: one fix = 1–2 lines

One thread = one task; never mix contexts.

EXAMPLE: AGENTS.md "One thread = one task"
What keeps you from forgetting
Agent context file
AGENTS.md (+ addendum: CLAUDE.md / .cursorrules / system prompt)
The contract: read at the start of every session.
Personal playbook
global rules, loaded every session
Your collaboration style (R1..RN), not project-specific.
Living plan
plans/YYYY-MM-DD-*.md
Progress / Decisions / Surprises — as you go.
ADR catalog
decisions/NNNN-*.md
Why we decided this way.
Lessons ledger
harness/lessons/<boundary>/
What NOT to repeat; matures → a sensor.
Sensors (gates)
boundary-linter · lint · types · size · test-integrity
Barriers on every commit/CI.
Skills / recipes
reusable procedure recipes
How to do a recurring task.
Roadmap / rollout
HARNESS_ROLLOUT.md
Where you are in building the harness.
Cross-session memory
agent memory store + index
Learned context; frequent → into playbook/lessons.
Doc-freshness check
doc-drift check script
Docs don't lag behind code.

Flow walk: how a task moves

step 1/21: 1 Task arrives · 👤 · 🟦 CONVENTION
almost the whole route; /wrong and escalation are event-driven and didn't fire here.
Framing & scope
1Task arrives
2Check recipes / skills
3Brainstorm / clarify intent
4Plan mode (or plan-only)
Design & plan
5Sketch before non-trivial code
6A plan for tasks > 1 day
7An ADR for a significant decision
8Isolate the work
9Read the boundary's lessons
10Decompose to ≤ 1–2 days
Implementation loop
11TDD: failing test first
12Implementation
13Run the sensors
14Verify the build / runtime
15Live-update the plan
16"Wrong" → /wrong
17Escalate on doubt
18Don't commit while debugging
Close & push
19Verification before completion
20Closing ritual
21Doc + code sync + freshness
22Atomic commit + push
23Handoff to the next session
24Memory: preferences

Honest about this flow: it isn't a strict line. Phase C is a loop; /wrong, escalation and commit are event-driven; conditional steps fire on a trigger and are often skipped. Only the 🟥 barriers are truly enforced — the rest rests on the agent's discipline.

The best way to grok a harness is to run the 'mid-flight correction' scenario: you see how 'wrong' doesn't kill the task but loops it back into phase C — a cycle, not a rollback to the start.
3

Barriers vs conventions: what actually gets enforced

The most common harness failure is confusing 'written in the rules' with 'actually followed'. A barrier is enforced mechanically: pre-commit and CI won't let code ship if it fails a check. A convention rests only on the agent's discipline — written in AGENTS.md, but nothing checks it. A conditional step fires on a trigger and is often skipped. The good news: barriers are off-the-shelf, cross-stack tools. Import boundaries: dependency-cruiser / import-linter; dead code: knip / ts-prune; cycles: madge; nesting and size: eslint (max-depth, max-lines). What isn't covered, you add as your own check script. Whatever you can't put a barrier on, you can't rely on for long.

🟥 Barrier

  • Enforced mechanically: pre-commit / CI
  • e.g. JS/TS: dependency-cruiser, knip, madge, tsc
  • Not covered? Your own check script

🟦 Convention

  • Rests on the agent's discipline
  • Stated in AGENTS.md, but unchecked
  • Code style, "no drive-by rewrites"

🟨 Conditional

  • Fires only on a trigger
  • ExecPlan, worktree, escalation, /wrong
  • Often — and correctly — skipped
Don't turn a metric into a target. '100% coverage' as a mandate breeds fake tests — that's Goodhart. A barrier should catch a real class of bugs, not please a dashboard.
4

Lessons-ledger: corrections as code

The autonomy core is the lessons-ledger: a mechanism that turns your corrections into code rather than a forgotten chat. You tell the agent 'wrong' → the /wrong command runs normalize, which splits a fork. A computational lesson (the mistake is machine-catchable) → a sensor edit: a new linter rule, a type check. An inferential lesson (judgement needed) → a markdown file the agent reads before working on that boundary. A separate maintain step promotes matured inferential lessons into sensors. The health metric is how many lessons graduated into barriers, not the size of the notebook: the goal is for knowledge to harden into machine checks, not pile up as text.
"Wrong" → /wrong
normalize
machine-catchable
Computational → sensor
needs judgement
Inferential → lesson
matured
maintain: promote to sensor
/wrong "<mistake>"
  → normalize:
      machine-catchable? → sensor       # computational (barrier)
      needs judgement?   → lessons/<boundary>/  # inferential (nudge)
  → maintain: matured inferential → promote → sensor
health metric = lessons promoted to sensors, NOT notebook size
A lesson is written only after your 'ok' — not in the heat of annoyance. A correction made while irritated often turns out to be your own framing mistake, not the agent's fault.
5

Series map: the 9 rollout phases

This recipe is a hub. A series follows it, where each rollout phase unfolds into its own recipe with copyable prompts. The front door is 'four modes of developing with AI' (A/B/B+/C): the meta-decision of how much AI a project even needs. Not everyone needs full agent-first — a harness is mandatory for modes B+/C and barely needed for A/B. Below is the series map: from picking a mode and auditing to scaling out. Each row is its own recipe; walk the phases in order or jump straight to the one you need.
PhaseWhatRecipe
EntryPick a mode: A / B / B+ / Cdev-modes-with-ai — done ✓
0Audit an existing project: baseline + environmentproject-audit — done ✓
1Context engineering: AGENTS.md, ADRagents-md-setup — done ✓
2ExecPlan for multi-hour tasksexecplan-long-tasks — done ✓
3Architectural barriers, strict typesarchitectural-constraints — done ✓
5Garbage collection: drift, debtharness-garbage-collection — done ✓
5.5Lessons-ledger: corrections as codelessons-ledger — done ✓
6Skills: reusable SKILL.mdagent-skills-library — done ✓
7Workflow: one thread, worktrees, subagentsagent-workflow-worktrees — done ✓
8Scaling: template repo, golden pathharness-template-golden-path — done ✓
Tool: stack → tools, DoD, artifactsharness-configurator — done ✓
If you're unsure whether you need a full harness, start at the front door — the modes. A team in mode B (human leads, AI speeds up typing) will waste time building infrastructure for an agent it doesn't need.
6

Where to start: cheap → contentious

Where to start without drowning? Order from cheap-and-uncontroversial to expensive-and-contentious. First an ADR: pin down your tool choices — that's for humans, no resistance. Then a Definition of Done — one checklist for what 'done' means. Then sensors — turn the DoD into machine barriers (pre-commit + CI). And only then the lessons-ledger — it pays off once barriers exist and there's something to promote into them. Every layer is useful on its own. You don't have to build it all at once: one real barrier today beats a perfect quarter-long plan.

Rollout order (recommended)

1. ADR for tool choices — cheap, for humans
2. Definition of Done — one checklist
3. Sensors — the DoD as machine barriers
4. Lessons-ledger — once barriers exist
Building everything before the first barrier
Coverage 80/100% as a mandate (Goodhart)
'Machine over text': one working pre-commit hook disciplines the agent more than a paragraph of rules in AGENTS.md that's easy to ignore.

Result

A harness-engineering hub: you understand that a harness is a five-layer environment, how a task flows through four phases, why only barriers are enforced (not text), and how the lessons-ledger turns corrections into code. Next: a per-phase recipe series and an entry point via choosing your development mode.