• AI development
  • Testing

What actually makes a coding-agent harness cheaper and better

My harness for Claude Code had grown for a year. Investigate, write a spec, review it, plan each slice, build test-first, verify, recap. It worked. It was also expensive, and I no longer knew which parts earned their cost.

A harness is everything around the model: instruction files, skills, hooks, gates, the process the agent must follow. Every piece of it costs tokens. So I asked one simple question: which parts change the result, and which only cost tokens?

To answer it I ran 19 controlled experiments. Each changed one thing and measured the effect on the same task: building one slice of a feature in a Blazor WebAssembly application from an approved spec. Two independent judge agents scored every build on acceptance criteria, on planted bugs caught by the tests, on weak tests and on cost.

The short version

The build cost fell from 5.57 USD to 1.81 USD per slice (−67%). The tests became stronger at the same time: a real page-level integration test, and a mutation score of 100% on the slice's code.

The final run missed my strict quality floor by two minor test gaps, and most conditions were run once. So the last figure is an indication, not a proven mean.

Three things made a measurable difference:

  • removing duplicate work;
  • keeping tool output out of the context;
  • replacing written testing rules by a mechanical check (mutation testing).

Three things did not: shortening or adding instruction text, removing paperwork, and regrouping tool calls. A cheaper model (Sonnet 5.5) held the quality once the mechanical check was in place.

And the results agree with Anthropic's published guidance on almost every point I could test.

The method

Task and baseline

  • Codebase: a Blazor WebAssembly line-of-business application, with unit, UI (bUnit) and integration test projects.
  • Task: build slice 1 of a "CSV export" feature from an approved spec with 11 acceptance criteria (file name with local date, sorted rows across pages, localized headers, quoting, formula-injection guard, a log record without personal data, and so on).
  • Agent: Claude Code, unattended, with a fixed prompt, a fixed tool allow-list and a cap of 300 turns. Opus 5.5 unless stated.
  • Baseline: the harness as it was (kit 2.5.6), built three times: 5.59, 5.64 and 5.48 USD. Mean 5.57 USD, spread ±1.5%.

What I measured

Two judge agents scored each build. Neither had seen the build session.

JudgeWhat it measures
Build judgeAcceptance criteria met (of 11); gate green (0 warnings, all tests, formatting); 2 bugs planted after the build and whether the tests catch them; code quality (0–5)
Coverage judge10 planted bugs (M1–M10) and how many the tests catch; weak tests (cannot fail, or only check a constant or a mock); whether a real integration test exists; line coverage

Cost is the build job's cost in USD. I also recorded turns and the tokens re-read from cache, as a proxy for context size.

Quality floor: 11/11 criteria, 10/10 planted bugs, 0 weak tests, a real integration test.

The loop

Every experiment followed the same cycle.

  1. Propose one improvement, with a reason taken from the previous analysis.
  2. Modify the harness (a new kit version or a setup change) and install it on the fixed baseline commit.
  3. Measure: one unattended build, then both judges.
  4. Analyse: cost, turns and context against the reference; the judges' findings.
  5. Decide: adopt, reject or "not alone". Adoption required at least 5% lower cost with the quality held, or better quality at an accepted cost.
  6. Next: the following proposal comes from what the analysis showed, not from a fixed list.

An adopted change became the new reference for the next experiment.

A defect in my own method

After experiment 10 I found a bug in my runner. It started each session on the repository's default branch and switched to the experiment commit afterwards. Claude Code loads the instruction file, the unscoped rules and the lists of skills and agents at session start. So changes to always-loaded text were never in effect in experiments 1–10.

The consequences: experiment 6 (shorter instruction text) is void, and absolute costs before the fix carry extra text. I fixed the runner so sessions start on the experiment commit, re-measured the reference in isolation at 4.29 USD, and re-tested the instruction-text question in experiments 11–12 and 15.

Phase 1: cost at equal quality

Experiments 1 to 10.

