A number has been going around: prompting a coding agent to follow TDD costs roughly 8x more tokens than letting it write code without that constraint, for no measurable quality gain. I've seen it quoted a few times now, usually with no link back to where it came from. So I went and found the source before I let it change how I think about agent prompting.
It traces to a small, self-described experiment published on Martin Fowler's site as part of Thoughtworks' Exploring Generative AI series — TDD in the agent loop: theater or actual value?. The core finding is real. The way it's being repeated is not quite how the author frames it.
What the study actually measured
Five task batches — one small (a medical appointment slot validator), three medium (a four-stage data pipeline report), one large (a loyalty points engine). Each batch ran two non-TDD solutions and two TDD solutions through Claude Sonnet 4.6, then Claude Opus 4.8 blind-judged the outputs without knowing which method produced which — a sound way to avoid the author's own bias creeping into the ranking.
The token multipliers, task size by task size:
| Task size | Non-TDD tokens | TDD tokens | Multiplier |
|---|---|---|---|
| Small | 119,815 | 1,018,245 | 8.50x |
| Medium | 736,486 | 2,181,105 | 2.96x |
| Large | 253,621 | 1,239,408 | 4.89x |
Notice the number that's actually spreading — "TDD costs about 8x, or maybe 3x on bigger tasks" — quietly drops the large-task result. 4.89x isn't close to 3x; it's over 60% higher than the figure being quoted as the conservative case. If you're sizing the cost impact of a TDD prompt on your own large agentic tasks, the number to plan around is closer to 5x than 3x.
On quality, Opus's blind rankings put non-TDD solutions in the top two spots for the small task, and top two of four for two of the three medium rounds. Mutation-testing scores — a reasonable proxy for whether the tests actually catch regressions — showed no meaningful difference between the two groups. The one round where a TDD solution ranked first came after the prompt was rewritten mid-experiment, and it happened once.
Why, not just how much
The more useful part of the write-up isn't the multiplier — it's the mechanism. TDD's value for a human developer comes from a cognitive forcing function: you can't write a test for an interface that doesn't make sense yet, so writing the test first makes you think through the design before you commit to it. That constraint is what red-green-refactor is actually for.
An agent doesn't have that constraint to begin with. It can hold the interface, the data model, and the edge cases in context simultaneously and generate all of it in one pass. When the non-TDD and test-first runs in this study produced better solutions, the pattern Böckeler traces in the session logs is that they did the full design up front — architecture, data types, edge cases, contracts — before writing any code. TDD's incremental one-test-at-a-time discipline actively worked against that upfront step, forcing the agent to discover the design piecemeal instead of stating it once. You end up paying for the sequencing without getting the benefit the sequencing exists to produce.
What the study doesn't claim
The author is upfront about the limits, and they're worth repeating rather than smoothing over, because the version circulating online drops all of them:
- Five batches is a small sample. The author's own words: "take it with a grain of salt."
- Quality was "almost fully" Opus's judgment call, not measured against an independent ground truth.
- Every task was greenfield and small — pure business logic, no legacy code, no large existing codebase to integrate with.
- Token counts don't separate out cache hits, so the absolute multipliers may be somewhat overstated. This is the one that turned out to matter most, so I went and measured it — see below.
None of that makes the finding useless — it's a well-designed experiment with a blind judge, and the directional result is worth taking seriously. But it's a first look, not a settled fact, and it says nothing about TDD's value for the human engineers steering the agent. That's a different question, and it's not the one this experiment answers — see TDD is a Dying Art: Myth or Reality? for that side of the argument, which still holds for teams where a person, not an agent, is doing the driving.
So I rebuilt the experiment
The cache-hit caveat bothered me. "Somewhat overstated" is doing a lot of work in a sentence that ends with a number people are quoting to three significant figures. So I built the experiment again from scratch to find out how much.
Same shape: three task sizes, greenfield business logic, three arms building the same library from a byte-identical spec. The only variable is the process instruction in the agent's system prompt — strict red-green-refactor, spec-first (design and implement in one pass, then write tests), or no tests at all. Correctness is scored by a 65-test hold-out suite written before any run that never enters the agent's workspace, so no arm can optimise against it and the no-tests arm isn't punished for having none. 18 runs on Claude Sonnet 5, $18.58 of tokens. Code and every run record are public.
Sample sizes are small and I'd rather say so than round it off: two runs per cell, nine cells. Treat the figures below as a well-instrumented first look, not a settled measurement. The per-run numbers are in the repo so you can see the spread rather than take my averages on trust.
The critical difference: I priced the tokens instead of just counting them.
The metric overstates the bill, and it gets worse as tasks grow
| Task size | Raw-token multiplier | Actual cost multiplier | Overstatement |
|---|---|---|---|
| Small | 10.0x | 6.0x | 1.65x |
| Medium | 71.5x | 24.6x | 2.90x |
| Large | 101.8x | 23.6x | 4.31x |
Same sessions, same token counts. The only difference is that the second column bills a cache-read token at what it actually costs — a tenth of fresh input — instead of counting it as if it were new.
The distortion isn't constant. It compounds with task size, because bigger tasks mean longer sessions, longer sessions accumulate more context, and every additional turn re-reads that context as a cache hit. On the large task, the headline metric overstates the real bill by more than 4.3x.
Which is the uncomfortable part: the number is least trustworthy exactly where people quote it as most conservative.
The multiplier is a dial, and adherence is what turns it
My raw-token ratios run far above the published 8.50x / 2.96x / 4.89x. That isn't a contradiction — it's the most useful thing I learned.
Böckeler reports her agents frequently skipped or faked the red step; TDD, she writes, is "an uphill battle against the training data." A partially-followed TDD loop is a cheap TDD loop. My arm prompt pushes hard the other way — no batching behaviours, an observed test run in every red, green and refactor step — and the runs show it: 80 test-runner invocations on the large task, against 1 for the spec-first arm.
So the honest version of the claim isn't "TDD costs Nx." It's that the multiplier is a function of how strictly the loop is enforced, and a single number quoted without the adherence level attached doesn't mean much.
The mechanism is turn count
| Task size | TDD turns | Spec-first turns |
|---|---|---|
| Small | 33 | 7 |
| Medium | 119 | 6 |
| Large | 175 | 7 |
Spec-first is roughly constant in turns no matter how big the task gets — one design pass, one implementation pass. TDD is roughly linear in the number of behaviours, because the process defines a cycle per behaviour. Tokens then grow faster than turns — 14.7x the raw usage across a 5.3x rise in turns — because each new turn re-reads a context that's bigger than it was on the last one. That compounding is the entire cost story.
Two results I didn't expect
TDD produced less test code, not more. Averaged test-suite size: 42 vs 109 lines on the small task, 147 vs 206 on medium, 265 vs 394 on large — spec-first wrote 1.4x to 2.6x more, every time, for a fraction of the tokens. It makes sense in hindsight: a test-first loop writes the minimum test to drive the next behaviour, while an arm writing tests against a finished implementation writes against the whole spec at once.
Every arm passed every hold-out test. 100% across the board. I want to be careful here, because it's tempting to read that as "TDD adds nothing." What it actually shows is that TDD bought no additional correctness on these tasks. It is not evidence that TDD is no better in general — a grader everyone aces can't rank anyone. That's a ceiling effect, and the correct reading is no signal, not no difference. The original study went further than I did on this question — blind LLM judging plus mutation testing — and its no-difference finding is the stronger one.
Where this lands if you're already spec-first
If your team has already made the move I wrote about in From Red-Green-Refactor to Living Documentation, this experiment is closer to confirmation than surprise. Spec-driven development front-loads exactly the design step — contract, data shapes, edge cases — that this study found agents benefit from doing up front. Requiring a coding agent to also run red-green-refactor on top of an already-agreed spec is asking it to rediscover, one test at a time, a design it was already handed. That's the token tax without the design benefit, on top of an approach that was already solving the problem TDD-for-agents is trying to solve.
My replication puts a number on that. Every arm got the same complete spec — so the forcing function had nothing left to force, and what red-green-refactor added was turns, not thinking. The cleanest comparison is TDD against spec-first, because both arms end up with a test suite; the only difference is when they wrote it. On that comparison TDD cost 4.4x, 11.1x and 10.2x the money across the three task sizes, and produced less test code at every size.
The way I'd put it now: TDD and a good spec are substitutes for the same underlying good — knowing what you're building before you build it. If you already work spec-first, mandating red-green-refactor on top buys you turns. If you're handing an agent a vague one-line prompt, that design pressure has to come from somewhere, and a test-first loop is one of the few things that reliably supplies it. The tax is only wasteful when you're paying it twice.
The practical move isn't "drop TDD" — it's separate the two questions. Keep TDD where a human is driving and the forcing function is doing real work. For agent-authored code, require the design and interface up front (a spec, a plan step, an architecture note the agent commits to before touching code) and let it write code and tests together, rather than importing a human discipline into a loop that doesn't share the constraint that discipline was built around.
The governance angle
This is the same category of decision as the model-tiering and caching work in AI Token Costs in CI/CD — a prompting policy with a real, measurable cost, that most teams inherit from human practice by default rather than test against their own tasks. "Should the agent follow TDD" belongs next to "which model handles this failure type" as a setting you A/B test on your own workload and your own cost data, not a default you carry over unexamined because it worked for humans.
And it's a reminder about how claims travel. The number itself wasn't fabricated — it traces to a real, careful, honestly-hedged experiment. What changed on the way to becoming a LinkedIn factoid was the hedging: first the large-task result, then the caveat that the multiplier counts cached tokens at full price. Strip both and you get a number that's roughly 4x too large on exactly the tasks people are using it to plan.
The fix isn't cynicism about the source — it's cheap. Böckeler published her method clearly enough that rebuilding it cost me an afternoon and under twenty dollars. If a statistic is about to change how you prompt, that's usually a better use of a day than arguing about it in the comments.
Related reading
- TDD is a Dying Art: Myth or Reality? — the case for TDD's continued value when a human is driving.
- From Red-Green-Refactor to Living Documentation — why spec-first already captures the upfront-design benefit this study found.
- AI Token Costs in CI/CD — the governance framework this fits into.
- TDD in the agent loop: theater or actual value? — Birgitta Böckeler's original experiment, on Martin Fowler's site.
- tdd-token-experiment — my replication: harness, specs, hidden grader, and every run record.
npm run verifyreproduces the grader check without spending a token.