Code cleanliness cuts AI agent token use by 8%, study finds

Original: Does code cleanliness affect coding agents? A controlled minimal-pair study

Why This Matters

Findings reframe code quality as a cost and efficiency factor in the AI-agent development era.

A SonarSource study of 660 Claude Code trials found that cleaner codebases do not improve task pass rates for AI coding agents, but reduce token usage by 7–8% and file revisitations by 34%, using a minimal-pair evaluation protocol across 33 tasks.

Researchers Priyansh Trivedi and Olivier Schmitt of SonarSource published a controlled study (arXiv:2605.20049) examining whether code cleanliness — defined by static-analysis rule violations and cognitive complexity — affects the performance of autonomous coding agents. Rather than varying agent capability, the team introduced a minimal-pair evaluation protocol: repository pairs matched on architecture, dependencies, and external behavior, but differing in structural and stylistic quality. Pairs were constructed in both directions — degrading clean repos or cleaning messy ones — using automated agent pipelines. Across 33 tasks and 660 trials using Claude Code, code cleanliness showed no statistically meaningful effect on task pass rates. However, agents working on cleaner codebases consumed 7–8% fewer tokens and revisited files 34% less frequently, indicating improved navigational efficiency. The authors conclude that traditional software maintainability principles remain highly relevant in AI-driven development, affecting computational cost even when task success is unchanged. They position code cleanliness alongside model choice, harness design, and prompting as material factors influencing coding agent behavior.

Source

arxiv.org — Read original →