Does code cleanliness affect coding agents? A controlled minimal-pair study
TL;DR Highlight
On cleaner code, Claude Code's pass rate was unchanged but it used 7-8% fewer tokens.
Who Should Read
A developer using coding agents like Claude Code on messy legacy code who worries about token cost and task time.
Core Mechanics
- Same app, different cleanliness
- Repo pairs match on architecture, dependencies and external behavior but differ in static-analysis violations and cognitive complexity.
- Pairs were built in both directions by agent pipelines that either degrade a clean repo or clean a messy one.
- The study is small
- It used six repo pairs and 33 tasks.
- There were 660 trials with Claude Code, graded by hidden tests at the application's public surface.
- Pass rate did not change
- Clean or messy, Claude Code's pass rate stayed the same.
- Cost did drop
- Agents on cleaner code used 7-8% fewer tokens.
- File revisitations fell by 34%.
- Authors say maintainability still matters
- They argue code cleanliness joins model choice, harness and prompting as a factor in agent behavior.
Community Reactions
- Critique of the experimental design
- Commenters pointed out that Opus 4.6 synthesized the degraded and cleaned repos and that unrelated existing tests weren't checked.
- Without controlling final output quality, they said the token comparison means little.
- Doubt that AI-cleaned code is representative
- One commenter said AI-cleaned repos can't be trusted to represent genuinely good codebases.
- An NJIT researcher praised the minimal-pair design but called not running the full test suite the biggest weakness.
- Experience: refactoring made agents faster
- One commenter said capping files at 400 lines and cleaning up cut quota use and task time sharply.
- Another said agents must read many chunks of 5k-line files, which is inefficient.
- Opinion: traversal is the main cost
- A commenter said much of the token use is searching and following call sites, with round-trip latency at every step.
- They suggested LSP access and hierarchical AGENTS.md guidance to reduce it.
- Experience: dead code fights the agent
- One team kept partial support for old hardware, and keeping LLMs away from that code cost more than removing it.
- Another comment noted the research came from SonarSource, which sells static analysis.
How to Apply
- Split your top 5 largest files with an agent
- Today, list files over 1,000 lines in your repo.
- Have the agent split them by feature with descriptive names and confirm existing tests still pass.
- Record tokens and time before and after cleanup
- Run the same task once before and once after cleanup and compare token usage and file revisits.
- Check with real numbers whether it helps in your repo.
- Remove dead code and legacy branches first
- Find unused hardware or feature-support code and open a PR deleting it.
- Add a linter pass to CI so agents don't copy those patterns.
- Gate agent refactors on the full test suite
- After an agent cleanup, run the whole suite, including unrelated tests.
- The paper did not check this, so cover it yourself.
Try It
# Paste into Claude Code as-is (simplified version of the paper's method: before/after comparison)
Follow these steps.
1. Find files over 500 lines under /src and show me the list with line counts.
2. Split {{target file}} by feature and rename files so the names describe their contents. Do not change external behavior.
3. Find unused functions, branches and dead code and show them as deletion candidates. Delete only after I approve.
4. Run the full tests ({{test command}}) and confirm results match before and after.
5. After cleanup, perform the task '{{task description}}' and report how many files you read and how many you reopened.Terminology
Related Papers
Frostbite: A new CPU architecture discovered, designed and verified by AI
AI agents designed a CPU from scratch, claiming 4.59x perf/W over a traditional core
Restricting AI agents in mobile operating systems platforms from capturing data
Signal now blocks OS-level AI agents from reading its screen on iOS 27 and Android
Actions Speak Louder than Words: Stateful Privacy Sniffing of LLM Agents via Behavioral Covert Channels in Web Interactions
Agents' link choices alone let attackers rebuild user queries at F1 0.89; SOR cuts it to 0.39.
Tracking and Limiting Unsupported Claim Propagation in Multi-Agent LLM Systems: A Provenance-Aware Framework
Passing claims with source, evidence and history kept equivalence at 5 agent stages at 96% versus 31%.
LLM assisted reverse engineering
Pointing an agent at binaries with skills and MD notes made years-long hacks feasible
Metrics-in-the-Loop: Complexity Feedback Reshapes Agent-Written Code
Injecting per-turn complexity reports into coding agents cut code erosion without changing correctness
Why is Gemini 4 Carbon taking so long?
Carbon took nearly an hour on bug fixes that Astra and Opus finished in minutes, mostly from extra unrequested work.
Weight-Space Programming builds neural networks like a 1990s researcher
LLM hand-wrote MNIST weights to 91.3%, using 1990s-style techniques