Clean Code Is Now Agent Infrastructure
A coding-agent study shows clean code may not change pass rate, but it can reduce token use and repeated file visits. Maintainability is now part of the AI adoption budget.
AI coding agents are changing the cost model of software work. The old debate was whether clean code made life easier for developers. The new question is sharper: does a messy codebase make your AI agent more expensive, more hesitant, and more likely to loop?
A controlled study from SonarSource researchers gives a useful answer. The researchers built minimal pairs of repositories: two versions of the same app with the same architecture, dependencies, tests, and external behaviour, but different levels of code cleanliness. Then they ran 33 tasks across those pairs, with Claude Code doing 660 trials.
Clean code changes the footprint, not the pass rate
The headline is not what most teams would expect. Clean code did not meaningfully change whether the agent completed the task. Pass rate stayed basically flat.
That matters because it pushes the conversation past the lazy version of “messy code breaks AI.” The better point is operational: clean code changed the agent’s footprint. The study reports that agents working on cleaner code used 7% to 8% fewer tokens and reduced file revisitations by 34%.
That is the part founders and engineering leads should care about. Agents can often get through a messy codebase. They just spend more time reading, re-reading, second-guessing, and dragging more context through the model. In human terms, it is the difference between walking into a well-labelled workshop and a garage where every tool exists, but nothing is where it should be.
The codebase is part of the AI system
This lines up with what teams are already feeling. GitLab’s 2026 Global DevSecOps Report frames the current phase as the intelligent software development era. AI is already part of the software delivery system. The constraint is no longer just whether a developer can generate code faster. It is whether the surrounding system can keep quality, review, security, and delivery under control.
A Thoughtworks article published on Martin Fowler’s site makes the same practical point: internal quality is what lets development continue at a sustainable pace. That was true before AI. It becomes more obvious when agents repeatedly navigate the same codebase, open files, edit, revisit, and rely on context windows that cost money.
The operator takeaway is simple: treat code quality as agent runtime infrastructure.
That means linting is not a cosmetic preference. Naming is not just taste. Smaller functions, clearer boundaries, fewer dead branches, and reduced cognitive complexity make the codebase easier for both humans and agents to traverse. They lower the search cost of a change. They give agents better handles to grab.
Avoid clean-code theatre
The wrong response is to make everything smaller at any cost. The study itself is careful: cleaner code did not win on every individual task. Some refactors spread logic across more files, which can make an agent read more surface area.
The useful goal is navigability. Can the agent find the right place quickly? Can it understand the responsibility of the component? Can it make a change without bouncing between the same files again and again?
That is more practical than enforcing a style guide and declaring victory. A tidy-looking repository can still have vague boundaries, brittle tests, hidden coupling, and misleading names. Agents will pay for those problems in extra context and loops, just as developers pay for them in time and mistakes.
What operators should measure
Before giving coding agents broader scope, pick one active repository and measure the basics:
- complexity hotspots and issue density
- test coverage and flaky-test frequency
- agent token spend and retry rate
- repeated file visits during agent runs
- review time and rework after generated changes
Add quality gates around the paths agents touch most often. Ask agents to leave short change notes explaining where they looked and why. Use static analysis and review automation as a map, not as a scoreboard.
Most importantly, budget for cleanup as part of the AI rollout. If the business case for coding agents depends on speed, the codebase they work inside becomes part of the machine. A messy repository may still pass the tests. It may still ship. But if every agent task costs more context, more retries, and more review attention, the savings quietly leak out of the system.
Clean code used to be framed as a craft value. In the agent era, it is operations hygiene. You are not just making the code nicer. You are making the work cheaper to delegate.