# The Package Was Invented. It Spread Anyway.

> The agent made up a dependency name, the install failed, and the invented name still reached a second service. What propagates downstream is not the package but the trace it left behind.

**Type:** Blog post  
**Author:** PasteCode  
**Published:** 2026-09-12  
**Updated:** 2026-09-12  
**Tags:** Dependencies, Security, Cursor, Codex, Review  
**URL:** https://pastecode.xyz/blog/how-a-package-that-never-existed-got-into-two-services

---

A colleague was reviewing a pull request and asked why we had switched a validation helper to a package he had never heard of. It was a small dependency, three lines of import, used in one service. The `package.json` entry looked normal. The build was green in CI.

The name in the pull request description did not exist. Not "was unmaintained", not "was renamed". There was no such package on the registry. The code that shipped imported something else entirely, and nothing in the diff said so.

Two weeks later, the same invented name appeared in a second service, in a commit message written by a different engineer who had read the first repository. The hallucination was no longer an incident. It was a convention.

## What actually shipped

The chain is short and boring, which is what makes it hard to catch.

The agent was asked to add form validation with server-side error mapping. It wrote a plausible import for a plausible helper, because that is what the pattern in its training data looks like:

```ts title="the invented dependency"
// plausible scope structure, no such package
import { mapIssues } from "@next/safe-actions";
```

The scope `@next` exists and the name is the kind of thing that would exist, so nothing in the sentence reads as wrong. The install failed. The retry resolved a *different*, similarly-named package that does exist, and the agent edited the code to match it, explained the substitution in one line of chat, and finished with a working build.

That part is fine. Substituting a real package for an invented one is the correct move, and it is not what caused the problem.

## What propagates is the trace, not the dependency

Here is the bit I had wrong the first time I thought about this.

A name that does not exist cannot be installed, so a lockfile can never contain it. But the invented name does not need to be installed to spread. It lives in the places that record *intent*: the pull request title, the summary of what changed, the code comment (`// uses @next/safe-actions under the hood`), the chat message in the ticket. Someone reading that trace later has no reason to doubt it, because at that point the feature works.

So the second service did not copy a dependency. It copied a claim. An engineer read "we standardised on X for server action error mapping", believed it, and wrote the same import. The install failed again, and the same silent substitution happened again. Two services, two engineers, one fabricated fact, zero broken builds.

That is the failure mode worth naming: **the reviewable surface of a change is the diff, and the fabricated part sits outside it.** Every artifact I actually looked at during review was true. The lie was in the sentence above the diff.

## Why the plausibility is the risk

A model generating an import is predicting the most likely string, not recalling a verified one. Registry names are short, idiomatic and highly predictable, so the output is fluent even when it is false. The same property that makes the names easy to guess makes false ones indistinguishable from real ones by reading.

This is the setup for what the security community calls **slopsquatting**: registering the names models most often invent, and waiting. It costs an attacker a registry publish. It costs you an install, and whatever the postinstall script does with your build environment.

The standard advice here is "be careful about hallucinated packages", which is not a rule anyone can act on. You cannot be careful in the abstract. You need a source of truth that is not the model.

## The registry is the source of truth, and it is cheap to ask

Checking that a package exists should not be a research project. Two commands cover almost everything, and both belong in the same breath as "does it typecheck".

```bash title="does it exist, who publishes it"
# Does the package exist in the registry at all?
npm view @next/safe-actions version
# npm error 404 — that name is not published. Stop here.

# What else should I know before adding it?
npm view <package> maintainers time.modified repository homepage
```

A 404 is the easy case. The interesting case is a package that exists and is three weeks old with one maintainer and no repository field, which is what you get when someone registered the name after reading the same kind of bug report the agent read. `time.modified` and `maintainers` are the two fields I look at first.

There is also a lower-effort check that catches most of it before you get that far: search the registry instead of the model.

```bash title="what exists vs what the model said"
npm search "zod form errors" --searchlimit=10
```

If the model's suggested name does not appear in the registry's own search results for the job it was supposed to do, that is the signal. The registry search ranks by what is published and downloaded. The model ranks by what sounds right.

## The rule, as I wrote it down

The line I put in `AGENTS.md` is deliberately not about the model's behaviour, because I cannot verify that:

> Never add a dependency that is not already in the lockfile without showing the output of `npm view <name> version` in the same message. If the command 404s, stop and tell me the name was invented.

The important part is "in the same message". A rule that asks the agent to be accurate gets ignored politely. A rule that asks for an artifact means I can see, in the transcript of the session, whether the check happened. It turns a trust problem into a reading problem.

I also stopped accepting "the other repo uses this" as a reason to add anything, and started asking for the name that was actually installed rather than the one in the description. That reasoning is how the second service picked up the claim. Cross-repository copying is a fine instinct for patterns and a bad one for dependencies, because the pattern carries the package name with it.

## What it costs to be wrong

Cheap: you notice in review, delete four lines, move on. That is most cases, and it is why this failure stays low on people's lists.

Expensive: the name was registered before you installed it. Then it is not a code-quality problem, it is a supply-chain event on a machine that holds your environment variables. The asymmetry is the whole argument for spending thirty seconds on the registry.

If you want the longer write-up of the failure pattern and the fixes, it is [here in the failures section](/failures/ai-invents-fake-npm-packages). The short version is the one to remember: the model's confidence and the registry's contents are unrelated facts, and only one of them can be checked in a terminal.