Your AI bill is a code quality problem
A controlled study by Sonar found that structural code quality directly impacts AI coding agent token consumption: agents working on cleaner code used 7–8% fewer tokens and revisited files 34% less often than on deliberately degraded variants of the same application. The effect is strongest in multi-module tasks (10.7% fewer tokens when crossing clean vs. messy module boundaries), driven by the agent’s inability to efficiently locate code paths in complex methods—agents read exhaustively to orient themselves before editing. The research isolates code structure as an independent variable and suggests cognitive-complexity metrics (rule S3776) may serve as proxies for AI agent cost.
This post is licensed under CC BY 4.0 by the author.