Does messy code make AI coding agents more expensive? Yes, and now you can see by how much. Coding agents pay by the token to read your code, so every structural shortcut in a codebase lands on the bill each time an agent touches it. Here's what we check when a client's AI coding bill is bigger than the work should cost.
One term first. An agent's read set is the files it has to load before it can make a change safely. Most of what follows is about keeping that read set small.
1. Oversized files force the agent to read everything. If one file holds a whole layer, the agent loads the whole layer to change one query. On July 30, 2026, Thoughtworks' Giles Edwards-Alexander published a controlled experiment on exactly this. He refactored a 17,155-line Rust file into smaller modules, and the same follow-up change dropped from 159,564 input tokens to 27,360. That's an 83 percent cut, and it repeats on every future change to that code. We walk through running the same measurement on your own code in our post on refactoring ROI measured in tokens.
2. Duplication is a rereading tax. When the same logic lives in six places, the agent has to load all six to change it safely. Edwards-Alexander's refactoring steps went after this kind of repetition, including one expression copied verbatim into 20 functions. We look for duplicated logic before we scope agent work. The fix and the payoff haven't changed. Now they're billed.
3. Tangled structure makes the agent search before it works. The experiment's savings didn't come from smaller files alone. They came from a structure that let the agent find the smallest set of files it needed. When a change could live anywhere, the agent goes exploring, and you pay for every file it opens along the way. Clear module boundaries are the cheapest thing you can hand an agent.
4. Missing tests turn one change into a retry loop. Output tokens cost more than input tokens. On Anthropic's published price list, the output rate is five times the input rate for every current Claude model. Without tests, the agent can't confirm its own change, so it explains, patches, and tries again. In our delivery work, that retry loop is where a codebase with no tests spends its money, and it spends it at the expensive rate.
5. No per-change cost tracking means you find out after the money's gone. Sloppy code usually comes with a sloppy meter. On July 31, 2026, TechSpot reported, citing the Financial Times, that an Amazon project using Claude Sonnet to match author information to product listings failed after spending about $1.8 million, 860 percent over its original budget. Nobody noticed the overrun for five months. "It's difficult to figure out how much anything [AI related] costs," one senior Amazon employee told the FT. Record what each change costs in tokens from the first week, not after the invoice lands.
None of this argues against coding agents. It argues for treating code quality as a cost input, not only a quality one. The pipeline decisions that set the rest of the bill (model routing, context, caching) are in why your AI bill is an architecture problem, and our AI implementation reviews run this math before a client signs off on scope.

