Code Cleanup Skill
Scan projects for redundant code and generate cleanup reports.
Quick Start
# Scan for dead code (unused imports, functions, variables)
python scripts/scan_dead_code.py backend/
# Scan for stale code (old TODOs, debug statements, commented code)
python scripts/scan_stale_code.py src/
# Check unused dependencies
python scripts/scan_unused_deps.py .
Scripts
| Script |
Detects |
Confidence |
| scan_dead_code.py |
Unused imports, functions, classes, variables |
High |
| scan_stale_code.py |
Commented code, old TODOs, debug statements |
Medium |
| scan_unused_deps.py |
Unused packages in requirements.txt/package.json |
Low |
Usage
scan_dead_code.py
python scripts/scan_dead_code.py <dir> [--format json|text] [--ignore "test_*"]
Detects:
- Unused imports (high confidence, safe to remove)
- Unused functions/classes not starting with
_ (medium confidence)
- Unused top-level variables (medium confidence)
scan_stale_code.py
python scripts/scan_stale_code.py <dir> [--todo-days 90] [--no-debug]
Detects:
- Commented-out code blocks
- TODOs/FIXMEs older than N days (default: 90)
- Debug statements:
print(, console.log(, debugger, pdb
scan_unused_deps.py
python scripts/scan_unused_deps.py <dir> [--type python|node|all]
Checks:
- requirements.txt vs actual imports
- package.json dependencies vs actual imports
Output Format
All scripts output JSON by default:
{
"target": "backend/",
"issues": [
{
"type": "unused_import",
"file": "services/user.py",
"line": 3,
"code": "import os",
"confidence": "high",
"suggestion": "Remove unused import: os"
}
],
"summary": {
"total": 15,
"high": 10,
"medium": 5,
"low": 0
}
}
Confidence Levels
| Level |
Meaning |
Action |
| high |
Definitely unused |
Safe to remove |
| medium |
Likely unused |
Review before removing |
| low |
Possibly unused |
Manual inspection needed |
Cleanup Workflow
- Run scan scripts on target directory
- Review JSON output, filter by confidence
- For each issue: remove, keep, or defer
- Apply changes (Claude can help edit files)
- Run tests to verify nothing broke
Safety Notes
- Scripts are read-only (scan only, no modifications)
- Always backup before bulk cleanup
- Run tests after cleanup
- Some "unused" code may be used dynamically (reflection,
__getattr__, lazy imports)
- Ignore
__init__.py re-exports
References
- Detection patterns:
references/detection-patterns.md
- Cleanup examples:
references/cleanup-examples.md
1---2name: code-cleanup3description: Detect and clean redundant code in Python and TypeScript projects. Finds unused imports, dead functions, stale comments, debug statements, and unused dependencies. Use when asked to "clean code", "find dead code", "remove unused imports", "check redundant code", or "清理代码".4---5
6# Code Cleanup Skill
7
8Scan projects for redundant code and generate cleanup reports.
9
10## Quick Start
11
12```bash
13# Scan for dead code (unused imports, functions, variables)
14python scripts/scan_dead_code.py backend/
15
16# Scan for stale code (old TODOs, debug statements, commented code)
17python scripts/scan_stale_code.py src/
18
19# Check unused dependencies
20python scripts/scan_unused_deps.py .
21```
22
23## Scripts
24
25| Script | Detects | Confidence |
26|--------|---------|------------|
27| scan_dead_code.py | Unused imports, functions, classes, variables | High |
28| scan_stale_code.py | Commented code, old TODOs, debug statements | Medium |
29| scan_unused_deps.py | Unused packages in requirements.txt/package.json | Low |
30
31## Usage
32
33### scan_dead_code.py
34
35```bash
36python scripts/scan_dead_code.py <dir> [--format json|text] [--ignore "test_*"]
37```
38
39Detects:
40- Unused imports (high confidence, safe to remove)
41- Unused functions/classes not starting with `_` (medium confidence)
42- Unused top-level variables (medium confidence)
43
44### scan_stale_code.py
45
46```bash
47python scripts/scan_stale_code.py <dir> [--todo-days 90] [--no-debug]
48```
49
50Detects:
51- Commented-out code blocks
52- TODOs/FIXMEs older than N days (default: 90)
53- Debug statements: `print(`, `console.log(`, `debugger`, `pdb`
54
55### scan_unused_deps.py
56
57```bash
58python scripts/scan_unused_deps.py <dir> [--type python|node|all]
59```
60
61Checks:
62- requirements.txt vs actual imports
63- package.json dependencies vs actual imports
64
65## Output Format
66
67All scripts output JSON by default:
68
69```json
70{
71 "target": "backend/",
72 "issues": [
73 {
74 "type": "unused_import",
75 "file": "services/user.py",
76 "line": 3,
77 "code": "import os",
78 "confidence": "high",
79 "suggestion": "Remove unused import: os"
80 }
81 ],
82 "summary": {
83 "total": 15,
84 "high": 10,
85 "medium": 5,
86 "low": 0
87 }
88}
89```
90
91## Confidence Levels
92
93| Level | Meaning | Action |
94|-------|---------|--------|
95| high | Definitely unused | Safe to remove |
96| medium | Likely unused | Review before removing |
97| low | Possibly unused | Manual inspection needed |
98
99## Cleanup Workflow
100
1011. Run scan scripts on target directory
1022. Review JSON output, filter by confidence
1033. For each issue: remove, keep, or defer
1044. Apply changes (Claude can help edit files)
1055. Run tests to verify nothing broke
106
107## Safety Notes
108
109- Scripts are **read-only** (scan only, no modifications)
110- Always backup before bulk cleanup
111- Run tests after cleanup
112- Some "unused" code may be used dynamically (reflection, `__getattr__`, lazy imports)
113- Ignore `__init__.py` re-exports
114
115## References
116
117- Detection patterns: `references/detection-patterns.md`
118- Cleanup examples: `references/cleanup-examples.md`