Manuscript Offprint

arXiv:2609.35357

Do Coding Agents Reuse Existing Code or Reinvent the Wheel?

Dongsheng Ma, Sizhe Wang, Xinyi Huang, Zhengren Wang, Yuhan Wang, Luyang Si, Xincheng Wei, Wentao Zhang

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Coding agents are increasingly deployed for iterative development on real repositories, yet existing evaluation barely answers a basic question: do coding agents reuse existing code or reinvent the wheel? The question matters: every duplicated implementation is a fix applied twice and agents produce code far faster than humans can audit, so redundancy accumulates unsupervised. Thus, we present RepoReuse, a multi-turn benchmark for auditing code reuse in real repositories, where requirements are revealed turn by turn and the workspace accumulates across turns. It is built by a fully automated pipeline combining AST-based dependency graphs, guided evidence collection, and execution-verified task synthesis, and scales readily to new repositories. Beyond pass rates, we measure the reuse rate together with recall and cross-turn structural redundancy. An audit over 3,000 turns shows that agents progressively stop exploring relevant repository code, reuse their own history less even when it is fully in the workspace, and leave duplicated logic in 50.8% of task chains by turn 5—all while pass rates barely move. Such deficiencies are invisible to pass rates, underscoring the need to evaluate code generation beyond functional correctness.

1 Introduction

Coding agents continue to break records on coding benchmarks (Team et al., 2026; DeepSeek-AI et al., 2026; Yang et al., 2024; Wang et al., 2025a; Jimenez et al., 2024), and are increasingly deployed in real repositories to assist humans with iterative development. Yet passing tests is only half of what makes code good. Code is read, extended, and maintained long after it is written; a solution that reinvents the wheel is not a good solution, even when every test is green.

Motivation Redundancy is not a cosmetic issue. Over time, every duplicated implementation means a bug fix or an interface change that must be applied twice, a piece of functionality that silently drifts between parallel copies, and more code that every later turn—human or agent—must wade through. Recent studies have already observed the signs: in long-horizon iterative tasks, the redundancy of agent-produced code keeps rising, and agent-generated patches are markedly longer than reference solutions that reuse existing modules (Orlanski et al., 2026; Li et al., 2026; Abbassi et al., 2025; Liu et al., 2025). What is truly alarming is the asymmetry of speed: agents write code far faster than human experts can audit it, so this failure mode accumulates at a staggering rate, quietly piling up into “spaghetti code.”

Yet our evaluation instruments are, in principle, blind to all of this. Existing benchmarks are built almost entirely around functional correctness: HumanEval (Chen et al., 2021), MBPP (Austin et al., 2021), and SWE-bench (Jimenez et al., 2024) score only whether tests pass (i.e., the pass rate), paying little attention to another key dimension of how models write code—reusability. Prior work touches on this dimension but does not measure it in realistic multi-turn, repository-scale development: benchmarks on reuse and maintainability either iterate only at the function level (Wang et al., 2026) or are confined to a single turn (Wang et al., 2025b), while repository-level efforts stop at one-shot completion or well-documented entry points rather than the discovery and reuse of internal modules (Ding et al., 2023; Liu et al., 2023; Tang et al., 2024).

Real iterative development unfolds precisely at the repository scale, across turns: a model must keep developing on an existing multi-file repository, reusing existing code—not only the repository’s own modules, but also the code it wrote in previous turns, which has by then become part of the reposi-

† Equal contribution (listed alphabetically);

  • Corresponding author. Work In Progress.

(a) Benchmark Protocol

Figure

(b) Illustrative Example: Turn 4 → Turn 5

Original Repository

Figure

Earlier Generated Code (T4)

Figure

encoding_batches.py (T5): agent-generated file

Task: Prepare Multiple Batches Using One Shared Scale.

Imports and Calls

from repo.scales import fit_scale

from encoding_pipeline import combine_batches

def prepare_batches(batches):

data, lengths = combine_batches(batches)

scale = fit_scale(data)

values = _encode_values(data, scale)

