· 15-minute read
Harness engineering in practice: what each change to a code-search agent was worth
By
Joe Corcoran
Founder of Clarvelo
The changes took Haiku from 91.2% of answers passed to 98.5%, and from $0.020 a question to $0.0036. They made Sonnet 5.5 about 12 times cheaper per question.
Harness engineering is the work of designing everything around a model in an AI agent: the tools it can call, what goes into each request, when its loop stops, and the code that checks its output. To check our code-search agent, we keep an evaluation suite, or eval suite: a fixed set of 68 questions about real code, each with known right and wrong answers, which the agent answers and our code grades. We first shipped the agent on Claude Sonnet 4.6, where one run of the suite cost about $27. That was too much to run after every change. So we did the harness work on the smaller Claude Haiku, and we ran the larger Claude Sonnet 5.5 on the harness as it was at the start and as it was at the end, to check that the changes were not tuned to one model.
The changes took Haiku from 91.2% of answers passed to 98.5%, and from $0.020 a question to $0.0036. They made Sonnet 5.5 about 12 times cheaper per question. On the final harness, Haiku matched Sonnet 5.5 almost exactly on quality, despite needing more citation rewrites, at one-fifteenth of the cost. This post gives the before-and-after tables, explains each change, and describes how we evaluate a harness. Birgitta Böckeler's harness engineering article, published by Martin Fowler, lists that last part among its open questions. The finding that surprised us most is that the gains came from the model taking fewer turns before it answered, not from making more tool calls in each turn.
What is harness engineering?
Harness engineering is the design of everything in an AI agent except the model. The term is recent. Ryan Lopopolo's harness engineering essay for OpenAI (February 2026) describes a team of three engineers, later seven, that shipped about a million lines of code with no hand-written code. Birgitta Böckeler's harness engineering article on martinfowler.com (April 2026) gives the most careful framework so far. She sorts the controls around a coding agent into guides that steer it before it acts and sensors that check its work afterward, and she separates deterministic checks such as tests and linters from checks that use a model. The open Learn Harness Engineering course turns the idea into exercises, starting with the same task run with and without a minimal harness.
Böckeler defines the harness as everything in an agent except the model itself. That is the definition we use. One difference matters for this post: her article is about the outer harness that a coding agent's user builds (rules files, tests, review). Ours is the inner harness that an agent's builder writes: the tool definitions, the loop and the request that goes to the model on each turn. Harness engineering for AI agents covers both, and the same question applies to both: how do you know a change helped?
A few published results now measure a harness change with the model held fixed. LangChain changed only the harness of its coding agent and raised its Terminal-Bench 2.0 score from 52.8% to 66.5%. An April 2026 paper on agentic harness engineering let an agent edit a harness and took the same benchmark from 69.7% to 77.0%. LangChain gives no cost figures, and the paper counts tokens. We wanted dollars per question, because that decides how often a suite can run. Böckeler names the wider gap among her open questions: "We need a way to evaluate harness coverage and quality". This post is one more answer, with costs.
The task: answering questions about code during a live workshop
Clarvelo runs live workshops in which one AI facilitator works with a whole group of people at once. (If that setup is new to you, start with what an AI facilitator does.) When a team is agreeing on a spec, or writing its AGENTS.md together, someone always asks what the code does today: whether it already retries failed payments, where the refund window is set, or whether the README still matches the code.
The facilitator does not search the code itself. It hands the question to a separate code-search agent, a sub-agent with read-only tools for searching, listing and reading files in the team's repository. The check runs in the background, so the room keeps working. The facilitator tells the group it is looking into it, and the answer arrives a little later with citations. A citation is a file path and line range, and each one becomes a link the team can open.
This puts three demands on the harness. The answer has to be right, because a group takes cited code as evidence and argues from it. It has to be fast, because a room moves on in seconds. And it has to be cheap enough that a team can ask freely; our free plan counts code-search turns against a monthly allowance. Every page we found on harness engineering assumes one developer driving one agent. Here the agent works for a room, and a wrong file path misleads several people at once.
How to evaluate an agent harness
Böckeler asks for a way to measure harness quality, as code coverage and mutation testing do for tests. For a question-answering agent like ours, this is our method. It is cheap to run, and it is how we found every problem described below.
- Pin the repositories. The questions for each repository name an exact commit, so line numbers never move. We use three small repositories we wrote for the suite (one in Go and TypeScript, one in Python, one in Ruby) and the open-source Hono web framework at release v4.13.13 as a large real-world codebase.
- Write questions the way people ask them. A question never names the file or function that holds the answer. We use four kinds: where something is, how something works, whether the code already does something, and where the docs and the code disagree.
- Grade facts both ways. Each question lists facts the answer must state and wrong facts it must not state. The wrong facts usually come from a README or comment that disagrees with the code on purpose.
- Grade citations against known evidence. Each question lists the line ranges that prove the answer. An answer passes only if it cites at least one of them.
- Record cost as well as correctness. For each question, record turns, tool calls, wall time, the share of input served from cache, and the provider's cost. Run each configuration more than once.
- Keep a cheap subset. A smoke run of two quick questions per repository catches breakage early, and a cost ceiling caps a bad run.
Here is the shape of one question, using a real Hono example from our suite:
| Field | What it holds | Example |
|---|---|---|
| Kind | One of the four question kinds | Do the docs match the code? |
| Question | Phrased as someone in a meeting would ask it | When a client accepts both gzip and deflate but ranks deflate higher, which encoding does response compression use? |
| Must state | Facts the answer needs | Deflate, because the code follows the client's ranking |
| Must not state | Known wrong answers | That gzip always wins when the client accepts both |
| Evidence | Line ranges that prove it |
The encoding choice in src/middleware/compress/index.ts
|
| Notes | Why the question exists | The code comment says gzip is preferred when the client accepts both, but the code picks the encoding the client ranks highest. An agent that trusts the comment gives the wrong answer. |
The model, the questions and the code stay fixed, so a change in the numbers that is larger than run-to-run noise comes from the harness. Record cost and turns as carefully as the pass rate: one of our changes barely moved the pass rate, and it was the most valuable change we made.
Watch what one run costs, too. The cheaper a run, the larger the suite you can keep and the more often you can run it, and a harness gets better only as fast as you can measure it. On Claude Sonnet 4.6, the model we first shipped on, one run of the suite cost about $27 ($0.397 a question). On Claude Haiku 5.5, two full runs cost about $2.70 with the original harness and about $0.50 with the final one. So we gave three models three different jobs:
- Claude Haiku 5.5 to build the harness. We made every change on it and measured each one with two runs of the full suite.
- Claude Sonnet 5.5, the current Sonnet, to check the result. We ran it twice on the original harness and twice on the final one, and we tuned none of the changes for it. We capped the original-harness run at $60, which covered 48 of the 68 questions, from three of the four repositories.
- Claude Sonnet 4.6, the model we first shipped on, as the starting point. That is one run, with an earlier prompt that allowed bare file names in citations. Those cannot become links, so the grader fails them and its pass rate understates the model.
Where we started: the original harness on three models
This table compares all three models before any of the changes, on the 48 questions that every run covered:
| Measure | Sonnet 4.6, as first shipped | Haiku 5.5 | Sonnet 5.5 |
|---|---|---|---|
| Answers graded | 48 | 96 | 96 |
| Pass rate | 77.1% | 88.5% | 96.9% |
| Facts right | 97.9% | 96.9% | 96.9% |
| Mean turns per question | 10.5 | 11.1 | 16.6 |
| Most turns in one answer | 56 | 48 | 56 |
| Tool calls per question | 11.6 | 14.3 | 31.7 |
| Tool calls per search turn | 1.2 | 1.4 | 2.0 |
| Median / p90 time | 15 s / 101 s | 15 s / 41 s | 18 s / 103 s |
| Cost per question | $0.46 | $0.018 | $0.64 |
A turn is one request to the model and its response. A search turn is any turn except the last, in which the model writes its answer. Facts right means the answer stated the correct facts and avoided known wrong ones. Pass means facts right plus at least one correct citation.
Haiku got about as many facts right as Sonnet 4.6, at about 4% of the cost per question. Sonnet 5.5 passed the most answers, but all three got the facts right about equally often, so its lead came from citations. It also did the most work: more than twice as many tool calls per question as Haiku, at 35 times Haiku's cost.
All three models also spent a long time on some questions. Each took 48 turns or more on its worst answer, and the p90 time ran from 41 seconds to 103. Sonnet 5.5 made more tool calls per turn than either of the others and still took the most turns, so the extra turns did not come from a model that searched for one thing at a time. The next section shows where they came from.
What we changed in the harness
We made each change on Haiku and measured it on the full suite of 68 questions, twice, so each column covers 136 answers. Each column adds one change to the one before it. None of these changes touched the model; each one changed what the model sees, what its tools return, or what happens to its answer afterward. We describe the ideas here and keep the wording, budgets and limits to ourselves.
| Measure | Original harness | + turn notes | + list tools | + stable prefix | + citation repair |
|---|---|---|---|---|---|
| Pass rate | 91.2% | 94.9% | 95.6% | 94.9% | 98.5% |
| Facts right | 97.1% | 98.5% | 97.8% | 100% | 99.3% |
| Mean turns per question | 12.4 | 5.9 | 5.2 | 2.6 | 2.6 |
| Most turns in one answer | 48 | 49 | 40 | 5 | 5 |
| Tool calls per question | 16.3 | 7.9 | 6.9 | 2.4 | 2.5 |
| Input served from cache | 35% | 36% | 46% | 67% | 65% |
| Median / p90 time | 16 s / 53 s | 9 s / 36 s | 9 s / 27 s | 8 s / 11 s | 9 s / 14 s |
| Cost per question | $0.020 | $0.011 | $0.0077 | $0.0028 | $0.0036 |
Turn notes
A turn note is a short message the harness adds to each request from the second turn on. It tells the model where it stands in its search and asks it to gather everything it still needs in one go, or to answer now if it can. The note is generated fresh for each request. It is never part of the stored conversation.
We expected turn notes to make the model run more searches in parallel, and the call counts show that this did not happen. Instead, the number of turns fell by half (12.4 to 5.9), the cost fell by about half, and the pass rate held.
Tools that take lists
In our loop, Haiku made little more than one tool call per turn, however we asked, so we made each call do more. The search tool and the symbol lookup now accept a list of patterns or names and run each one as its own search inside a single call. The matches share one cap, so a call with several patterns returns about as much text as a call with one. (Joining the patterns into one regular expression was simpler, but the most common pattern would fill the cap and hide the rest.) This saved a little more: 5.9 turns to 5.2, and $0.011 to $0.0077.
Stable prefix: each request starts with the one before it
Prompt caching lets a model provider reuse the work it did for the start of an earlier request, and Anthropic's prompt caching documentation is explicit that the reused part must be identical. Our harness broke that rule twice. It added the turn note at the end of each request and then dropped it, and it shortened the previous turn's tool output on every turn to save space. After the system prompt and the repository map, nothing matched, and only 35% to 46% of input came from the cache.
The fix was to keep each request a strict extension of the last one. Earlier notes are now rebuilt in the same place on every request, and old tool output is shortened rarely and all at once, so most questions are answered before anything is shortened. The cache share rose to 67%.
The bigger effect was one we did not plan. Before the fix, the model saw each tool result in full for one turn only, then lost it to shortening, and could end up searching for the same thing again. Once results stayed visible, mean turns fell from 5.2 to 2.6, the longest answer in the suite went from 40 turns to 5, and the p90 time fell from 27 seconds to 11. Two things changed at once here: results stayed visible, and earlier turn notes stayed in the request. We think visibility did most of the work, but we did not test the two apart. No other change did as much for the slowest answers, and it was a fix for our own mistake.
Citation repair
After the stable-prefix change, two runs of the suite had seven failures out of 136, and every fact in all seven answers was right. Each failure was a citation the grader could not use: a bare file name with no directory, or a line range with no file at all. The prompt already asked for full paths, with examples, and Haiku still drifted.
So we fixed citations in code. When a bare file name matches exactly one path the agent actually read, the harness writes in the full path; an ambiguous name stays as written. For a line range with no file, we first tried attaching the file mentioned last before it. That run passed 135 of 136, but the one failure cited two functions in the wrong file, because the model had mentioned a different file in between. A wrong path misleads more than a missing link, especially in front of a group, so we removed the guess.
Now, when an answer still has citations without a file, the harness asks the same agent once to rewrite it with full paths. The request continues the same conversation, so the model knows which file it meant, and it reuses the cached prefix. The harness keeps the rewrite only if it is better. About one answer in three needed one (46 of 136), at roughly $0.0017 each, which is why the last column costs a little more than the one before it.
Anthropic's Building effective agents describes a close cousin of this problem: their coding agent made mistakes with relative file paths until the tools required absolute ones. Their summary, "we actually spent more time optimizing our tools than the overall prompt", matches our experience. Twice our prompt already asked for what we wanted (parallel calls, and full paths with examples), and twice the model still fell short. Each fix that worked changed how the harness built a request or handled an answer, and none of them reworded the system prompt.
Where we ended: the final harness on both models
With all the changes in place, on all 68 questions:
| Measure | Haiku 5.5 | Sonnet 5.5 |
|---|---|---|
| Answers graded | 136 | 136 |
| Pass rate | 98.5% | 100% |
| Facts right | 99.3% | 100% |
| Mean turns per question | 2.6 | 3.0 |
| Most turns in one answer | 5 | 7 |
| Tool calls per question | 2.5 | 4.2 |
| Input served from cache | 65% | 71% |
| Answers that needed a citation rewrite | 46 | 15 |
| Median / p90 time | 9 s / 14 s | 10 s / 16 s |
| Cost per question | $0.0036 | $0.054 |
Sonnet 5.5 passed every answer and Haiku failed two. One was a real citation failure. The facts were right, but the line ranges that held the evidence had no file path, so they would not have become links, and the citation rewrite did not catch them. In its other run on the same question, Haiku cited the right lines with full paths. A model does not give the same answer twice, and this is the kind of variation that comes with it. The other failure was our grader's: the answer said the owner gets a "notice", and the grader's pattern for that fact did not accept the word. Haiku passed that question in its other run too. Sonnet 5.5 needed fewer citation rewrites, but it was a little slower and cost 15 times as much per question, so code search stays on Haiku.
The changes carried over to the larger model. On the 48 questions from the starting table, Sonnet 5.5 went from 16.6 turns per question to 3.0, from a p90 time of 103 seconds to 15, and from $0.64 a question to $0.054, about 12 times cheaper. Its pass rate rose from 96.9% to 100%. We built every change on Haiku, so this is the best evidence we have that the changes fixed problems in the harness, not the habits of one model.
From the agent as first shipped to the final version on Haiku, the cost per question fell about 110 times on the full suite, from $0.397 to $0.0036. The move to Haiku, together with a newer prompt, accounts for about 20 times of that ($0.397 to $0.020), and the harness for about 5.5 times more. On Haiku, the harness also took the pass rate from 91.2% to 98.5% and the p90 time from 53 seconds to 14. On Sonnet 5.5, where the model stayed the same, the harness alone made each question 12 times cheaper.
The surprising finding: the gains came from fewer turns
We expected the gains to come from parallelism, with the model firing off many searches per turn and finishing in fewer rounds. The data says otherwise. In every Haiku configuration, the agent made between 1.4 and 1.7 tool calls per search turn. The list tools let each call do more work, but they did not change how many calls the model made.
Sonnet 5.5 shows the same thing from the other side. On the original harness it made about 2 tool calls per search turn, the most of any model we ran, and it still took the most turns. Making more calls in each turn did not cut the number of turns it took. On the final harness it still made about 2 calls per search turn, and finished in 3.0 turns.
The turns went away for two other reasons. Turn notes made the model commit to an answer earlier instead of making one more check. The stable prefix stopped the harness from hiding results the model had already found, so it stopped searching for them again. In both cases the model spent turns on checks it did not need: one more look before answering, or a second search for a result it had already seen. The same logic explains the long tail: slow answers come from questions where the model keeps looking. The p90 time fell from 53 seconds to 14 on Haiku, and from 103 seconds to 15 on Sonnet 5.5.
What this comparison does not show
Sonnet 4.6 is one run of the agent as first shipped, with an earlier prompt that penalized its citations, so it marks where we started and is not a fair measure of that model. We built the harness on Haiku and did not tune it for Sonnet 5.5. At 136 of 136 there was little left for a Sonnet-specific harness to gain in quality, though it might cost less. The comparison at the start covers 48 of the 68 questions. Every other configuration is two runs, and on the full suite one answer is worth about 0.7 points of pass rate, and between the two runs of one configuration up to 8 of the 68 questions changed result. So the moves between 94.9%, 95.6% and 94.9% are noise, and Haiku's 98.5% against Sonnet 5.5's 100% is a difference of two answers. And 68 questions over four repositories make a focused test of one kind of agent. They say little about agents in general.
What the tables do show clearly is cost, turns and time. Those moved by multiples on both models, far beyond run-to-run noise. On Haiku, the harness changes gave about 5 times fewer turns, a p90 about 4 times faster and a cost 5.5 times lower. On Sonnet 5.5, they gave 5.5 times fewer turns, a p90 7 times faster and a cost 12 times lower.
Conclusion
Under our eval conditions, Claude Haiku 5.5 matched Claude Sonnet 5.5 almost exactly on quality, despite needing more citation rewrites, at a fraction of the cost. On the final harness, one of its two failures in 136 answers was a real citation failure on a question it passed in its other run, which is normal variation for a system that does not answer the same way twice. The other was a right fact using a word the grader did not accept. Sonnet 5.5 did show one real difference: it needed a citation rewrite on only 15 answers, against 46 for Haiku. Our theory is that its extra tool calls help. It made about 1.7 times as many per question (4.2 against 2.5), and an agent that has opened more files has more exact paths and line numbers to cite. We have not tested this. Our questions are the kind a workshop asks, on four repositories, and the final harness lets either model answer nearly all of them. A harder and more extensive suite, with larger codebases and questions that need longer searches, would give Sonnet a chance to show what it is worth as a code searcher.
Why this matters for agentic code search in a group
The agentic code search tools we know of serve one developer in an editor, who can wait or retry. In a workshop, the answer goes to a facilitator who has to fit it into a live conversation among several people. Multiplayer AI, one AI working with a group in real time, changes what good enough means. A 14-second p90 means the answer usually lands while the group is still on the topic, and a citation that links lets anyone in the room check the claim. At about a third of a cent per question, a team has no reason to ration its questions.
We applied the same habit when we chose the models for our LLM council for synthesis: we timed and priced each candidate over repeated runs, then picked the fastest mix that kept three different providers. And when a team uses code search to agree on what it wants an agent to build, that is intent engineering as a team sport, with the real code in the room.
Frequently asked questions
What is harness engineering in simple terms?
Harness engineering is designing everything around the model in an AI agent: its tools, its instructions, how each request is built, when its loop stops, and how its output is checked. The model is the engine, and the harness decides what it sees and what happens to its answers. Good harness work can let a smaller, cheaper model do the job of a larger one.
Is Claude Haiku good enough for agentic code search?
In our eval suite it matched Claude Sonnet 5.5 almost exactly on quality, once the harness was right. With our final harness, Claude Haiku 5.5 passed 98.5% of 136 graded answers at $0.0036 per question, and one of its two failures was a citation slip that it did not repeat in its other run. Claude Sonnet 5.5 passed all 136 through the same harness, at about 15 times the cost per question. A harder suite might separate the two models. Your results depend on your tools and your questions, so measure on your own code before you switch.
Do harness improvements carry over to a larger model?
In our eval suite they did. We built the changes on Claude Haiku 5.5 and ran Claude Sonnet 5.5 on the harness before and after them. On the same questions, the changes took Sonnet 5.5 from 16.6 turns per question to 3.0 and made it about 12 times cheaper per question, and its pass rate went up. One eval suite for one kind of agent does not prove this for every harness, but changes that stop a model from wasting turns are likely to help any model.
How do you evaluate an agent harness?
Hold the model, the questions and the code fixed, change one part of the harness, and compare. For a code-search agent, that means repositories pinned to an exact commit, questions with known right and wrong facts, citations graded against known line ranges, and cost, turns and time recorded per question. Run each configuration more than once. If runs on your production model are expensive, build on a cheaper model and check the start and the end on the larger one.
Does prompt caching work with agent loops?
Yes, but only if each request begins with the full previous request, unchanged. Anything that edits earlier parts of the conversation, such as trimming old tool output or moving a note, breaks the match. Making our requests strict extensions of each other raised the cached share of input from under half to about two thirds.