Refactoring now has an agent-era cost metric: fewer input tokens
Original: The Economic Benefit of Refactoring View original →
Martin Fowler’s latest agentic engineering note reframes refactoring as an operating cost question. The test case was a roughly 150,000-line application written almost entirely by coding agents. One Rust data access layer had grown into a single 17,155-line file, with repeated request setup, JSON encoding, decoding, and little internal structure.
The experiment asked the same representative change of a fresh sub-agent at each stage. First Fowler measured the baseline. Then he applied a sequence of correctness-preserving refactorings, threw away each test change, and ran the exact same prompt again. Because each sub-agent started fresh, the experiment reduced the usual human learning effect and made code structure the variable to watch.
The headline number is strong: input tokens for the same change fell from 159,564 to 27,360, an 83% reduction. Total lines in the data access layer stayed fairly flat, but the largest file shrank from 17,155 lines to 3,695 lines. That suggests the savings came from making the relevant code easier for the agent to locate, not simply from deleting code.
HN discussion added practical context. Readers noted that LLMs often benefit from well-factored code but are poor at producing it unaided. Others pointed back to Fowler’s older refactoring rule: reliable tests are the precondition. In an agent workflow, tests become more than regression protection; they are also a compact specification that both humans and models can read while changing code.
The article is careful about the limits. Fowler says Claude did not independently discover the right refactorings and needed explicit human guidance. Some mechanical steps were done with scripts, and the experiment did not fully account for the token cost of planning and applying the refactorings. Even with those caveats, the result gives teams a concrete way to discuss code structure in agent-heavy development: a better architecture may reduce the recurring input cost and latency of every future change. Sources: Martin Fowler and HN discussion.
Related Articles
OpenAI moved ChatGPT Voice into the macOS and Windows desktop app, where it can control the computer and coordinate multiple agents. The tweet drew more than 2.6 million views, making voice a front door for Codex and ChatGPT Work rather than a chat-only feature.
Agent performance is moving beyond model choice alone. NVIDIA says NOOA reached 82.2% on SWE-bench Verified and 86.8% on CyberGym L1 with an open object-oriented harness.
The final MCP 2026-07-28 specification replaces protocol-level sessions with a stateless core, MRTR, header routing, and updated Tier 1 SDKs. With TypeScript and Python SDKs each past 1 billion downloads, this is an infrastructure-level change for agent tool servers.