Fowler refactored a single Rust data access file, written end to end by AI agents and never read by a human, and measured the token cost of every future change. The savings compound with each stage.
A single Rust file holds the entire data access layer of a 150,000-line application. It is 17,155 lines long, contains no internal language, no deduplication, and almost no extracted functions. No human has read it. The file was written end-to-end by AI coding agents, mostly Claude Code with some Cursor, according to Fowler's account of the project. It had grown unwieldy enough that Martin Fowler picked it as the target of a controlled experiment in the cost of cleaning up.
Fowler's article "The Economic Benefit of Refactoring", published 30 July 2026 as part of the Thoughtworks "Exploring Gen AI" series, is a budget argument: in a codebase where agents write the code, every future feature an agent ships into a sprawling file costs tokens, and those tokens compound. Refactoring pays a known cost now to lower an unknown but growing cost later. The experiment puts a number on that slope.
The setup neutralizes learning. Fowler wrote a single representative change prompt, then established a baseline token cost for running that prompt in a fresh, learning-naive sub-agent. He then ran a new agent on the same prompt after every refactoring stage, so the agent carries no knowledge from the prior steps. Any measured drop in token spend can be attributed to the refactor, not to a human or model learning the codebase.
The file was self-contained with a clear interface, even as its contents had multiplied: a data access layer past 6,000 lines that ultimately reached 17,155 lines in a single Rust file. By Fowler's account, there was no deduplication, no internal language, limited function extraction, and very little class extraction. Without engineering prompts, agents produced code that works but does not compact. The shape of the code, long and repetitive, is also the shape of the cost it imposes on the next prompt.
Practitioners in the Hacker News discussion push the corollary further: cyclomatic and cognitive complexity scale with token usage, and a codebase which caps complexity caps agent cost with it. A test suite that already covers behavior is the other half of the argument. Fowler's book on refactoring opens with a solid test base as a precondition, and several commenters treat that as the load-bearing part of the experiment, not any AI-specific magic. The refactor only pays back because tests guarantee the behavior does not drift while the code is reshaped.
Fowler's book "Refactoring" gives the primary-source claim more weight than a typical self-experiment, and the same authority narrows what the result can show. This is one author, one application, one stack, and one style of agentic flow. The shape of the result, the steep cost reduction after each refactor stage, is more transferable than the specific number, which Fowler has not yet published in a form independent reviewers can replicate.
The practical question for engineering teams is whether the same slope shows up in codebases they did not write, in stacks they did not choose, and in agentic flows they did not configure. Fowler's own answer is that the next run will be larger, on a different stack, with a longer change prompt and a published token-count table that outside reviewers can check. Until then, the experiment fully supports only the bounded claim Fowler makes in the article: in an agentic codebase, refactoring is a paid-down tax on every future prompt, and the slope of that tax is now measurable rather than asserted.