What Is Dead Code?
Dead code is source code that exists in a repository but is never executed, never imported, and never referenced by any active code path. It includes unreachable functions, unused modules, orphaned files, and code behind permanently false conditional branches. Dead code occupies maintenance surface area, confuses developers, and inflates complexity metrics without providing any functional value.
Why It Matters
Dead code is one of the few forms of technical debt that can be safely eliminated with zero functional impact — by definition, removing dead code changes nothing about what the software does. Despite this, dead code accumulates in every long-lived codebase because removing it requires knowing it is dead, and that knowledge is difficult to obtain without systematic analysis.
The cost of dead code is indirect but real. Developers waste time reading, understanding, and maintaining code that does nothing. Search results return dead code alongside live code, creating confusion. Refactoring efforts must account for dead code paths. Build times increase as dead files are compiled. Test coverage metrics are diluted by dead code that is either untested (lowering coverage) or needlessly tested (wasting test execution time).
In large codebases, dead code can represent 10-20% of total lines of code — a significant maintenance burden that can be eliminated safely once identified.
How It Works
Dead code detection works by constructing a complete dependency graph and then identifying nodes (files, functions, classes) with zero in-degree — meaning nothing in the active codebase references them.
File-level dead code detection identifies files that are never imported by any other file and are not entry points (main files, scripts, test files, or configuration files that are invoked externally).
Function-level dead code detection identifies functions that are defined but never called within the reachable code graph. This requires call graph analysis in addition to import graph analysis.
The analysis must account for legitimate zero-in-degree files: entry points, CLI scripts, test files, migration files, and configuration files that are invoked by external systems. These are excluded from dead code findings through entry point detection heuristics and user-configurable exclusion patterns.
How Axiom Refract Addresses This
- Axiom Refract identifies dead files, dead functions, and orphaned database entities through the get_safe_to_remove tool
- Dead code findings include recoverable LOC counts — the number of lines that can be safely deleted
- The migration plan includes dead code removal as a prioritized action item with estimated effort and structural benefit