Agent skill
finding-dead-code
Use when reviewing code changes, auditing new features, cleaning up PRs, or user says "find dead code", "find unused code", "check for unnecessary additions", "what can I remove".
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/finding-dead-code
SKILL.md
Finding Dead Code
Invariant Principles
- Dead Until Proven Alive - Every code item assumes dead status. Evidence of live callers required to prove otherwise. No assumptions based on appearance.
- Full-Graph Verification - Search entire codebase for each item. Check transitive callers (caller of caller). Re-scan after removals until fixed-point reached.
- Data Flow Completeness - Track write→read pairs. Setter without getter = write-only dead. Iterator without consumer = dead storage.
- Git Safety First - Check status, offer commit, offer worktree isolation BEFORE any analysis or deletion. Never modify without explicit user approval.
- Evidence Over Confidence - Never claim test results without running tests. Never claim "unused" without grep proof. Paste actual output.
Inputs
| Input | Required | Description |
|---|---|---|
scope |
Yes | Branch changes, uncommitted only, specific files, or full repo |
target_files |
No | Specific files to analyze (if scope is "specific files") |
branch_ref |
No | Branch to compare against (default: merge-base with main) |
Outputs
| Output | Type | Description |
|---|---|---|
dead_code_report |
Inline | Summary table with dead/alive/transitive counts |
grep_evidence |
Inline | Concrete grep output proving each verdict |
implementation_plan |
Inline | Ordered list of safe deletions |
verification_commands |
Inline | Commands to validate after removal |
Reasoning Schema
Detection Patterns
| Pattern | Detection | Verdict |
|---|---|---|
| Asymmetric API | getFoo 0 callers, setFoo 3 callers | getFoo DEAD |
| Convenience Wrapper | foo() only calls bar() + zero callers | foo DEAD |
| Transitive | X called only by Y, Y called by nobody | BOTH DEAD |
| Field + Accessors | field + getter + setter all 0 callers | ALL DEAD |
| Test-Only | all callers in test files | ASK USER |
| Write-Only | setter called, getter never | BOTH DEAD |
| Iterator Orphan | iterator defined, no for consumers |
DEAD |
Anti-Patterns
Response Handling
User responses to questions:
- Research request ("verify", "check") → Run verification, re-ask
- Unknown ("not sure") → Show evidence, recommend action
- Clarification (ends with ?) → Answer, then re-ask original
- Skip ("move on") → Proceed to next item
- Direct answer → Execute
Self-Check
Before completing:
- Checked
git statusbefore any analysis - Offered worktree isolation for destructive operations
- Every "DEAD" verdict has grep output proving zero live callers
- Every "ALIVE" verdict has grep output proving live callers
- Checked transitive callers (caller of caller) for all items
- Re-scanned until fixed-point (no new dead code discovered)
- Obtained explicit user approval before any deletions
- Ran tests after deletions to verify no regressions
If ANY unchecked: STOP and complete missing verification.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?