Python 死代码检测清理
vulture-dead-code
使用 Vulture 和 deadcode 工具检测未使用的 Python 代码(函数、类、导入)。在清理代码库或移除死代码时使用。触发词:vulture、deadcode。
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 60
- Forks
- 6
01 前言 Front Matter
- name
- vulture-dead-code
- created
- 1765843200000
- modified
- 1778284800000
- reviewed
- 1765843200000
- description
- Vulture and deadcode tools for detecting unused Python code (functions, classes, imports). Use when cleaning up codebases or removing dead code. Triggers vulture, deadcode.
- allowed-tools
- Bash, Read, Grep, Glob
- user-invocable
- false
02 资源文件 5
- 参考文档README.md15.1 KB
- 参考文档REFERENCE.md9.8 KB
- 参考文档references/best-practices.md13.5 KB
- 参考文档references/examples.md15.4 KB
- 参考文档references/patterns.md8.8 KB
03 SKILL.md 正文
Vulture and deadcode - Dead Code Detection
Tools for finding unused Python code including functions, classes, variables, imports, and attributes.
When to Use This Skill
| Use this skill when... | Use another tool instead when... |
|---|---|
| Detecting unused functions, classes, variables | Finding unused imports only (use ruff --select F401) |
| Cleaning up dead code in a codebase | Checking type correctness (use basedpyright) |
| Enforcing code hygiene in CI | Formatting code (use ruff format) |
| Generating whitelists for false positives | Running general linting (use ruff check) |
Overview
Vulture (mature, confidence-based) and deadcode (newer, AST-based) both detect unused code but with different approaches:
| Feature | Vulture | deadcode |
|---|---|---|
| Approach | Static analysis + confidence scores | AST-based detection |
| Accuracy | Confidence scores (60-100%) | High accuracy, fewer false positives |
| Speed | Fast | Very fast |
| Configuration | Whitelist files | TOML configuration |
| Maturity | Mature (2012) | Newer (2023+) |
| Best For | Large codebases, gradual cleanup | New projects, strict enforcement |
Installation
# Install vulture
uv add --dev vulture
# Install deadcode (newer alternative)
uv add --dev deadcode
# Install both for comparison
uv add --dev vulture deadcode
Vulture - Confidence-Based Detection
Basic Usage
# Check entire project
vulture .
# Check specific files/directories
vulture src/ tests/
# Minimum confidence threshold (60-100%)
vulture --min-confidence 80 .
# Exclude patterns
vulture . --exclude "**/migrations/*,**/tests/*"
# Sort by confidence
vulture --sort-by-size .
# Generate whitelist of current issues
vulture . --make-whitelist > vulture_whitelist.py
Configuration (pyproject.toml)
[tool.vulture]
min_confidence = 80
paths = ["src", "tests"]
exclude = [
"**/migrations/*",
"**/__pycache__/*",
".venv/*"
]
ignore_decorators = [
"@app.route",
"@pytest.fixture",
"@property",
"@staticmethod",
"@classmethod"
]
ignore_names = [
"test_*",
"setUp*",
"tearDown*",
]
deadcode - AST-Based Detection
Basic Usage
# Check entire project
deadcode .
# Check specific files/directories
deadcode src/
# Verbose output
deadcode --verbose .
# Dry run (show what would be removed)
deadcode --dry-run .
# Show unreachable code
deadcode --show-unreachable .
# Generate configuration
deadcode --init
Configuration (pyproject.toml)
[tool.deadcode]
paths = ["src"]
exclude = [
"tests/*",
"**/__pycache__/*",
"**/migrations/*",
]
ignore_names = [
"test_*",
"setUp",
"tearDown",
"main",
]
ignore_decorators = [
"app.route",
"pytest.fixture",
"property",
"staticmethod",
"classmethod",
"abstractmethod"
]
show_unreachable = false
Choosing Between Tools
| Choose Vulture when... | Choose deadcode when... |
|---|---|
| Large, mature codebases | New projects |
| Need confidence-based filtering | Want fewer false positives |
| Need whitelist file approach | Prefer TOML configuration |
| Dynamic code (getattr, exec) | Need unreachable code detection |
Hybrid Approach
# Run both for comprehensive detection
vulture --min-confidence 80 .
deadcode .
Agentic Optimizations
| Context | Command |
|---|---|
| Quick vulture check | vulture --min-confidence 90 . |
| Quick deadcode check | deadcode . |
| Generate whitelist | vulture . --make-whitelist > vulture_whitelist.py |
| CI enforcement | vulture --min-confidence 80 . vulture_whitelist.py |
| Unreachable code | deadcode --show-unreachable . |
| Combined check | vulture --min-confidence 80 . && deadcode . |
Quick Reference
Vulture Flags
| Flag | Description |
|---|---|
--min-confidence N |
Minimum confidence (60-100%) |
--exclude PATTERN |
Exclude glob patterns |
--sort-by-size |
Sort results by size |
--make-whitelist |
Generate whitelist file |
deadcode Flags
| Flag | Description |
|---|---|
--verbose |
Verbose output |
--dry-run |
Show without modifying |
--show-unreachable |
Detect unreachable code |
--init |
Generate configuration |
--strict |
Strict enforcement mode |
For detailed examples, advanced patterns, and best practices, see REFERENCE.md.
04 同仓库更多 Skills
session-workflow-capture
Workflow-tool scripts and workflow friction from this session, filed as issues here or in the plugins repo. Use when a session ran Workflow scripts.
kitty-show-image
Show the user an image with a note on what to judge, via a file send or a labelled kitty tab. Use when the user must see an image, or icat fails with no /dev/tty.
kitty-session-persistence
Snapshot and restore kitty terminal sessions on macOS. Use when surviving WindowServer hangs without losing tabs, configuring snapshots, or restoring after a force-reboot.
kitty-remote-control
Safe kitty remote control from an agent — read panes with kitty @ ls/get-text, notify, and never mutate the live terminal unasked. Use when running inside kitty.
docs-reference-check
Dangling doc-reference gate: flag markdown naming repo paths or relative links that no longer exist. Use when docs cite moved/deleted files, or wiring a doc-drift lint.
YouTube 视频上传与编辑
youtube-upload
通过 Data API v3 将视频上传到 YouTube,并在之后编辑其标题、描述、标签或缩略图。适用于发布 YouTube 视频或修改其标题。