Force code search before generate

Agents duplicate what they cannot see. A reuse-first habit forces search before generate: find helpers, patterns, and endpoints that already exist, then.

Published 2026-11-09 · Translation: VI

Agents duplicate what they cannot see. A reuse-first habit forces search before generate: find helpers, patterns, and endpoints that already exist, then implement only the true gap.

The trap is accepting a shiny new utils2 because the agent never looked. Duplication is the quiet tax of AI coding. It grows the surface area and splits the real source of truth.

Search, compare, then generate only the gap

Workflow

Workflow

  1. State behavior, not “create a function.” Describe the capability the caller needs.
  2. Require repo search. Symbols, text, and semantic search across the package ecosystem, not only the open file.
  3. Summarize candidates. The agent lists what it found and why each fit or failed.
  4. Extend when fit is good. Prefer one more call site or a small extension over a twin helper.
  5. Generate only true gaps. New code lands in the correct package with a one-line “why reuse failed.”
  6. Review for twins first. Style nits come after duplication checks.

Stop gates: when to reject the new helper

Stop gates before you ship

Stop gates before you ship

  • No search evidence. New helpers without a candidate list get rejected.
  • Open-file-only search. The agent never left the current buffer. Require package-level search.
  • Stale pattern copy. It copied from a module the team already replaced. Point it at the current exemplar.
  • Parallel client or endpoint. Discovery failed, so it reinvented the integration. Stop and find the real one.

Checklist before you accept new code

Ship checklist

Ship checklist

Practical defaults:

  • PR template field: “candidates considered.”
  • One exemplar file in the prompt so the agent sees local style and the real helper location.
  • When a twin slips through, open a follow-up to delete it. Closing the loop teaches the system.

Bottom line

Search before generate keeps the codebase coherent under agent load. Cite candidates, prefer reuse, and reject undocumented new helpers. For context that helps the agent find the right files without dumping the repo, see agent context budgets.

Share

X Facebook LinkedIn
Educational content only. Rankings reflect stated criteria at the update date—not investment advice or permanent performance guarantees.