重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
dead-code-detector by terrylica/cc-skills
npx skills add https://github.com/terrylica/cc-skills --skill dead-code-detector广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
在以下情况下使用此技能:
不适用于 : 代码重复(请使用 quality-tools:code-clone-assistant)
# 步骤 1: 安装
uv pip install vulture
# 步骤 2: 以 80% 置信度阈值进行扫描
vulture src/ --min-confidence 80
# 步骤 3: 为误报生成白名单
vulture src/ --make-whitelist > vulture_whitelist.py
# 步骤 4: 使用白名单重新扫描
vulture src/ vulture_whitelist.py --min-confidence 80
# 步骤 1: 安装(推荐项目本地安装)
bun add -d knip
# 步骤 2: 初始化配置
bunx knip --init
# 步骤 3: 扫描死代码
bunx knip
# 步骤 4: 自动修复(移除未使用的导出)
bunx knip --fix
# 步骤 1: 扫描死代码警告
cargo clippy -- -W dead_code -W unused_imports -W unused_variables
# 步骤 2: 用于更严格的强制执行
cargo clippy -- -D dead_code # 拒绝(错误)而非警告
# 步骤 3: 自动修复可能的部分
cargo clippy --fix --allow-dirty
| 置信度 | 含义 | 操作 |
|---|---|---|
| 100% | 在分析的文件中保证未使用 | 可以安全移除 |
| 80-99% | 极有可能未使用 | 移除前需审查 |
| 60-79% | 可能未使用(动态调用、框架) | 如果是故意的,则添加到白名单 |
常见误报(由框架调用的代码):
Knip 使用 TypeScript 的类型系统来提高准确性。在 knip.json 中配置:
{
"entry": ["src/index.ts"],
"project": ["src/**/*.ts"],
"ignore": ["**/*.test.ts"],
"ignoreDependencies": ["@types/*"]
}
使用属性来抑制误报:
#[allow(dead_code)] // 单个项目
fn intentionally_unused() {}
// 或模块范围
#![allow(dead_code)]
[tool.vulture]
min_confidence = 80
paths = ["src"]
exclude = ["*_test.py", "conftest.py"]
{
"scripts": {
"dead-code": "knip",
"dead-code:fix": "knip --fix"
}
}
[lints.rust]
dead_code = "warn"
unused_imports = "warn"
详细信息请参阅:
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 报告框架调用的代码 | 框架魔法 / 回调 | 添加到白名单或排除配置 |
| 遗漏动态加载的代码 | 不在静态入口点中 | 配置入口点以包含插件/扩展目录 |
| 警告测试专用辅助函数 | 测试代码单独编译 | 使用条件编译或测试专用排除项 |
| 误报过多 | 阈值过低 | 提高置信度阈值或配置忽略模式 |
| 缺少仅类型引用 | 仅编译时使用 | 大多数现代工具能处理此情况;检查工具版本 |
重要提示:在移除任何检测到的"死代码"之前,请生成并行子代理,从多个角度验证发现结果。死代码实际上可能是未实现的功能或不完整的集成。
| 发现类型 | 真正的死代码 | 未实现的功能 | 不完整的集成 |
|---|---|---|---|
| 未使用的可调用对象 | 无调用者、无测试、无文档 | 有 TODO/FIXME,在规范中被引用 | 存在部分调用链 |
| 未使用的导出/公共项 | 在任何地方都未导入 | 在公共 API 中,有文档记录 | 在兄弟模块中使用 |
| 未使用的导入/包含 | 拼写错误,重构后移除 | 需要其副作用 | 仅类型或编译时使用 |
| 未使用的绑定 | 已赋值但从未读取 | 未来功能的占位符 | 调试/检测代码已移除 |
运行检测工具后,生成以下并行子代理:
┌─────────────────────────────────────────────────────────────────┐
│ 死代码发现结果 │
└─────────────────────────────────────────────────────────────────┘
│
┌───────────────────┼───────────────────┐
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ 意图代理 │ │ 集成代理 │ │ 历史代理 │
│ │ │ │ │ │
│ - 检查 TODO │ │ - 追踪调用链 │ │ - Git blame │
│ - 搜索规范 │ │ - 检查导出 │ │ - 提交信息 │
│ - 查找问题 │ │ - 测试覆盖率 │ │ - PR 上下文 │
│ - 阅读 ADR │ │ │ │ - 作者意图 │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
└───────────────────┼───────────────────┘
▼
┌─────────────────────────────────────────────────────────────────┐
│ AskUserQuestion: 确认分类 │
│ [ ] 真正的死代码 - 可以安全移除 │
│ [ ] 未实现的功能 - 创建 GitHub Issue 以跟踪 │
│ [ ] 不完整的集成 - 调查集成差距 │
│ [ ] 误报 - 添加到白名单 │
└─────────────────────────────────────────────────────────────────┘
意图代理(搜索计划中的使用):
在以下位置搜索对 [标识符] 的引用:
1. 代码库中的 TODO/FIXME/HACK 注释
2. 问题跟踪器(开放和已关闭的问题)
3. 设计文档和架构决策记录
4. README 和项目文档文件
报告:此代码是否已计划但尚未集成?
集成代理(追踪执行路径):
对于 [标识符],分析:
1. 所有模块导入/包含/使用语句
2. 运行时模块加载机制(延迟加载、插件)
3. 框架调用模式(元数据属性、配置绑定、注解)
4. 可能执行此代码路径的测试文件
报告:是否存在部分或间接的调用链?
历史代理(调查来源):
对于 [标识符],检查:
1. VCS blame/annotate - 谁在何时编写了它
2. 提交信息 - 声明的意图是什么
3. 代码审查 / 合并请求上下文 - 是否是更大功能的一部分
4. 最近的提交 - 调用代码是否被移除或重构
报告:这是有意遗弃还是意外损坏?
# 步骤 1: 为你的语言运行检测工具
<工具> <源路径> --confidence-threshold 80 > findings.txt
# 步骤 2: 对于每个高置信度的发现结果,生成验证
# (Claude Code 将使用 Task 工具配合 Explore 代理)
示例发现 : 未使用的函数 'calculate_metrics' (src/analytics.py:45)
多代理调查结果:
结论:不是死代码 - 这是一个未实现的功能。创建跟踪问题。
代理分析后,使用 AskUserQuestion 并设置 multiSelect: true:
AskUserQuestion({
questions: [
{
question: "我们应该如何处理这些发现结果?",
header: "操作",
multiSelect: true,
options: [
{
label: "移除已确认的死代码",
description: "删除已验证为真正未使用的项目",
},
{
label: "为未实现的功能创建问题",
description: "在 GitHub Issues 中跟踪计划的功能",
},
{
label: "调查不完整的集成",
description: "对部分实现进行更深入的分析",
},
{
label: "更新白名单",
description: "将误报添加到工具白名单",
},
],
},
],
});
| 风险等级 | 标准 | 操作 |
|---|---|---|
| 低 | 100% 置信度,在任何地方都无引用,超过 6 个月 | 使用 VCS 提交自动移除 |
| 中 | 80-99% 置信度,有一些间接引用 | 首先使用代理验证 |
| 高 | <80% 置信度,近期代码,有测试覆盖率 | 需要手动审查 |
| 关键 | 公共 API 表面,有文档记录,有外部依赖者 | 切勿自动移除 |
每周安装数
57
仓库
GitHub 星标数
22
首次出现
2026年2月7日
安全审计
安装于
opencode56
gemini-cli55
github-copilot55
amp55
codex55
kimi-cli55
Find and remove unused code across Python, TypeScript, and Rust codebases.
| Language | Tool | Detects |
|---|---|---|
| Python | vulture v2.14+ | Unused imports, functions, classes, variables |
| TypeScript | knip v5.0+ | Unused exports, dependencies, files |
| Rust | cargo clippy + rustc lints | Unused functions, imports, dead_code warnings |
Why these tools?
Use this skill when:
NOT for : Code duplication (use quality-tools:code-clone-assistant)
# Step 1: Install
uv pip install vulture
# Step 2: Scan with 80% confidence threshold
vulture src/ --min-confidence 80
# Step 3: Generate whitelist for false positives
vulture src/ --make-whitelist > vulture_whitelist.py
# Step 4: Re-scan with whitelist
vulture src/ vulture_whitelist.py --min-confidence 80
# Step 1: Install (project-local recommended)
bun add -d knip
# Step 2: Initialize config
bunx knip --init
# Step 3: Scan for dead code
bunx knip
# Step 4: Auto-fix (removes unused exports)
bunx knip --fix
# Step 1: Scan for dead code warnings
cargo clippy -- -W dead_code -W unused_imports -W unused_variables
# Step 2: For stricter enforcement
cargo clippy -- -D dead_code # Deny (error) instead of warn
# Step 3: Auto-fix what's possible
cargo clippy --fix --allow-dirty
| Confidence | Meaning | Action |
|---|---|---|
| 100% | Guaranteed unused in analyzed files | Safe to remove |
| 80-99% | Very likely unused | Review before removing |
| 60-79% | Possibly unused (dynamic calls, frameworks) | Add to whitelist if intentional |
Common false positives (framework-invoked code):
Knip uses TypeScript's type system for accuracy. Configure in knip.json:
{
"entry": ["src/index.ts"],
"project": ["src/**/*.ts"],
"ignore": ["**/*.test.ts"],
"ignoreDependencies": ["@types/*"]
}
Suppress false positives with attributes:
#[allow(dead_code)] // Single item
fn intentionally_unused() {}
// Or module-wide
#![allow(dead_code)]
[tool.vulture]
min_confidence = 80
paths = ["src"]
exclude = ["*_test.py", "conftest.py"]
{
"scripts": {
"dead-code": "knip",
"dead-code:fix": "knip --fix"
}
}
[lints.rust]
dead_code = "warn"
unused_imports = "warn"
For detailed information, see:
| Issue | Cause | Solution |
|---|---|---|
| Reports framework-invoked code | Framework magic / callbacks | Add to whitelist or exclusion config |
| Misses dynamically loaded code | Not in static entry points | Configure entry points to include plugin/extension directories |
| Warns about test-only helpers | Test code compiled separately | Use conditional compilation or test-specific exclusions |
| Too many false positives | Threshold too low | Increase confidence threshold or configure ignore patterns |
| Missing type-only references | Compile-time only usage | Most modern tools handle this; check tool version |
IMPORTANT : Before removing any detected "dead code", spawn parallel subagents to validate findings from multiple perspectives. Dead code may actually be unimplemented features or incomplete integrations.
| Finding Type | True Dead Code | Unimplemented Feature | Incomplete Integration |
|---|---|---|---|
| Unused callable | No callers, no tests, no docs | Has TODO/FIXME, referenced in specs | Partial call chain exists |
| Unused export/public | Not imported anywhere | In public API, documented | Used in sibling module |
| Unused import/include | Typo, refactored away | Needed for side effects | Type-only or compile-time |
| Unused binding | Assigned but never read | Placeholder for future | Debug/instrumentation removed |
After running detection tools, spawn these parallel subagents :
┌─────────────────────────────────────────────────────────────────┐
│ Dead Code Findings │
└─────────────────────────────────────────────────────────────────┘
│
┌───────────────────┼───────────────────┐
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Intent Agent │ │ Integration │ │ History Agent │
│ │ │ Agent │ │ │
│ - Check TODOs │ │ - Trace call │ │ - Git blame │
│ - Search specs │ │ chains │ │ - Commit msgs │
│ - Find issues │ │ - Check exports │ │ - PR context │
│ - Read ADRs │ │ - Test coverage │ │ - Author intent │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
└───────────────────┼───────────────────┘
▼
┌─────────────────────────────────────────────────────────────────┐
│ AskUserQuestion: Confirm Classification │
│ [ ] True dead code - safe to remove │
│ [ ] Unimplemented - create GitHub Issue to track │
│ [ ] Incomplete - investigate integration gaps │
│ [ ] False positive - add to whitelist │
└─────────────────────────────────────────────────────────────────┘
Intent Agent (searches for planned usage):
Search for references to [IDENTIFIER] in:
1. TODO/FIXME/HACK comments in codebase
2. Issue tracker (open and closed issues)
3. Design documents and architecture decision records
4. README and project documentation files
Report: Was this code planned but not yet integrated?
Integration Agent (traces execution paths):
For [IDENTIFIER], analyze:
1. All module import/include/use statements
2. Runtime module loading mechanisms (lazy loading, plugins)
3. Framework-invoked patterns (metadata attributes, config bindings, annotations)
4. Test files that may exercise this code path
Report: Is there a partial or indirect call chain?
History Agent (investigates provenance):
For [IDENTIFIER], check:
1. VCS blame/annotate - who wrote it and when
2. Commit message - what was the stated intent
3. Code review / merge request context - was it part of larger feature
4. Recent commits - was calling code removed or refactored
Report: Was this intentionally orphaned or accidentally broken?
# Step 1: Run detection tool for your language
<tool> <source-path> --confidence-threshold 80 > findings.txt
# Step 2: For each high-confidence finding, spawn validation
# (Claude Code will use Task tool with Explore agents)
Sample finding : unused function 'calculate_metrics' (src/analytics.py:45)
Multi-agent investigation results :
Conclusion : NOT dead code - it's an unimplemented feature. Create tracking issue.
After agent analysis, use AskUserQuestion with multiSelect: true:
AskUserQuestion({
questions: [
{
question: "How should we handle these findings?",
header: "Action",
multiSelect: true,
options: [
{
label: "Remove confirmed dead code",
description: "Delete items verified as truly unused",
},
{
label: "Create issues for unimplemented",
description: "Track planned features in GitHub Issues",
},
{
label: "Investigate incomplete integrations",
description: "Spawn deeper analysis for partial implementations",
},
{
label: "Update whitelist",
description: "Add false positives to tool whitelist",
},
],
},
],
});
| Risk Level | Criteria | Action |
|---|---|---|
| Low | 100% confidence, no references anywhere, >6 months old | Auto-remove with VCS commit |
| Medium | 80-99% confidence, some indirect references | Validate with agents first |
| High | <80% confidence, recent code, has test coverage | Manual review required |
| Critical | Public API surface, documented, has external dependents | NEVER auto-remove |
Weekly Installs
57
Repository
GitHub Stars
22
First Seen
Feb 7, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode56
gemini-cli55
github-copilot55
amp55
codex55
kimi-cli55
Flutter/Dart代码审查最佳实践:提升应用性能与质量的完整检查清单
1,100 周安装