Clean Code Cuts AI Agent Token Use 8% and File Revisitations 34% — Pass Rate Unchanged
Clean code does not make AI agents more likely to succeed. It makes them cheaper to run.
That is the headline finding from a controlled study published on arXiv, which ran 660 trials using Claude Code across six matched repository pairs — identical in architecture, dependencies, and external behavior, but differing systematically in static-analysis violations and cognitive complexity.
Pass rates were unchanged across clean and messy codebases. Whether the code had proper naming, comments, and low cyclomatic complexity did not move the needle on task completion. The agent either solved the problem or it did not, and cleanliness was not the deciding factor.
What changed was the cost. Working on cleaner code, Claude Code used 7 to 8% fewer tokens per task and revisited files 34% less often. At scale, those numbers are not cosmetic.
How the Study Was Structured
Researchers built 33 tasks across six minimal-pair repository sets. Each pair contained a clean version and a messy version of the same codebase. Pairs were constructed in both directions: agent pipelines that degraded a clean repository, and pipelines that cleaned a messy one. Tasks were evaluated through hidden tests at the application’s public surface — not self-reported by the agent.
This minimal-pair methodology is what distinguishes the finding from standard benchmark studies, which evaluate agents on fixed codebases and cannot isolate the effect of code quality from task difficulty. By holding everything constant except cleanliness, the authors get a clean causal estimate.
What 34% Fewer Revisitations Actually Means
File revisitations are a proxy for agent confusion — how often the agent returns to a file it already read. A 34% reduction on clean code means agents are building a more accurate internal map of the codebase on first pass and navigating with less backtracking.
For token budgets, the compounding effect matters. An agent that revisits a 500-line file three fewer times per task saves roughly the tokens needed to run one additional task from scratch. At the enterprise scale where multi-agent systems run thousands of parallel sessions daily, the 7–8% overhead on messy codebases becomes a direct line item in the infrastructure bill.
The Compute Cost of Technical Debt
The study reframes what technical debt costs in the agent era. The traditional case for maintainability was human productivity: clean code is easier for engineers to read and modify. That argument already felt weaker as AI systems absorbed more of the navigational burden.
The new case is compute efficiency. Messy code may not stop your agent, but it will cost you more per successful task. The paper puts the efficiency penalty at 7–8% in token terms, with file navigation degrading by a third.
For companies running Claude Code or comparable agents across large legacy codebases, the arithmetic is straightforward. A codebase that incurs an 8% token overhead on every agent task costs significantly more to operate over a quarter than one maintained to clean code standards. The traditional argument for paying down technical debt now has a per-API-call translation rate.
Key Numbers
| Metric | Clean Code | Messy Code |
|---|---|---|
| Pass rate | — | No change |
| Token usage | −7 to −8% | Baseline |
| File revisitations | −34% | Baseline |
| Tasks evaluated | 33 | 33 |
| Total trials | 660 | 660 |
The study used Claude Code throughout. Whether the efficiency gap holds at comparable magnitude across other coding agents — Cursor Composer, GitHub Copilot, Codex — is not tested. But the mechanism (agent navigation and context management) is agent-agnostic, and the result is likely directionally consistent across architectures.