Dead Code Removal
Find and remove code added in the current branch that is never actually used.
Workflow
- •Get the diff:
git diff master...HEAD --name-onlyto find changed files - •For each changed file, identify newly added exports:
- •Functions, classes, constants, types
- •Controllers, services, SDK functions, API endpoints
- •React components, hooks, utilities
- •Search the codebase for references to each new export
- •Flag exports with zero references (excluding their own definition and re-exports)
- •Remove confirmed dead code or report findings
What to Look For
Backend dead code
- •Controllers with no routes pointing to them
- •Service methods never called by controllers or other services
- •SDK/API client functions never imported in frontend
- •Middleware not registered in any route
- •Database models with no queries
Frontend dead code
- •Components never rendered or imported
- •Hooks never called
- •Utility functions never imported
- •Context providers never used
- •Redux actions/selectors with no dispatch/useSelector calls
Shared dead code
- •Types/interfaces never referenced
- •Constants never imported
- •Exported functions only used internally (should not be exported)
Search Strategy
For each new export ExportName:
- •Grep for import statements:
import.*ExportNameorrequire.*ExportName - •Grep for direct usage:
ExportName(or<ExportNameor.ExportName - •Check barrel files (index.ts) for re-exports
- •Exclude the file where it's defined from results
An export is dead if:
- •Zero imports outside its own file
- •Zero usages outside its own file
- •Not re-exported from a public API barrel
Guidelines
- •Only analyze code added in the current branch (not pre-existing code)
- •Be careful with dynamically referenced code (string-based imports, reflection)
- •Check for indirect usage through barrel files and re-exports
- •When uncertain, report as "potentially unused" rather than auto-deleting
- •Preserve code that's part of a public API even if unused internally
- •Report a summary: number of dead exports found, files affected, bytes removed