有 Bug

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

Imported a package that doesn't exist

智能体导入或安装了一个名字很像真的包,它不在你的依赖清单里,甚至根本不存在。如果这个名字被人抢注,就成了供应链风险。

适用于: Claude Code · Cursor · Codex · Copilot agent

症状

出现 `ModuleNotFoundError` / `Cannot find module`,或者安装成功了一个你从没听过的包。

为什么会这样

智能体按“看起来对”来套模式,编出听起来合理的名字。agent-failure-modes(AFM-16)提示了“slopsquatting”(抢注幻觉包名)风险;agent-review(AR005)会把 import 和依赖清单比对;developertoolkit.ai 的“invented API”类别也涵盖包、参数和版本。

示例

摘自 agent-review 分类(AR005)。

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

复制即用的修复

按你用的智能体挑选文件。规则片段用英文写,放进任何仓库都能用。

规则

Claude Code:加入 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.
规则

Codex、Copilot 编码智能体等:加入 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 规则

Cursor:项目规则

.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.
配置

Claude Code 权限:硬性禁止敏感路径,安装依赖前先询问

CLAUDE.md 里的规则只是上下文;权限规则由工具强制执行。按你的仓库调整路径。

.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:*)"
    ]
  }
}

来源与致谢

相关条目

每周翻车

每周一个真实的智能体翻车案例和它的修复。免费、简短、不刷屏。