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".

Stars 163
Forks 31

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

  1. Dead Until Proven Alive - Every code item assumes dead status. Evidence of live callers required to prove otherwise. No assumptions based on appearance.
  2. Full-Graph Verification - Search entire codebase for each item. Check transitive callers (caller of caller). Re-scan after removals until fixed-point reached.
  3. Data Flow Completeness - Track write→read pairs. Setter without getter = write-only dead. Iterator without consumer = dead storage.
  4. Git Safety First - Check status, offer commit, offer worktree isolation BEFORE any analysis or deletion. Never modify without explicit user approval.
  5. 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 status before 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.

Expand your agent's capabilities with these related and highly-rated skills.

Didn't find tool you were looking for?

Be as detailed as possible for better results