Do coding agents reuse existing code, or reinvent the wheel?
π The manuscript is being revised. Where it differs from this repository, the Results table here is authoritative.
π¬ Questions about the code are welcome β open an issue or contact us.
RepoReuse is a multi-turn benchmark for auditing code reuse in real repositories. Each task is a chain of requirements on one repository, revealed one turn at a time; the workspace carries over, so later turns run in a codebase the agent has partly written itself. Alongside the pass rate we score, per turn, what the agent read, what it actually reused, and how much it duplicated.
218 task chains / 1090 turns across 15 repositories β astropy, dask, django, matplotlib, networkx, pint, pvlib, pydicom, scikit-learn, seaborn, sphinx, sqlfluff, sqlglot, sympy, xarray.
(a) repos are mined into an AST dependency graph that drives task synthesis
and execution verification, yielding 218 task chains (5.0 turns/chain, 11.6
tests/turn).
(b) each turn, a fresh agent extends its own earlier files on a new
requirement and is scored on hidden tests plus read/reuse/duplication.
(c) turn 4 β 5 example: the agent reuses fit_scale and combine_batches
but reinvents convert_units and split_batches β tests pass, reuse is only
1/2 each.
(d) duplication rises from 6.4% (turn 1) to 50.0% (turn 5) as self-reuse
falls from 87.2% to 70.2%.
This repository is the evaluation harness; the task package lives on π€ Hugging Face.
git clone https://github.com/OpenDCAI/RepoReuse.git
cd RepoReuse
./server-setup.sh # creates .venv, installs deps, runs the unit testsPython β₯ 3.9 for the harness, β₯ 3.10 for the mini-swe agent. Docker is not
required: the default backend builds one conda environment per repository on the
host. SETUP.md covers the repositories, their environments, and
troubleshooting.
python -m evalkit.hub download --repo-id risemds03/RepoReuse
python -m evalkit.hub status # path, content digest, chain and turn countsIt lands in ./data/RepoReuse/ and is validated on arrival β every gold
checksum, every declared function contract, and a package-wide content digest
recorded in each run manifest. Already have a copy? Point EVALKIT_BENCH at it.
cp .env.example .env.local
$EDITOR .env.local # EVAL_MODEL_NAME, EVAL_API_BASE (ending at /v1), EVAL_API_KEY./run_eval.sh --smoke # 3 seaborn chains: proves the whole path
./run_eval.sh # mini-swe over every chain
./run_eval.sh --agents mini-swe,opencode # both harnessesrun_eval.sh is the single entry point and runs, in order: credential and
/models pre-flight β per-repository environment build β gold must pass /
null must fail self-check β the measured run β dependency trees β
metrics.json. The self-check costs no API calls and is what separates "the
environment is broken" from "the agent is bad".
./run_eval.sh --agents opencode --repos seaborn,sympy
./run_eval.sh --workers 4 --limit 20
./run_eval.sh --dry-run # print the plan and the exact commands
./run_eval.sh --help--backend docker switches to the container backend, and everything after --
is forwarded verbatim to evalkit.runner.
Everything lands under runs/<run_id>/. Two files answer most questions:
| File | What's in it |
|---|---|
metrics.json |
the scores β reuse, recall, correctness, plus by_round[t] for the per-turn curves |
<task_id>/<mode>/round<t>/traj.json |
what the agent actually did that turn, step by step (credentials scrubbed) |
Each turn directory also keeps requirement.md (exactly what the agent was
given), solution.py (what it submitted), read_events.json (its reads,
normalised to {path, start, end, channel}), test_output.txt and
result.json. Re-score an existing run with
python -m evalkit.score --run-id <id>.
It resumes. Re-issue the same --run-id and finished turns are skipped β the
harness only resumes in place when the benchmark, agent, task list, backend,
limits and workspace identity all match, and when the completed turns form an
unbroken prefix. For an interrupted run with leftovers, continue into a new
ID instead:
python -m evalkit.runner --continue-from full_run_a --run-id full_run_a_cont1 --workers 2The source is opened read-only and only the verified prefix is copied,
digest-checked before and after. One limitation, recorded in the new manifest
rather than papered over: restoring a workspace replays each turn's
solution.py to its canonical path, which is partial fidelity β it cannot
restore edits the agent made to other files, deletions, or by-products.
An excerpt from the paper: mini-SWE-agent, four models. All figures are %;
C_dup is the cross-turn duplication rate, averaged over the five cumulative
turn-wise rates.
| Model | reuse repo | reuse self | recall repo | recall self | Resolve | Pass | C_dup |
|---|---|---|---|---|---|---|---|
| GPT-5.6 Terra | 56.4 | 66.4 | 60.2 | 98.8 | 68.7 | 91.5 | 35.6 |
| DeepSeek-v4.1-flash | 51.8 | 77.0 | 62.0 | 100.0 | 69.1 | 92.2 | 26.9 |
| Grok-4.5 | 60.2 | 73.4 | 66.9 | 99.7 | 71.3 | 91.9 | 42.3 |
| Step-5-Preview | 53.8 | 71.1 | 64.9 | 99.7 | 65.0 | 90.9 | 36.7 |
The gap between the two self columns is the point. Recall of the agent's own
earlier code is essentially saturated β it can find what it wrote, and the code
is sitting in its workspace β yet it reuses only two thirds to three quarters of
it, and leaves duplicated logic behind in a quarter to over 40% of chains. Pass
rates stay inside a 91 Β± 1 band throughout, so none of this is visible from
correctness alone.
The paper reports the full matrix (three harnesses Γ four models) and the turn-by-turn breakdown.
How a turn runs. One chain, one workspace, turns accumulating inside it.
The agent gets requirement.md and nothing else, works in the repository with
its own tools, and its submission is taken from <workdir>/<submit_to>; only
then is the hidden test.py copied in, run in a throwaway directory, and
deleted. It never sees test.py, gold/, the ground truth, an earlier turn's
trajectory, a future turn's requirement, or grader feedback. Requirements
arrive one turn at a time (hand over all five and the agent plans once, never
needing to find its own earlier code) and every turn is a fresh session (keep it
alive and the previous turn's code is still in context, so recall_self pins at
1.0). Scoring is not a gate: turn t+1 depends only on the files turn t left
behind, so a broken implementation stays in the workspace.
What comes out. The columns above are metrics.json fields by the same
name:
| Field | Definition |
|---|---|
reuse_repo |
share of the repository symbols the reference solution uses that the submission actually references |
reuse_self |
the same, for functions the agent authored in earlier turns |
recall_repo |
share of those repository symbols whose body the agent actually viewed |
recall_self |
the same, for its own earlier-turn functions |
resolved_rate |
share of turns whose tests all pass (binary; 8/10 does not count) |
passed_rate |
mean over turns of passed/total assertions (soft credit) |
C_dup |
computed in the paper's analysis, not emitted by this scorer; bloat is the closest signal available today |
Every metric is <family>_<target set>, and recall_* and reuse_* share each
set exactly β same denominator, counted in targets rather than lines β so the
two are directly comparable. A target is read when a view or search overlaps
any line of its body, and reused when the submission references its name in a
value position; an import alone does not count. Ratios are computed per turn,
then macro-averaged; undefined is not zero, so turn 1 is excluded from the self
averages. Beyond the table, metrics.json carries recall_read (the broader
declared read-target set), bloat, rediscovery, reuse_grounding and
per-target attribution.
Exploration numbers are not comparable across harnesses. A line-ranged
readis exact; a barecatcan only be charged as the whole file. Compare trends across turns within a harness β which is where the finding lives.
--agents |
What it is | API calls |
|---|---|---|
mini-swe |
mini-swe-agent, run in-process; bash only | yes |
opencode |
the opencode CLI, headless; native tool set, line-exact reads |
yes |
gold |
writes the reference solution. Must pass. | no |
null |
writes nothing. Must fail. | no |
oracle |
scripted: reads the ground-truth locations, then writes gold. Must score recall_read = 1.0. |
no |
The three probes are not decoration β a harness is only trusted once all three behave. The oracle in particular catches a trajectory parser that silently drops events: it is how a 94-step trajectory parsing out to zero read events was found.
Adding your own. The two shipped harnesses cover both shapes a harness can
take β bash-only, where read events come from parsed shell commands, and a
native tool set that reports line windows β so porting a third is a small job.
Because every turn is a fresh session, anything that can "take a workspace and
an instruction, then hand back the files and a trajectory" fits: implement
AgentAdapter (evalkit/adapters/base.py), normalise its trajectory to
ATIF
in a *_atif.py module, and register it in evalkit/adapters/__init__.py.
readevents.py dispatches on tool name rather than on harness, so bash,
read, grep/glob and str_replace_editor(view) already work. cli.py
handles subprocess, environment and credential plumbing for anything driven as
an external CLI.
run_eval.sh one entry point: pre-flight -> setup -> self-check -> run -> score
server-setup.sh venv and dependency bootstrap
SETUP.md the 15 repositories, their environments, troubleshooting
evalkit/
bench.py load, validate and identify a task package
hub.py fetch (or publish) a task package on the HuggingFace Hub
deptree.py AST dependency graph: symbol -> (path, start, end)
runner.py turns x chains x modes, resume and continuation
score.py correctness + exploration + reuse
readevents.py trajectory -> ReadEvent{path, start, end, channel}
atif.py trajectory normalisation; one *_atif.py module per harness
adapters/ gold | null | oracle | mini-swe | opencode
local/ default backend: one conda env per repo + pristine snapshot
images/ Docker backend: reference implementation and extension point
tests/ 167 unit tests; the ones that sweep the task package skip without it
@misc{ma2026codingagentsreuseexisting,
title={Do Coding Agents Reuse Existing Code or Reinvent the Wheel?},
author={Dongsheng Ma and Sizhe Wang and Xinyi Huang and Zhengren Wang and Yuhan Wang and Luyang Si and Xincheng Wei and Wentao Zhang},
year={2026},
eprint={2609.35357},
archivePrefix={arXiv},
primaryClass={cs.SE},
url={https://arxiv.org/abs/2609.35357},
}We are releasing the latest version of the code first β the manuscript is still being revised, so the paper and this repository may differ in places until the next arXiv version lands. The release is our way of giving back to the AI community, and we would be glad to see RepoReuse used as a foundation for new work: build on the benchmark, extend it to new repositories, plug in your own harness, or take the metrics somewhere we did not. If you do, we would love to hear about it.
Questions, bug reports and requests for access to the task package are all welcome β open an issue, or email:
- Dongsheng Ma β madongsheng26@stu.pku.edu.cn
- Sizhe Wang β wangsz26@m.fudan.edu.cn
Apache-2.0. The evaluated repositories are not redistributed here β the harness clones each at a pinned commit from upstream, under its own license. See NOTICE for third-party components.
