Coding agents follow existing code more than new instructions for changes
Precedent or Intent? What Coding Agents Follow When Evolving Existing Code
Software EngineeringArtificial Intelligence
Summary
When computer programs that write code add new features, they face a choice: should they copy what old code does or follow new instructions? The authors studied this by running many tests on both made-up and real-world codebases. They found that these coding agents mostly stick to how the previous code was written, especially when there are many similar examples nearby. However, clear written rules about priorities helped agents balance following old code and new instructions better. This work suggests that keeping track of why code was written a certain way can help future code changes go more smoothly.
What this means in practice
- •For software development teams: Improve code change tools by adding clear priority rules to help automated coding agents decide when to follow old code or new instructions.
- •For devops engineers: Design repositories and code organization so that local examples strongly guide automated updates and reduce conflicts in code evolution.
Authors
Haichao Zhu, Geyang Xu, Zhaorui Yang, Jiyuan Wang, Qian Zhang
Abstract
Existing code reveals past implementation decisions but rarely explains the reasoning behind them. When coding agents implement new features or modify existing functionality, past decisions may conflict with new task instructions. This raises a fundamental question for agentic software evolution: when multiple implementations satisfy the same functional requirements, how do coding agents decide whether to follow existing code or new task instructions? We investigate this question through bidirectional, controlled experiments in purpose-built repositories, followed by validation in real-world open-source repositories. Our approach isolates three competing sources of guidance: (1) agents' default preferences, (2) repository precedents, and (3) explicit task instructions. We conduct 5,625 trials across four coding agents and six implementation pairs, with validation in four open-source repositories spanning three programming languages. We find that agents share the same default implementation choices, yet overwhelmingly follow repository precedent when it conflicts with those defaults (359/360 trials). Crucially, not all precedents carry equal influence: three supporting local files yield 96% adoption, compared with only 4% for sibling-resource files, and changing file placement alone can shift adoption from 0% to 100% at a fixed example count. When new task intent conflicts with existing code, written priority rules achieve substantially higher success than code examples alone (59/60 versus 38/60 joint successes for two agents on two implementation pairs). The effectiveness of explicit rules also extends to open-source repositories, where a harness-loaded rule raises joint success from 0/120 to 117/120. These findings motivate design-decision traceability that preserves not only implementation choices but also the rationale and priorities that should guide future changes.