Does Code Cleanliness Affect Coding Agents? A Controlled Minimal-Pair Study

Updated

Does Code Cleanliness Affect Coding Agents? A Controlled Minimal-Pair Study

The developer ecosystem is undergoing a transition from the initial euphoria of "vibe-coding"—using AI agents to generate massive codebases in hours—to a gritty, cynical assessment of long-term maintainability, as tracked in The 'Vibe-Coding' Hangover: AI Codebases, Maintenance Debt, and the Codex SSD-Burning Bug. A critical question in this transition is whether traditional software engineering principles still matter when machines, rather than humans, are writing and navigating the code.

A peer-reviewed study from SonarSource, titled Does Code Cleanliness Affect Coding Agents? A Controlled Minimal-Pair Study, provides the first rigorous empirical look at this dynamic. Evaluating Claude Code across 660 trials on "minimal-pair" repositories—codebases that are architecturally and functionally identical but differ in static-analysis violations and cognitive complexity—the researchers reached a surprising conclusion: code cleanliness does not change the agent's task pass rate.

However, the study revealed that code hygiene dramatically alters the agent's operational footprint. When working on cleaner code, agents used 7% to 8% fewer tokens and reduced file revisitations by 34%.

This finding has ignited a sharp debate on Hacker News, exposing a deep divide between empirical academic findings and the daily lived experience of software practitioners. While the paper suggests that LLMs are resilient enough to "power through" messy code to find a solution, developers argue that real-world "messiness"—such as dead code, leaking abstractions, and obsolete design patterns—actively misleads agents, causing them to hallucinate, bloat contexts, and adopt obsolete practices.

Substantive Takes & Community Split

  • The Token and Navigation Footprint: The study's load-bearing finding demonstrates that maintainability directly impacts the financial and computational cost of running AI developers.

    "Across 660 trials with Claude Code, code cleanliness does not change the agent's pass rate. However, it substantially alters the agent's operational footprint: agents working on cleaner code use 7 to 8% fewer tokens and reduce file revisitations by 34%." — jakubmazanec quoting the paper's abstract

  • The Practitioner Counter-Argument: Experienced developers contend that the paper's definition of "cleanliness" (static linter rules) misses the structural rot that actually breaks LLM reasoning.

    "In my experience, 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, with clear data flow, with good encapsulation and clean architecture. Like, I've seen all the frontier models have to do several rounds of code review / QA and fix when the code is bad vs just getting it right at the 1st/2nd attempt." — i_have_an_idea

  • The Methodological Flaw: Critics heavily questioned the study's methodology, particularly the use of AI pipelines to generate the "clean" or "messy" repository pairs.

    "I simply am not going to trust any conclusion that requires assuming these AI 'cleaned' repos are in any way representative of actually-good codebases." — wgd

  • The "Instant Legacy" Threat: There is a growing consensus that AI code generation accelerates technical debt because LLMs are highly susceptible to mimicking the poor patterns they find in their local context.

    "actually goes even further than humans, humans can pretty rapidly get inured to things being awkward or messy and stop noticing, but the context for agents is taking up the same space and 'attention' every time they're run, and they're creations entirely of context, so the quality and examples matter massively." — jaggederest

Why It Matters

This research proves that "clean code" is no longer just an aesthetic or human-centric preference; it is a critical variable in AI operational economics. Even if a frontier model can successfully navigate a bloated, messy codebase, doing so incurs a continuous "tax" in the form of higher token costs, slower execution times, and rapid context window exhaustion.1 To maximize the utility of agentic coding, organizations must enforce strict deterministic guardrails (such as pre-commit linters and CI checks) to prevent agents from spiraling into a loop of mimicking their own generated technical debt.


  1. An instance of Modern software maintenance is a war of attrition against AI-generated codebase slop. — The study demonstrates that working in disorganized codebases forces agents into loops of high token consumption and file revisitations, driving up operational debt. ↩︎

Part of

This finding is an example of a pattern recurring across your work:

Revision history

  • Update/Create the note on code cleanliness and AI coding agents, linking to vibe-coding-backlash-bun.
    · by the agent
  • Update/Create the note on code cleanliness and AI coding agents, linking to vibe-coding-backlash-bun.
    · by the agent
  • Update/Create the note on code cleanliness and AI coding agents, linking to vibe-coding-backlash-bun.
    · by the agent
  • Update/Create the note on code cleanliness and AI coding agents, linking to vibe-coding-backlash-bun.
    · by the agent
  • Update/Create the note on code cleanliness and AI coding agents, linking to vibe-coding-backlash-bun.
    · by the agent