#ChangeCost USDDecision
baseKit 2.5.65.57reference
1No slice-plan file, no separate analysis build, short recap4.78 (−14%)adopted
2Every build and test through a fresh sub-agent8.57 (+54%)rejected
3Many small targeted builds and tests6.37 (+33%)rejected
4Fewer, more targeted tests4.61 (−4%)not alone
5Integration test first, slice gate filtered to it4.77 (0%)adopted with 4: first real integration test at equal cost
6Always-loaded instructions −55%4.78 (0%)void (see the method defect)
7Quiet build and test output, read once4.11 (−14%)adopted
8Write all tests, then all code (batching)4.60 (+12%)rejected
9No recap file, no spec edits4.04 (−2%)not adopted
10Parallel independent tool calls5.62 (+37%)rejected

Result of phase 1: 5.57 → 4.11 USD (−26%) with the quality held.

Phase 2: how much harness do you need?

Experiments 11 and 12.

RunHarnessCost USDCriteriaPlanted bugs
Isolated referenceFull kit 2.5.94.2911/1110/10
11bMinimal harness, no spec, from the one-paragraph request3.425/118/10
11cMinimal harness with the approved spec3.9610/1110/10
12Kit 2.6.0: build skill cut from 22.6 KB to 3.1 KB4.3311/1110/10

Without the spec, the agent built less. No date in the file name, no log record, no empty state, and an unrequested grid filter. The saving was real, but it came from building a smaller feature.

With the spec, a minimal harness reached almost the same quality as the full process.

Cutting the build instructions by 86% changed neither cost nor quality.

Phase 3: test quality

Experiments 13 to 19. The judges kept finding the same weaknesses: tests written after the code, tests that could not fail, an integration test that bypassed the page. I tried three ways to fix this.

#ChangeModelCost USDCriteriaBugsWeak testsIntegration test
13Home-made check "each test was seen failing first"Opus4.6711/1110/101bypasses the page
14Same check, correctedOpus5.3111/1110/100bypasses the page
15Seven written rules for efficient testsOpus4.9410/1110/101bypasses the page
16Rules + mutation testing as the slice gateOpus5.0911/1110/100drives the page
17Mutation gate packaged, stricter, whole changed filesOpus5.7811/1110/101bypasses the page
18Same as 17Sonnet 5.53.2211/1110/100bypasses the page
19Mutation on changed lines only; outer test must drive the pageSonnet 5.51.8110/1110/101drives the page
  • The home-made check failed twice (13, 14) on details of the test runner's output. It blocked correct builds and cost more.
  • Written rules changed nothing (15). The build broke the very rules it had been given.
  • Mutation testing worked (16). Fewest tests of the series, none weak, and an integration test that caught five of the ten planted bugs by itself.
  • Scope matters (17, 18). When the tool mutated whole files, the agent wrote tests for existing code to reach the threshold. In experiment 18, 11 of 12 new view-model tests were off-scope.
  • Limiting the check to changed lines removed that (19). 38 of 38 mutants killed, 122 outside the slice not scored, no off-scope tests, and 44% cheaper than experiment 18 on the same model.

The overall gain

BaselineFinal (exp. 19)
Build cost per slice5.57 USD1.81 USD (−67%)
Against the isolated reference (4.29 USD)−58%
Acceptance criteria11/1110/11 (one partly met)
Planted bugs caught10/1010/10
Weak tests01
Real integration testno (a UI test)yes, through the page, on the real container
Mutation score on the slice's codenot measured100%
Line coverage≈87%≈97%

Where the saving came from, roughly:

  • process and output changes on the same model: −26%;
  • the cheaper model: about −44% (experiment 17 against 18);
  • a correctly scoped check: a further −44% (18 against 19).

