Study Shows Clean Code Reduces Coding Agent Token Use by 8% and File Revisits by 34%
A study of 660 Claude Code trials shows that writing cleaner code saves 7–8% tokens and 34% fewer file visits without affecting task success rates.
In this experiment, we ran 660 Claude Code trials over 33 tasks across 6 pairs of matched repositories (i.e., identical codebases and functionalities, except one repo is “messy”). Our minimal pair experiments suggest that code quality has no impact on other variables. With cleaner code, our agent used 7–8% fewer tokens and revisited existing files 34% less often. The task success rate was not significantly different between the clean and messy repositories.
This experiment gives you another reason to write clean code! In addition to being easier for humans to read and modify, clean code is also cheaper for AI agents to work with. By writing cleaner code, you can improve token efficiency and reduce the number of times you need to visit a file, which will save you money on computing resources. While AI may take over many programming jobs in the future, it’s always worthwhile to keep your code clean.
Source: arxiv.org
Free course
Stop reading about AI — start building with it
The free Claude Code course: your first site, tool or game — no coding. No upsells, no cross-sells — nothing to buy here.
Start free →
Author
Evgenii Arsentev
PhD · Founder & CEO, Dad4Kids
Articles · Latest articles