Harness engineering for your repo: a worked example
2026 is almost over. In February, harness engineering was a phrase in a few blog posts. Mitchell Hashimoto used it for fixing an agent's mistakes so they never happen again. OpenAI used it for how a small team shipped a million-line product with Codex.
Now DeepSeek and AWS ship harnesses as products. DeepSeek Harness arrived in August, built so that every part is a plugin, down to the agent loop. Strands harness arrived in September. AWS reported that it cost 28% less than other harnesses on the same models, with similar accuracy.
Those are harnesses you adopt. Most of us will keep running Claude Code or Codex against a repository we already have. The part of the harness we control is the files in that repository. So how should you engineer those files?
I tested that with one prompt, run twice on the same model. Only the repository changed between the runs.
TL;DR
- The model is not the agent. A harness is everything around the model. The part that encodes how your team works lives in your repository.
- Most instruction files hold noise, and some hold mistakes. Audit yours twice: once with
/doctor, and once with tests you write. - An instruction is a request, not a guardrail. Move every rule that must hold into a hook, a deny rule, or a script.
The model is not the agent
Anthropic defines a harness as "the tools, context management, and execution environment that turn a language model into a capable coding agent." Claude is the model. Claude Code is the harness around it.
Changing only the harness changes results. LangChain held its model fixed and took its coding agent from 52.8% to 66.5% on Terminal Bench 2.0, which moved it from the Top 30 to the Top 5. Can Bölük changed only the edit tool and took one model from 6.7% to 68.3% on his editing benchmark.
Hashimoto's definition of harness engineering is the one I use: "anytime you find an agent makes a mistake, you take the time to engineer a solution such that the agent never makes that mistake again."
Every agent has the same seven subsystems
The clearest map I have found is a source-code study of eleven coding agents, including Claude Code, Codex CLI, Gemini CLI, and Aider. Each one has the same seven subsystems, with the agent loop at the centre. An interface layer sits outside all seven, and you drive the agent through it.
The agent loop calls the model, runs a tool, reads the result, and decides what to do next. Every other subsystem connects through the loop.
You did not write any of this, because Claude Code ships all seven. You cannot change Claude Code's code. You can change what it reads.
Your team process is not in the repository
Your team has a process. Branch off main, run the checks, open a draft PR, and get a human to read the diff. New engineers learn it from a teammate, a review comment, or a Slack thread that nobody can find twice.
An agent cannot read any of those. So it guesses, as my first run did. A longer prompt does not help, because the next session starts with an empty context window and you type the same preamble again.
A convention counts only if every teammate, every CI run, and every agent picks it up without being told. The one place that reaches all three is the repository. An agent cannot follow a convention it cannot see.
How you engineer each subsystem
You can reach six of the seven subsystems from a file you commit. This version of the diagram has a sticky note on each block that names the file or setting that reaches it.
The two grey notes mark the limits:
- The agent loop is fixed in Claude Code. No file changes its stop conditions. The Claude Agent SDK exposes the loop, with a turn cap, a spend cap, and a callback on every tool call.
- You change the interface layer by choosing it. Pick the CLI, an IDE extension, the desktop app, or the SDK.
Files that load every session cost context every turn
The diagram does not show when each file loads, and load time sets the cost. Anything that loads at session start stays in context on every turn, whether the task needs it or not.
- Every session:
CLAUDE.md,AGENTS.md, MCP servers, and enabled plugins. - Only when needed: skills, subagents, and path-scoped rules in
.claude/rules/. - On every tool call: permission rules in
.claude/settings.json. - At fixed points in the session, such as before a tool call: hooks.
- When something runs them: scripts.
Chroma tested 18 models and found that they get less reliable as input grows, even on simple tasks. A second study found that instruction-following gets worse as the number of instructions rises. The strongest models scored 68% when given 500 instructions. Every line in CLAUDE.md competes with every other line for the model's attention.
Loading is not obeying
CLAUDE.md loads every session, but the model can still ignore it. Anthropic's best practices state the difference: "unlike CLAUDE.md instructions which are advisory, hooks are deterministic and guarantee the action happens."
Birgitta Böckeler splits a harness into guides and sensors. Guides steer the agent before it acts, like CLAUDE.md and skills. Sensors check the result after it acts, like tests, linters, and the hooks that run them. With guides alone, she writes, you get "an agent that encodes rules but never finds out whether they worked."
The eleven-agent study saw the same move across the field. Behavioural policy is "migrating from prompt prose to configuration".
Audit and improve your harness
The two runs come from a hands-on lab I wrote against Excalidraw, the open-source whiteboard app. I seeded its CLAUDE.md with the kind of team conventions I see in real repositories, and made a few of them subtly wrong.
The order matters. I audited the harness twice, ran the first prompt, had Claude rebuild the harness, then ran the same prompt again. Every sample here comes from recorded runs on Opus 5. Claude is non-deterministic, so your results will differ.
Start Claude Code at the root of a clean checkout. Each prompt below goes into that session.
Audit one: run /doctor
/doctor checks your setup and proposes changes. One of its checks trims a checked-in CLAUDE.md by cutting what Claude can work out from the code.
It cut the file from 1,711 characters to 480. By /doctor's estimate, about 80% of the file repeated what the repository already says:
- The directory tour repeats
ls. - The command list repeats the
scriptsblock inpackage.json. - The UI component map repeats a directory listing.
It also caught two lines that were plausible and wrong. The file said to run yarn lint, but no lint script exists. The real script is yarn test:code. A pointer to Notification.tsx named a file that is actually Toast.tsx. In /doctor's words, "a session following that line hunts for a missing file."
That is how a harness rots. Nobody writes a wrong line on purpose. The code changes, and nobody updates the instructions.
But /doctor kept a line that it should have cut: "Always run yarn test:update before committing." That command rewrites failing snapshots to match the current output. If Claude follows it after a real regression, the failing test passes and you commit the bug with a green report.
/doctor. The yarn test:update line survives the cut.Review the trim with git diff CLAUDE.md, then commit it. A git worktree receives only committed files, and the second run works in a worktree.
Commit the CLAUDE.md trim with a short message.Audit two: judge each line against your own tests
/doctor picks what to check. In the second audit, you pick. Run this prompt in the same session. The scope line keeps the findings on the repository instead of your personal config.
Audit this repository's harness and write the result to harness-audit.md.
Look only at project-level files: CLAUDE.md, AGENTS.md, and whichever of .claude/rules/, .claude/skills/, .claude/agents/ and .claude/settings.json exist here. Ignore my personal config in ~/.claude.
Judge every instruction against these tests:
- Would removing this line cause Claude to make a mistake? If not, it's noise.
- Could Claude derive this by reading the code? If so, it doesn't belong in an always-loaded file.
- Is it a fact, a guardrail, or a procedure? Facts belong in CLAUDE.md, guardrails in hooks or permissions, procedures in skills.
- Does it say "always" or "never" while nothing enforces it?
- Is it still true? Check every command against package.json and every path against the tree.
Output a table: instruction, what it is, where it should live, is it enforced, is it still correct. Put anything factually wrong at the top.The first three tests come from Anthropic's guidance. I added the last two. Add your own as you find mistakes worth checking for every time.
Claude wrote the result to harness-audit.md. It found three problems.
One line did damage. The audit read the CI workflow and found that CI runs the tests without --update. The test:update line in CLAUDE.md told Claude to do the opposite of what CI does.
One line was wrong because /doctor wrote it. During its trim, /doctor added a note under the lint rule: "This is not enforced automatically." The note is true of the pre-commit hook. It is false for the repository, because .github/workflows/lint.yml runs yarn test:code on every pull request. /doctor read the hook, and the second audit read the workflow. The two audits read different files, so run both.
One line was noise. "Always document non-obvious logic changes with comments." Delete the line and Claude still comments non-obvious logic. The line changes nothing and costs context on every turn.
The conventions that this repository enforces, like its ban on barrel imports, already live in ESLint. ESLint is the right place for them. A failing lint check teaches the rule when someone breaks it, and it costs no context. Before you write a hook for a rule, check whether CI already enforces it.
The first run commits straight to the main branch
Before rebuilding anything, I asked for a change the way I would at work. The prompt points to a team process that no file in the repository describes.
Fix this: the Toast close button has no accessible title. Then follow our team process.The fix was correct. The process was the one from the opening of this post: the shared checkout, two of the four checks, a commit to the main branch, and "Done." Undo that commit before you rebuild the harness.
Undo that commit, but keep everything else. Revert only the Toast change, then show me git log and git status.Improve it: tell Claude where each rule belongs
I did not write any harness file by hand. One prompt did the work. It has three parts, in this order: fix what the audit found, state the team process, and say where each piece belongs.
Now improve this harness. Fix what the audit found, and add the one thing it could not know: our team process.
Correct every instruction you marked as factually wrong, and cut anything you marked as derivable from the code.
Our process, which no file in this repo currently states:
- Every code change starts in its own git worktree. Never edit the shared checkout. Share the main checkout's node_modules so the worktree needs no install.
- After the change, run the full merge gate in order and report each result.
- QA the change against its acceptance criteria, and state what you checked and how.
- A pull request always opens as a draft, and you ask a human to validate it before it leaves draft. There is no gh CLI here, so write the PR body to PR-DRAFT.md in the worktree and end it with a line asking for validation.
- Never use yarn test:update to make a failing test pass.
Apply these rules while you build it:
- A prohibition that must hold belongs in a hook or a permissions deny rule. An instruction is a request, not a guardrail, so pick the strongest layer each rule can live in.
- A step that should never vary belongs in a script.
- A procedure belongs in a skill, loaded on demand, not in every context window.
- CLAUDE.md must still answer three questions for a session that reads nothing else: what this project is and how it is laid out, how to verify a change, and where the team process is written down. Keep those as short pointers, not copies.
- Prefer pointers to copies everywhere: name a file or a command rather than pasting its contents, so the harness cannot go stale.
- Leave code style to the linter. If eslint or prettier already enforces something, it does not need a line in CLAUDE.md.
- CLAUDE.md must end up shorter than you found it, and use emphasis only where it is load-bearing.
- Whatever you add must still pass yarn test:other, since the repo's prettier check covers markdown and JSON.
- Keep CLAUDE.md as the canonical file and make AGENTS.md point to it with a symlink.
Then show me the harness as a file tree, and for each file say which layer it is and whether it is advisory or enforced.In this post, the merge gate means the four checks that CI runs: typecheck, lint, format, and tests.
The second block is your team's process. No tool can find it for you, so replace it with your own. The third block, the routing rules, is the part most people leave out. It works in any repository, and three of its lines do most of the work:
- "An instruction is a request, not a guardrail." This line moves
test:updateout of prose and into something that blocks it. - Procedures go in skills. A skill loads only when the task needs it, instead of in every context window.
- The three questions. They stop the trim from going too far, so
CLAUDE.mdstill tells a new session how to verify its own work.
Having Claude write the guardrails is a documented path. Anthropic's docs say "Claude can write hooks for you."
The harness Claude built
CLAUDE.md 4 lines
AGENTS.md -> CLAUDE.md symlink
.claude/
├── settings.json hooks + deny
├── hooks/
│ ├── require-worktree.sh
│ └── block-snapshot-update.sh
├── scripts/
│ ├── new-worktree.sh
│ └── merge-gate.sh
└── skills/
└── change-workflow/SKILL.mdCheck the skill's path before you go on. A skill loads only from .claude/skills/<name>/SKILL.md, with name and description frontmatter. One of my runs left it at .claude/skills/merge-gate.md, where it never loads.
CLAUDE.md became four lines. I shortened them slightly here:
- Monorepo, layout in
package.jsonworkspaces. - Verify a change:
.claude/scripts/merge-gate.sh. - Every change follows the
change-workflowskill. - Use
app.ownerDocument, not globals; lint misses it.
The first three lines point to a file, a script, or a skill, so they stay true while those targets keep working. The fourth records a convention that no linter catches.
OpenAI's team reached the same design. Their AGENTS.md is roughly 100 lines, and they treat it as "the table of contents" instead of the encyclopedia.
Claude put each process rule in the strongest layer that could hold it:
| Rule | Landed in |
|---|---|
| Work in a worktree | Script + hook |
| Run the merge gate | Script |
| QA against criteria | Skill |
| Draft PR, human validates | Skill |
Never test:update | Hook + deny rule |
Prohibitions became hooks. Fixed steps became scripts. Judgement stayed in the skill, because no script can check whether a criterion was really met.
Claude runs a script only if it remembers to call it. So each script has an enforced check behind it. The hook blocks edits outside a worktree, and CI runs the same checks as the merge gate on every pull request.
Commit the harness, because the second run works in a worktree.
Commit everything with a short message.Run the same prompt again
Claude Code loads skills and hooks at session start. So exit, start a new session, and paste the identical prompt. Add no mention of skills or worktrees.
Fix this: the Toast close button has no accessible title. Then follow our team process.
The skill loaded because "our team process" matched the skill's description. The edit happened in a worktree, not in the shared checkout.
The rest of the run is the right side of the diagram at the top of this post. The lab has no gh CLI, so the skill wrote the PR description to PR-DRAFT.md in the worktree. The file ends with a request for validation. On a real team, the same skill would open a draft pull request instead.
The failing check was the most useful result
The merge gate reported that the format check failed. This change did not cause the failure. Prettier flagged CLAUDE.md, which still had a formatting problem from the /doctor trim. The first run never ran the format check, so nobody had noticed.
Claude did not slip a markdown fix into an accessibility change. It traced the failure to the base commit and asked me how to handle it.
The harness also produced a better fix
I asked for an accessible title and also got a translation fix. The QA step made Claude check how the four other close buttons in the repository set their titles. They all use the translated buttons.close key, so the Toast button now uses it too.
Without the harness, the first run would have needed five more prompts to reach this result: use a worktree, run the full merge gate, don't commit to the main branch, match the other buttons, and tell me what you verified. With the harness, you write those instructions once.
What a harness does not do
Claude was no better at TypeScript at the end than at the start. The first run wrote a working fix with no help. The harness changed everything around the edit: where the edit happened, how it was checked, and who approved it.
A harness does not make an agent more capable. It narrows how much the agent's runs vary. You still work with a non-deterministic model, so two runs of one task still differ. If you measure a harness by whether the model gets smarter, you will conclude that it does nothing.
Fix each mistake once
Each time an agent gets something wrong, change the harness so that the mistake cannot happen again. Usually that means moving one rule to a stronger layer: from prose to a skill, from a skill to a script, or from a script to a hook.
Three signs tell you that the harness needs another pass:
- You type the same preamble for the third time. Put that sentence in a file.
- The agent does the task correctly, but not the way your team does it. The harness is missing a convention. The model is not the problem.
- A convention exists only in a review comment or a Slack thread. Move it into the repository, or the agent cannot follow it.
Check the date on any harness advice, including this post. Anthropic keeps a list of practices it has since replaced. Advice from six months ago can describe a product that no longer behaves that way.
What's next
Try this on a repository you work in. Run /doctor, the audit prompt, and the improve prompt with your own process in the second block.
Then hand the work off. At level 4 of Dan Shapiro's five levels of AI coding, you write the spec, leave for 12 hours, and check the tests. A remote coding agent makes that possible. You steer less while a task runs, so the harness has to hold.
To try one, deploy the sample from the guide I co-wrote on running Claude Code as a remote agent on Amazon Bedrock AgentCore. It runs several tasks in parallel in your own AWS account, each in its own microVM, and each comes back as a pull request for you to review.