What made a real difference

  1. The spec. It was the single largest quality factor: 5/11 criteria without it, 10–11/11 with it, whatever the rest of the harness looked like. The spec is where the owner's decisions enter the build.
  2. Removing duplicate work. A separate plan file and a second analysis build repeated what the spec and the gate already did: −14%.
  3. Keeping tool output out of the context. Quiet build and test output: −14% cost, −27% context. The context grows from what the agent reads and runs, not from the instructions.
  4. A mechanical check instead of prose. Mutation testing changed how the agent tested. Seven written rules did not.
  5. Scoping that check to the slice. An unscoped gate creates its own waste.
  6. Model choice, once the gate exists. Sonnet 5.5 met the same floor as Opus 5.5 at 56% of the cost. The gate, not the model, set the quality.

What had no measurable effect

  1. Instruction text, in either direction. −86% of the build skill: no change. Seven new rules: no change.
  2. Paperwork. Dropping the recap file and spec edits: −2%, inside the noise.
  3. Regrouping work. Batching tests, parallel tool calls, many small commands: all more expensive, because each turn re-reads the context and bigger steps grow it.

What made things worse

  1. A sub-agent per command: +54% and more than twice the time.
  2. A home-made verification hook: two versions, two defects, both blocking correct work. A proven tool (Stryker.NET) did the job the first time.
  3. Stale instructions. Old texts left in the project contradicted the new ones. Two builds from the same base differed by 37%.

Anthropic's guidance holds up

I compared my findings with three Anthropic sources: the Claude Code best-practices page, "Harness design for long-running application development" (March 2026) and "Harnessing Claude's intelligence" (April 2026).

GuidanceMy measurementVerdict
Write a spec, then build from it in a fresh sessionSpec: 5/11 → 11/11. Every build ran in a fresh session from the spec.Confirmed, strongest effect of the study
Instructions are advisory; what must always happen belongs in a hook or a checkRules text: no effect (exp. 15). Mutation gate: clear effect (exp. 16, 19).Confirmed
Give the agent a check that returns pass or failThe mutation check let the agent find and close its own gaps (68% → 83%, 70% → 87%).Confirmed
"Every component in a harness encodes an assumption about what the model can't do on its own"; remove components and measurePlan file, analysis build and 86% of the build skill removed without loss.Confirmed
Keep the instruction file shortShorter is harmless, but it saved nothing measurable: the context is dominated by tool output.Partly: right for clarity, not a cost lever here
Keep noisy output out of the main contextQuiet output: −14% cost, −27% context.Confirmed
Sub-agents isolate noisy workOne sub-agent per build or test command: +54%.Not confirmed as I applied it: isolation has a start-up cost; per command is too fine
Agents grade their own work too positively; use a separate evaluatorMy independent judges found weak tests, false claims in the test list and mislabelled mutants that the builders reported as fine.Confirmed
Every enforced rule will sometimes fire wrongly and must be maintainedMy own red-check hook failed twice.Confirmed, the hard way
Sonnet costs less on routine workSame quality floor at 56% of the cost, with the gate in place.Confirmed
Stale or contradictory instructions should be audited outA 37% cost difference traced to stale texts.Confirmed

On plan mode

Several third-party articles report that Anthropic now puts less weight on plan mode and more on a written spec. I did not find this stated in the Anthropic pages I read, so I treat it as unverified.

My data is consistent with it. Removing the separate planning step saved 14% with no loss. Removing the spec lost half the acceptance criteria. For this kind of work, the spec is the plan.

Limitations

  • One task, one codebase, one slice. A different feature may behave differently.
  • Mostly single runs. The baseline spread was ±1.5% over three runs, but I also saw 37% between two runs with contaminated instructions. Differences under 10% should be read as noise. The larger effects (−14%, −44%, +54%) are outside it.
  • The final run did not fully meet the floor (one criterion partly tested, one weak test). It is the best cost and the best integration test, not a clean win on every line.
  • The judges are models. They were blind to the build session and consistent across runs, but they are not ground truth.
  • Early absolute costs are inflated by the isolation defect. Relative results for skill and setting changes hold.
  • Evaluation is not free. The two judges cost about 4.5 USD per experiment, more than the final build itself.

Keep what decides, drop what only instructs

The harness I ended with is smaller than the one I started with. It produces better-tested code for about a third of the cost.

