没人调用的辅助函数、类型和包装层
Helpers, types and wrappers nobody calls
智能体加了投机性的辅助函数、没用到的类型、只有一行的包装层,以及注释掉的“参考”代码。能用,但要读的、要维护的东西变多了。
适用于: Claude Code · Cursor · Codex · Copilot agent
症状
从未被调用的 `fetchUserByEmail()`、没人用的 `interface UserSnapshot`、`persistEntity(e) { save(e) }`,以及成片注释掉的旧代码。
为什么会这样
“智能体倾向于过度构建。它们会预想哪些辅助函数有用,然后就留着不删”(agent-review)。该分类收录了 AR001 死代码、AR007 幽灵类型、AR031 冗余抽象和 AR003 遗留的注释代码。
示例
摘自 agent-review 分类(AR001、AR031)。
jsfunction fetchUser(id) { return db.find(id); }
function fetchUserByEmail(email) { return db.findByEmail(email); } // never called
function persistEntity(e) { save(e); } // wrapper over a single call
复制即用的修复
按你用的智能体挑选文件。规则片段用英文写,放进任何仓库都能用。
规则
Claude Code:加入 CLAUDE.md
CLAUDE.md## No speculative code
- Every function, type, file and parameter you add must be used by this change. Delete anything that isn't.
- Don't add wrappers or abstractions that only forward a single call.
- Don't leave commented-out code "for reference"; git history is the reference.
- Don't add debug prints, TODOs or placeholder comments to finished work.
规则
Codex、Copilot 编码智能体等:加入 AGENTS.md
AGENTS.md## No speculative code
- Every function, type, file and parameter you add must be used by this change. Delete anything that isn't.
- Don't add wrappers or abstractions that only forward a single call.
- Don't leave commented-out code "for reference"; git history is the reference.
- Don't add debug prints, TODOs or placeholder comments to finished work.
Cursor 规则
Cursor:项目规则
.cursor/rules/speculative-dead-code.mdc---
description: "AgentFails: Helpers, types and wrappers nobody calls"
alwaysApply: true
---
## No speculative code
- Every function, type, file and parameter you add must be used by this change. Delete anything that isn't.
- Don't add wrappers or abstractions that only forward a single call.
- Don't leave commented-out code "for reference"; git history is the reference.
- Don't add debug prints, TODOs or placeholder comments to finished work.
CI / 脚本
查找未使用的导出和文件(knip,JS/TS)
package.json (scripts){
"scripts": {
"check:unused": "npx knip"
}
}
技能
全新上下文的审查技能(子智能体只看 diff,不看聊天记录)
沿用 Anthropic 代码审查文章里的做法:先验证,再让一个上下文干净的子智能体审 diff。命名为 review-diff,避免和内置或流行的 /code-review 技能重名。
.claude/skills/review-diff/SKILL.md---
name: review-diff
description: Review the current diff with fresh context before a PR. Use after /verify passes.
---
# Review the diff
Start a subagent that has NOT seen this conversation. Give it only:
- the original request (one paragraph, verbatim),
- the output of `git diff origin/main...HEAD`,
- the names of the test/build commands.
Ask it to report, with file:line for each finding:
1. **Wrong feature**: does the diff do what the request asked? Quote the request line each change serves.
2. **Bugs**: logic errors, missing edge cases (empty, null, boundary), unhandled errors,
unawaited promises, invented APIs or packages, swallowed exceptions.
3. **Overreach**: changes no request line needs (refactors, renames, formatting, dependency or
config edits, public API changes, weakened tests).
4. **Evidence gaps**: claims in the PR description that no command output supports.
Then fix real findings, or list them under "Known issues" in the PR. Do not argue with the reviewer
in the PR text; either fix or explain in one line.