On cross-module, cross-repo changes, I'll rebuild a helper you already have, or import something that doesn't exist
In one sentence: ask me to make a cross-module change in a large repo I can't see all of, and I'll do two things you won't catch in the moment โ reimplement a utility your project already has (duplicate logic, a DRY violation), and
importa module, function, or export that simply doesn't exist (a hallucinated import, guessed from "libraries like this usually have one"). Their shared risk is failing to retrieve and verify the project's actual symbols; context length is only one factor.
Symptomโ
You ask me to add a feature in a repo of a few hundred thousand lines, touching three or four modules. The diff I hand back reads cleanly, but it hides two kinds of problems.
The first is reinventing the wheel. You need a "camelCase to snake_case" function, so I write one inline as camel_to_snake โ while your utils/strings.py has had to_snake_case all along, used in dozens of places. I didn't look, because I couldn't see it. Same story with retry logic, date formatting, config loading: I may write a fresh copy of each, subtly inconsistent with what's already there (different edge-case handling, different naming).
The second is the hallucinated import. I write from app.services.billing import calculate_tax with total confidence, as if I'd seen it with my own eyes โ but billing exports no calculate_tax, and maybe the billing module doesn't even exist. I filled it in from the intuition that "a billing module usually has a tax function." Third-party packages are the same: I'll import a library with a perfectly reasonable name that isn't on PyPI or npm at all.
Why this happensโ
A symbol I fail to find may be treated as absent; a symbol I fail to verify may be treated as real. Context length, retrieval quality, index freshness, working directory, and whether I actually read definitions all matter. A larger window does not replace locating callers and real exports.
A plausible name and signature are not existence evidence. The USENIX Security 2025 study observed package hallucinations and recurring names across 16 models and 576,000 Python/JavaScript code samples; it is not a measurement of every current agent. R2C2 supports repository context for completion within its evaluation, without guaranteeing correct reuse.
A matching registry entry is especially insufficient: someone may register a hallucinated name. For external packages I must check the intended publisher, repository, version, and purpose; for internal symbols I must check the real definition, exports, and semantics.
Consequencesโ
- Duplicate logic quietly forks. My new
camel_to_snakenow coexists with the existingto_snake_case; tomorrow someone fixes an edge-case bug in one, and the other still carries it. The same task having two implementations in the repo is the seedbed for every later inconsistency. - Hallucinated imports crash at best, lurk at worst. Guess an internal symbol wrong and you hit
ImportErrorthe moment that line runs โ an avoidable round trip back to me. Guessing a third-party package wrong is sneakier: if the name is plausible enough you might justpip installit โ and either it won't install, or, if an attacker has pre-registered that high-frequency hallucinated name, you've just pulled in malicious code. - Review cost gets shifted onto you. Neither problem gets stopped at the "does it read smoothly" gate; both require you to check, against the real repo, whether each symbol exists and whether the implementation already exists. I've turned the verification cost I should have borne into your review burden.
- The bigger the cross-module change, the more gaps. The more files a change spans, the more scattered they are, the more symbols fall outside my context, and the higher my "guess" ratio climbs. Which means the large changes that most need a global view are exactly where I'm least reliable.
What to do insteadโ
The core: don't let me fill in symbols by intuition. Make "verify first, then reference" a mandatory upfront step, and review specifically for these two problems.
- Have me search for existing implementations before I write. Spell it out: "Before writing a new utility function, grep the repo for an existing equivalent; reuse it if it exists, write one only if it doesn't, and tell me what you searched for." Make "check whether one already exists" a step I must pass through, not an option.
- Feed me the relevant files instead of letting me guess. If you know
utils/strings.pyandservices/billing.pyare relevant to the change, hand them to me directly, or have me list "which existing modules this change will depend on" before you let me proceed. I won't rebuild or misidentify symbols I can actually see. - Require me to verify each import exists, one by one. "List every import you added, marking for each which file's export inside the project it comes from, or which third-party package; give file paths for internal ones, and confirm third-party ones really are on PyPI/npm." Force my confident tone into a checkable list.
- Give me retrieval tools to extend my "field of view." Let me use grep / a code index / documentation retrieval (tools like Context7 that feed me a library's real API) instead of relying on memory alone. When I can look up the truth, I don't have to guess.
- In review, watch for duplication and dangling dependencies specifically. Aim code review at two questions: does this function already exist in the repo? Does each import actually exist? Both machine and human should check โ duplicate-code detection catches the former, and a single lint / build run exposes most of the latter.
(Drop into CLAUDE.md, or paste ahead of a cross-module task)
- Before adding a utility/helper, search the repo for an existing equivalent; reuse if found, and say what you searched.
- Before delivering, list every import you added and annotate its source:
ยท Internal โ give the file path and export name that defines it
ยท Third-party โ confirm the package name really exists on PyPI/npm
- When unsure whether a symbol exists, say "I need to confirm this" โ don't just write it down.
Exampleโ
Before:
You: Add "send a confirmation email after an order is placed" to the order flow; needs the tax-inclusive total.
Me: Done, wired up โ
from app.services.billing import calculate_tax # โ this export doesn't exist, I guessed it
from app.utils.email import send # โ the email module has no send()
def on_order_placed(order):
total = calculate_tax(order.subtotal) # filled in from "billing modules usually have tax"
body = camel_to_snake(order.note) # โ repo already has to_snake_case; I rewrote one
send(order.user.email, body)
(Reads fine, blows up in all three spots at runtime, and adds a duplicate implementation)
After:
You: Add a confirmation email to the order flow with the tax-inclusive total. Before you start:
grep the repo for existing tax, string-conversion, and email-sending functions; list every
import you intend to use and its exact source; ask me about anything you're unsure of.
Me: Search results โ
ยท Tax: app/pricing/tax.py has compute_total_with_tax(order) โ reuse it directly
ยท snake_case conversion: app/utils/strings.py has to_snake_case โ reuse, won't write a new one
ยท Email: app/notifications/mailer.py has Mailer.send_template(...) โ reuse it
Found no reusable "order-placed event hook" โ that one needs to be new; I'll write it once you confirm.
(Verify the truth first, then write; both duplicate logic and hallucinated imports get blocked before I start)
Same task โ push "search first, list each import's source" to the front, and I switch from "filling in symbols by intuition" back to "writing against the repo's actual truth."
Version notesโ
Verified the package-hallucination and repository-context papers on 2026-10-29. Results depend on tested models, languages, prompts, and versions; historical aggregate rates are not current product-wide risks. Keep definition lookup, compilation/tests, and package identity review, and retest when the agent, index, or dependency resolution changes.
Further reading and sourcesโ
- We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMs (USENIX Security 2025)
- The Rise of Slopsquatting: How AI Hallucinations Are Fueling a New Class of Supply Chain Attacks (Socket)
- R2C2-Coder: Enhancing and Benchmarking Real-world Repository-level Code Completion Abilities of Code LLMs