The pattern behind every gain was the same: keep what carries decisions (the spec) and what can be checked by a machine (the gate, the mutation check); remove what only tells the model how to work.

The practical advice I draw from the measurements:

  1. Invest in the spec; it decides what gets built.
  2. Enforce with a proven tool, not with more text and not with home-made hooks.
  3. Scope every gate to the change under review.
  4. Watch tool output, not instruction length, when the cost is too high.
  5. Measure one change at a time against a fixed task, and start every session on the commit under test.
  6. Re-test the model choice after the gate is in place.

Measurements

All runs

Costs in USD for the build job only. "Ctx" is tokens read from cache, in millions. "–" means not judged.

RunHarness / changeModelCostTurnsCtxCriteriaBugs caughtWeakLine cov.Decision
base-1Kit 2.5.6Opus5.5914712.3010/11–––baseline
base-2Kit 2.5.6Opus5.6415010.81––––found one criterion untestable; spec fixed
base-3Kit 2.5.6, spec fixedOpus5.4814911.0611/11–––reference
1No plan file, no analysis buildOpus4.7812110.5311/11–––adopted (2.5.7)
2Sub-agent per build/testOpus8.57––––––rejected
3Small targeted commandsOpus6.3715215.70––––rejected
4Test economyOpus4.611188.84––––not alone
5Integration test firstOpus4.771019.5011/11–––adopted with 4 (2.5.8)
6Instructions −55%Opus4.781269.39––––void
7Quiet outputOpus4.111036.9311/1110/100≈87%adopted (2.5.9)
8Batch red, batch greenOpus4.601168.57––––rejected
9No recap, no spec editsOpus4.041017.12––––not adopted
10Parallel tool callsOpus5.621147.99––––rejected
ref-isoKit 2.5.9, isolatedOpus4.291028.0511/1110/100≈87%isolated reference
11bMinimal harness, no specOpus3.42966.825/118/100100%rejected
11cMinimal harness + specOpus3.961017.6110/1110/100≈92%not adopted as is
12Kit 2.6.0, slim build skillOpus4.331218.6011/1110/100≈89%kept (simpler, equal)
13Kit 2.6.1, red checkOpus4.67117–11/1110/101≈90%check defective
14Kit 2.6.2, red check v2Opus5.3113910.8711/1110/100100%check defective
15Kit 2.6.3, testing rules onlyOpus4.9410910.0310/1110/101≈91%not adopted
16+ mutation gateOpus5.0911710.5011/1110/100100%adopted (2.6.4)
17Kit 2.6.4Opus5.7815211.6011/1110/101100%confirmed, padding found
18Kit 2.6.4Sonnet3.22168–11/1110/100100%model adopted
19Kit 2.6.5Sonnet1.81113–10/1110/101≈97%recommended

All judged runs had a green gate, caught both bugs planted by the build judge, and scored 4/5 on code quality.

Mutation testing detail

RunScopeMutants scoredFirst scoreFinal scoreTests added for itOff-scope tests
16Selected files4571.4%80.0%20
17Whole changed files12368.3%82.9%95
18Whole changed files12570.4%87.2%≈2011
19Changed lines only38 (122 outside, not scored)7 survivors100%0 beyond the slice0

Tool: Stryker.NET 5.1.0, threshold 80%, no mutant without coverage allowed. Surviving mutants are committed with the slice and classified as killed later, equivalent (unobservable by any test) or accepted for the reviewer.

The ten planted bugs

BugCaught in exp. 19 by
M1Separator ; changed to ,1 unit, 2 integration
M2Byte-order mark removed13 unit, 2 integration
M3CRLF changed to LF13 unit, 2 integration
M4Quoting removed4 unit
M5Formula guard for = removed2 unit
M6Headers in a fixed language1 integration
M7Only the current page exported1 integration
M8Grid sort ignored1 integration
M9UTC date instead of local date in the file name1 integration
M10A person's name added to the log record1 unit

Sources