
TL;DR
A new SonarSource study finds clean code doesn't boost agent pass rates - but it cuts token usage by 8% and file revisitations by 34%. Here's what that means for your codebase.
Clean code has always been one of those things developers know they should do but often deprioritize. The argument was always about maintainability, readability, and keeping your future self from rage-quitting at 2am. But now that AI coding agents are writing more and more of our code, a new question emerges: does code cleanliness actually matter to the bots?
A new study from SonarSource (the folks behind SonarQube) set out to answer that question with actual data. The results are not what you might expect.
The researchers built an evaluation protocol around "minimal pairs" - repositories that share the same architecture, dependencies, and external behavior, but differ dramatically in code quality. They constructed these pairs in two directions:
The result was six pairs of repos with 33 tasks total, tested across 660 trials using Claude Code as the agent.
Here's the headline finding: code cleanliness did not change the agent's pass rate. Whether the code was pristine or a tangled mess, the agent was equally likely to complete the task correctly.
But pass rate was only half the story.
While the pass rate stayed flat, the operational costs changed significantly. When working on cleaner code, agents:
The second metric is the more interesting one. A 34% reduction in file revisitations means the agent spent less time wandering around the codebase trying to find its bearings. It read a file once, understood it, and moved on. In messy code, the agent had to keep re-reading the same files because it couldn't hold a coherent picture of the codebase in its context window.
Newsletter
Get the weekly deep dive
Tutorials on Claude Code, AI agents, and dev tools, delivered free every week.
From the archive
Jul 6, 2026 • 5 min read
Jul 6, 2026 • 5 min read
Jul 6, 2026 • 6 min read
Jul 6, 2026 • 8 min read
The Hacker News discussion on the study surfaced some important caveats. The biggest one: the study didn't check whether the agent broke unrelated tests already in the repository. As first author Priyansh Trivedi acknowledged in the comments, that was "a stupid oversight." The pass rate only measured whether the agent passed hidden tests for the specific task, not whether it introduced regressions elsewhere.
Several developers chimed in with real-world experience. One comment (i_have_an_idea) described it bluntly: "the delta in agent performance is substantial if the codebase is littered with dead code, redundant code, unreachable fallbacks, leaking abstractions and half-baked design patterns vs if the code is well-organized."
Another pattern that emerged: agents mimic their environment. If the codebase has bad patterns, the agent will reproduce them. Multiple commenters noted that agents learn from whatever code they pull into context first - so if the first file an agent reads is legacy spaghetti, expect the output to be legacy spaghetti too.
Some commenters pointed out that deterministic linters solve many cleanliness issues (dead code, code duplication, unreachable code) and have done so for years. Running a linter in CI (or as a pre-commit hook that the agent itself can trigger) is a proven pattern.
One developer shared a trick: tag legacy code explicitly so the agent knows not to use it as a reference pattern:
// LEGACY CODE, per docs/legacy_rules.md section14, section19
If cleaner code saves 7-8% on token usage, investing an hour in cleanup can pay back in agent API costs over time. For teams that run agents heavily (CI pipeline agents, PR review agents, code-gen pipelines), that math shifts into real money territory.
The study's findings suggest that the biggest gains come from navigability not prettiness. Well-named files in predictable locations, clear separation of concerns, and modular architecture matter more than formatting conventions. The agent's bottleneck is finding the right code, not reading it.
The SonarSource team used static analyzer rule violations as their cleanliness metric. This sidesteps debates about what "clean" means and focuses on measurable, enforceable properties - dead code, complexity thresholds, naming conventions. If you want agent-friendly code, start with the things a static analyzer can catch.
One practical approach from the discussion: ask the agent to run a code review against SOLID standards, then apply the suggestions you agree with. This keeps you in control while leveraging the agent's ability to identify issues at scale.
The study's core contribution is this: traditional maintainability principles remain relevant in the era of AI-driven development. They just change what they optimize for. Instead of optimizing solely for human comprehension, clean code now also optimizes for agent efficiency - fewer tokens, fewer round trips, lower latency.
Code quality always had a cost argument for it - messes take longer to fix. Now that cost argument extends into your API bill.
Read next
The coding-agent workflow is maturing past giant hand-written prompts. The winning pattern in 2026 is a control stack: project rules, reusable skills, bounded sub-agents, and deterministic tools around the model.
9 min readAddy Osmani's agent-skills repo is trending because it turns vague AI coding advice into reusable engineering checklists. The real value is not the markdown. It is the exit criteria.
7 min readThe Bayer and Thoughtworks PRINCE case study is a useful reminder that reliable agentic AI comes from context routing, traces, evals, monitoring, and human review, not from a better prompt alone.
7 min readTechnical content at the intersection of AI and development. Building with AI agents, Claude Code, and modern dev tools - then showing you exactly how it works.
Anthropic's agentic coding CLI. Runs in your terminal, edits files autonomously, spawns sub-agents, and maintains memory...
View ToolMac app for running parallel Claude Code, Codex, and Cursor agents in isolated workspaces. Watch every agent work at onc...
View ToolAI-native code editor forked from VS Code. Composer mode rewrites multiple files at once. Tab autocomplete predicts your...
View ToolOpenAI's coding agent for terminal, cloud, IDE, GitHub, Slack, and Linear workflows. Reads repos, edits files, runs comm...
View ToolEvery coding agent in one window. Stop alt-tabbing between Claude, Codex, and Cursor.
View AppTurn a one-liner into a working Claude Code skill. From idea to installed in a minute.
View AppUnlock pro skills and share private collections with your team.
View AppClickable PR link in the footer with review state color coding.
Claude Code2.5x faster Opus at a higher token cost (research preview).
Claude CodeResearcher, auditor, reviewer, and other ready-made subagent types.
Claude Code
Claude Code Review: Next-Level AI-Assisted Coding In this video, I share my insights after using Claude Code for 30 days. Discover why I believe Claude Code is one of the best AI coding agents...

Open Design: Open-Source n8n App That Turns Any Website into a Brand Kit, Design System, HTML + Images The video introduces Open Design, an MIT-licensed full-stack template that combines AI and n8n a

Nimbalyst Demo: A Visual Workspace for Codex + Claude Code with Kanban, Plans, and AI Commits Try it: https://nimbalyst.com/ Star Repo Here: https://github.com/Nimbalyst/nimbalyst This video demos N

The coding-agent workflow is maturing past giant hand-written prompts. The winning pattern in 2026 is a control stack: p...

Addy Osmani's agent-skills repo is trending because it turns vague AI coding advice into reusable engineering checklists...

The Bayer and Thoughtworks PRINCE case study is a useful reminder that reliable agentic AI comes from context routing, t...

A controlled study of 660 Claude Code trials shows clean codebases reduce token usage by 7-8% and file revisitations by...

A new study from nrehiew quantifies a problem every Claude Code, Cursor, and Codex user has felt: models making huge dif...

The Program-as-Weights paper is a useful signal for developers: some LLM calls may move from per-request API prompts int...

New tutorials, open-source projects, and deep dives on coding agents - delivered weekly.