agentsclimarketplace

Detecting dead code

Skill quangphu1912/codebase-analyzer/skills/detecting-dead-code

Use when reducing codebase size, cleaning up before refactoring, investigating slow builds, or auditing for unused code and orphaned filesFrom its SKILL.md

Install
npx -y skills add quangphu1912/codebase-analyzer --skill detecting-dead-code

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

4.0 KB, as published. Nobody here has run it

Announce at start: "Using codebase-analyzer to detect dead code."

Overview

Find code that is unreachable, unused, or orphaned. Classify findings by removal safety.

Process

  1. Find unused exports: symbols exported but never imported elsewhere
  2. Find unreachable code: after return/throw, behind false conditions
  3. Find orphaned files: files not imported/required by anything
  4. Find dead config: config keys no code reads
  5. Find unused dependencies in package manifests
  6. Classify: safe-to-remove, needs-verification, keep-for-compat

Classification

CategoryConfidenceAction
Exported, nothing imports itHIGH safeRemove
Behind false compile conditionHIGH safeRemove
Not imported but may be dynamicMEDIUM verifyCheck dynamic imports
Platform-conditional codeLOW verifyMay be alive in other builds
Public API for external useKEEPDocument if missing

Trigger Signals

  • HIGH confidence: Code dead in THIS build but build flags suggest alive in other configs -> map-feature-gates
  • HIGH confidence: Significant dead code behind feature flags -> analyze-build-pipeline
  • MEDIUM confidence: Dead code that was recently killed -> analyze-agent-loop (check git history)
  • LOW confidence: Standard unused code -> refactoring candidate only

Warning: False Positives

Dynamic imports, reflection, plugin systems, and eval() can make live code appear dead. Always check for these before reporting.

Dead Code Archaeology

Before removing anything, determine why code died. Use git log -p -- <file> to investigate. The story matters more than the fact of death.

PatternMeaningAction
Behind feature flagUpcoming, not dead (not yet released)Keep, check flag status
Recently deletedChanged requirementVerify removal was intentional
Commented outBroken migration, someone couldn't finishCheck linked tickets/PRs
Conditionally excludedConfiguration-dependentMay be alive in other builds

For detailed git archaeology commands, see _shared/references/git-archaeology-techniques.md.

Zombie Code Detection

Code that appears dead but is loaded via reflection, plugin systems, or string-based dynamic imports. Static analysis will miss it. Search for these patterns:

  • require(variable), import(variable) -- dynamic loading paths
  • Reflect.get, plugin registries loading modules by name or path
  • Framework auto-discovery patterns (Spring @ComponentScan, Python entry_points, JS require.context)

If code is loaded dynamically through any of these mechanisms, it is alive regardless of what static import analysis says. Always verify against runtime loading before flagging as dead.

Security Signals

Dead code removal can silently strip security controls:

  • Dead auth checks = removed security (was it intentional?)
  • Dead data validation = intentional bypass or forgotten migration
  • Dead logging = hidden audit gap (compliance impact)

When dead code involves authentication, authorization, validation, or logging, escalate before removing. Verify against security requirements and compliance obligations.

Adversarial Lens

Dead code is the best hiding spot. If someone wanted to keep malicious code around, they'd make it LOOK dead (unused import, behind a feature flag that's always off, in a test file that never runs). Check: is this code really dead, or is it waiting to be activated?

Red Flags

  • Reporting code as dead without checking dynamic imports
  • Not checking reflection/eval patterns
  • Ignoring platform-specific code paths

Output Contract

Write docs/analysis/dead-code.md using standard contract. Include: unused exports list, orphaned files, classification breakdown, removal recommendations.

Keep looking

Skills are one crate of 627,801. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.