代码整洁度不影响编程代理成功率,但显著降低其资源消耗。
Does Code Cleanliness Affect Coding Agents? A Controlled Minimal-Pair Study

- 构建最小差异代码对,隔离整洁度与代理能力影响。
- 整洁代码使代理调用令牌减少7-8%,文件重访率下降34%。
- 适合关注AI开发效率与成本的工程团队参考。
随着自主编程代理的快速普及,现有评估多聚焦于任务完成率并固定目标代码库。这留下了一个关键问题:底层代码的结构与风格质量(即‘整洁度’)是否会影响代理的导航与修改能力?为分离整洁度与代理能力的影响,我们提出基于最小配对的评估协议:在架构、依赖和外部行为一致的前提下,仅在静态分析违规和认知复杂度上存在差异的代码库对。通过代理流水线,从干净代码生成混乱代码,或反之,构建了6组代码对,共设计33个任务,在应用公开接口进行隐蔽测试。在660次实验中,使用Claude Code时,代码整洁度未改变代理通过率。然而,整洁代码显著降低代理操作开销:令牌使用量减少7-8%,文件重访次数下降34%。结果表明,传统可维护性原则在AI驱动开发时代依然重要,直接影响编程代理的计算成本与导航效率。代码整洁度与模型选择、提示策略、工具调用共同构成影响代理行为的关键因素。
原文摘要 · Abstract (English)
As autonomous coding agents see rapid adoption, their evaluation has primarily focused on task completion rates holding the target codebase fixed. This leaves a critical question unanswered: does the structural and stylistic quality, or ``cleanliness'' of the underlying code affect an agent's ability to navigate and modify it? To isolate the effect of code cleanliness from agent capability, we introduce an evaluation protocol built around minimal pairs: repositories that match on architecture, dependencies, and external behaviour, but differ on static-analysis rule violations and cognitive complexity. The pairs are constructed in both directions, by agent pipelines that either degrade a clean repository or clean a messy one. We author 33 tasks across six such pairs, evaluated through hidden tests at the application's public surface. 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%. Our findings suggest that traditional maintainability principles remain highly relevant in the era of AI-driven development, shaping the computational cost and navigational efficiency of coding agents. Code cleanliness joins model choice, harness, and prompting as a factor that materially affects agent behaviours.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。