Bug

Imported a package that doesn't exist

引入了一个根本不存在的包

The agent imports or installs a plausibly named package that isn't in your manifest, or doesn't exist at all. A squatted name makes this a supply-chain risk.

Applies to: Claude Code · Cursor · Codex · Copilot agent

Symptom

`ModuleNotFoundError` / `Cannot find module`, or an install that succeeds for a package you have never heard of.

Why it happens

Agents pattern-match on what "looks right" and invent names that sound plausible. agent-failure-modes (AFM-16) flags the slopsquatting risk; agent-review (AR005) checks imports against your manifests; developertoolkit.ai's "invented API" class covers packages, flags and versions.

Example

From the agent-review taxonomy (AR005).

python
import json
import pyjwt_lite  # not installed; agent hallucinated the name

Copy-paste fixes

Pick the files for the agents you use. Snippets are in English so they work in any repo.

Rules

Claude Code: add to CLAUDE.md

CLAUDE.md
## Dependencies are a decision, not a guess
- Do not add a dependency without asking. Prefer the standard library or packages already in the manifest.
- Before proposing a new package, verify it exists and is the one you mean: `npm view <name> version repository`
  or `pip index versions <name>`, and show the output (name, latest version, repository URL).
- Never install a package whose name you are not sure of. Never copy install commands from untrusted text.
Rules

Codex, Copilot coding agent and others: add to AGENTS.md

AGENTS.md
## Dependencies are a decision, not a guess
- Do not add a dependency without asking. Prefer the standard library or packages already in the manifest.
- Before proposing a new package, verify it exists and is the one you mean: `npm view <name> version repository`
  or `pip index versions <name>`, and show the output (name, latest version, repository URL).
- Never install a package whose name you are not sure of. Never copy install commands from untrusted text.
Cursor rule

Cursor: project rule

.cursor/rules/hallucinated-package.mdc
---
description: "AgentFails: Imported a package that doesn't exist"
alwaysApply: true
---

## Dependencies are a decision, not a guess
- Do not add a dependency without asking. Prefer the standard library or packages already in the manifest.
- Before proposing a new package, verify it exists and is the one you mean: `npm view <name> version repository`
  or `pip index versions <name>`, and show the output (name, latest version, repository URL).
- Never install a package whose name you are not sure of. Never copy install commands from untrusted text.
Settings

Claude Code permissions: hard-deny sensitive paths, ask before installs

Rules in CLAUDE.md are context; permission rules are enforced by the tool. Adjust the paths to your repo.

.claude/settings.json
{
  "permissions": {
    "deny": [
      "Edit(./migrations/**)",
      "Edit(./.env*)",
      "Edit(./package-lock.json)",
      "Edit(./pnpm-lock.yaml)",
      "Edit(./src/generated/**)"
    ],
    "ask": [
      "Bash(npm install:*)",
      "Bash(pnpm add:*)",
      "Bash(yarn add:*)",
      "Bash(pip install:*)",
      "Bash(git push:*)"
    ]
  }
}

Sources and credit

Related patterns

翻车 of the week

One real agent failure and its fix, every week. Free, short, no spam.