return _restore_batches(values, lengths)

One function reused from each source; Two wheels reinvented.

Two Functions Are Not Reused.

Rewrites convert_units

def _encode_values(data, scale):

return [scale(x) for x in data]

Rewrites split_batches

def _restore_batches(values, lengths):

ends = cumulative_sum(lengths)

return [values[a:b] for a,b in zip([0]+ends[: -1], ends)]

Functional TestsReuseRepoReuseSelf
Pass1/21/2

Figure 1: Overview of RepoReuse. Left: the benchmark protocol—turn-wise requirements over a workspace that accumulates the agent's own code, scored per turn by functional tests and by recall, reuse, and redundancy. Right: an illustrative example—the agent reuses one repository symbol and one of its own earlier functions but rewrites the two remaining targets; tests pass while both reuse rates are 1/21/2.

tory. To this end, we construct RepoReuse, a multi-turn benchmark for auditing code reuse in real repositories (See Figure 1). Requirements are revealed turn by turn and the workspace accumulates across turns, so that an agent's reuse of both pre-existing repository modules and its own historical implementations can be measured turn by turn. RepoReuse is built by a fully automated pipeline that combines AST-based dependency graphs, guided evidence collection, and execution-verified task synthesis, and scales readily to new repositories (Le et al., 2026; Jain et al., 2024).

Our metrics mirror the agent's per-turn workflow: reading code, deciding what to reuse, and writing new code. The central metric, reuse rate, asks whether the submission calls each target through a real call edge, identified by AST analysis against the reference solution's actual dependencies; repository and self-produced targets are measured separately (reuse repo_{repo} / reuse self_{self}). To explain why a target is missed, upstream recall records the fraction of target source code read in the current turn, separating exploration-side gaps (never read) from execution-side gaps (read but not used); downstream, CdupC_{dup} counts targets that are not called yet have most of their logic rewritten, capturing the redundancy they leave behind (Jiang et al., 2007). Together, the three trace a reuse decision from exploration to consequence, forming a complete auditing instrument for code reuse.

With this auditing instrument, we uncover systematic reuse deficiencies of coding agents. On the exploration side, agents gradually stop retrieving as turns progress: they read 83.6% of relevant repository code at turn 1 on average, but only 35.4% at turn 5. Once the workspace is filled with their own code, reuse decisions are increasingly made from signatures and priors rather than grounded in current-turn observation. On the execution side, a more counterintuitive phenomenon is that seeing is not using: recall over their own historical code is nearly saturated in every turn, yet self-reuse still decays from 83.9% to 69.1%. Ablations further show that disclosing the complete source of historical implementations barely helps, performing on par with providing no memory at all—the bottleneck is not access to information, but the agent's own disposition to build on existing code. Downstream, bypassed targets steadily accumulate as structural redundancy in the workspace: the fraction of task chains containing a cross-turn reimplementation climbs from 13.8% at turn 1 to

50.8% at turn 5, while pass rates barely move. Agents solve task after task correctly while the codebase grows messier turn after turn, pass-rate-centered evaluation is structurally blind to all of it.

Our contributions are as follows:

• An important question: we raise a question neglected by existing evaluation: do coding agents reuse existing code or reinvent the wheel? We give the first systematic, turn-by-turn measurable answer: agents steadily accumulate redundant code that piles up into “spaghetti code.”

• The RepoReuse benchmark: a repository-level multi-turn iterative development benchmark with turn-wise requirement revelation, measuring an agent’s reuse of both pre-existing repository code and its own historical code turn by turn. It is built by a fully automated pipeline that requires no human involvement and scales readily to new repositories.

• Auditing findings: a systematic audit over 3,000 turns of development shows that reuse deficiencies are pervasive and deepen over turns: agents see their own historical code yet fail to reuse it (self reuse decays from 83.9% to 69.1% even under saturated recall); by turn 5, half of the task chains have accumulated cross-turn re-implementations while pass rates barely move—deficiencies entirely invisible to pass-rate-centered evaluation.

References (23)