GuidesUpdated

How do I stop a coding agent rebuilding an existing feature?

Have the agent find the existing implementation and its callers before editing, then review the smallest change against the running app.

On this page

You ask for a CSV download on the billing page. The agent adds a new export service, though the project already has one for reports. It demos fine but leaves two authorization paths and two file formats to maintain. Before it writes code, ask the agent where the current behavior lives and what it can reuse. Then judge the change in the running app and the diff.

Canopy agent workspace joining a coding session with project files and changed code
Canopy agent workspace joining a coding session with project files and changed code

Search for the behavior before choosing a design

Start from the user-facing words: the page label, button, route, error text and any existing CSV export. Ask the agent to search the checkout and report file paths, callers, tests and the branch it inspected. The helper you need may have a different name.

GitHub's code navigation traces symbols and references; `git grep` searches your working tree. One hit doesn't prove code is live, so follow the route or import chain from the running page.

  • Check whether a candidate serves the current app, an old route or a test fixture.
  • Record the checkout and branch; another worktree can hold a different implementation.

Ask for a short reuse decision

The agent compares the reports exporter with the requested CSV: who may export, which rows, columns, timezone, escaping and file naming. Reusing, extending or building separately can each be right; have it cite the evidence before editing.

A rule like 'never write a new helper' forces bad reuse. Ask instead what it checked and why the boundary fits. Review any new package's need and cost before it's installed.

A decision record for the billing CSV example.
CandidateEvidence to inspectPossible decision
Existing reports exporterCallers, access check, row mapping, CSV escaping, testsReuse or extend if its contract fits
Billing page's current download pathRoute, button handler, permissions, error statesConnect to it if it already owns the action
New export serviceA security or data contract existing code can't meetAdd only with a documented reason and focused tests

Give one bounded implementation task

Name one observable outcome: a permitted billing user downloads the expected rows, an unauthorized user can't, and the reports export still works. Let the agent explain if the search shows a different owner.

Keep research and implementation on the same Canopy project and checkout. A second agent can review the reuse decision, but a second terminal tab doesn't isolate edits; use a worktree.

  • Have the agent stop for a decision if the access rule or CSV contract is unclear.
  • Keep acceptance checks in the task, not only the chat.

Check the live result and final diff

Run the app from the same checkout with safe sample data. Check the CSV header, rows, empty and error states, and access boundary. Run a reports export to catch regressions in shared code.

Review the diff for duplicate endpoints, helpers, dependencies and unrelated files. Call paths and observed behavior outweigh the agent's claim that it reused code.

  • Confirm the page, process, branch and PR head refer to the same change.
  • If the design is still unclear, have a qualified reviewer decide before merge.

Leave a small map for the next session

Record the active route, export helper, access rule, test command and owner in the project docs or task handoff. Keep it short and linked to source; stale catalogs mislead the next agent. CLAUDE.md gives Claude Code stable conventions, but it doesn't replace checking today's code. Never write an agent's unverified architecture claim into shared instructions.

Copyable resources

Read before you build

Use a read-only first pass. Replace the example with your behavior and paths.

Task: Add a CSV download to the billing page. Do not edit yet.
Checkout and branch inspected: [ ]
Search for the page, current download route, existing CSV/export helpers, callers and tests.
Return: active path from UI to data; reuse candidates with file paths; access and data contracts; unknowns; smallest proposed change.
Stop if the existing export's contract or billing access rule is unclear.
After I approve: implement only the agreed change. Test an allowed user, a denied user, the expected CSV rows and the existing reports export. Show the running result, commands and outcomes, and the changed-file list.

Frequently asked questions

Should I put 'always reuse existing code' in my agent instructions?

Ask for an evidence-based reuse check instead. Existing code may be obsolete or have the wrong security or data contract; forcing the task into it can be as harmful as duplicating it.

Can a project map prevent the agent from forgetting the codebase?

A short, maintained map points the first search in the right direction. It can't prove the mapped code is still live, so check source paths and callers before editing.

What if the agent already built a duplicate feature?

Keep the diff, compare both paths and their contracts, and pick one reviewed implementation. Run the affected journeys before removing anything; don't delete the older path just because the new one demos well.

More questions and answers →

Sources and further reading