Dead Code Detector

VerifiedSafe

Identify unused code, imports, variables, and functions for safe removal.

Sby Skills Guide Bot
DevelopmentIntermediate
7/27/2026
Claude CodeCursorWindsurfCodex
#dead-code#static-analysis#refactoring#code-quality#dependencies

Recommended for

Automated summary

This skill guides the agent through detecting dead code — unused imports, variables, functions, exports, unreachable paths and dependencies — and producing a risk-tiered report before anything is removed.

Strengths

  • Broad coverage: imports, variables, functions, unreachable code, CSS, type definitions and npm dependencies
  • Sorts findings into three actionable buckets (safe to remove, potentially unused, review required), which curbs risky deletions
  • Flags classic traps such as public exports and string-based dynamic calls
  • Ships a quantified report format (lines saved, bundle size, packages dropped) that can be handed straight to a team

Limitations

  • The skill only produces a report: no automated deletion or fixing is described
  • Detection relies on the agent's static reading, so dynamic usage, reflection and external consumers remain blind spots
  • No concrete tooling (ts-prune, knip, ESLint) is mandated, so result quality depends on the model and the context provided
When to use it

Use it during a cleanup or refactoring pass, or ahead of a dependency review, to get a prioritized inventory of potentially dead code.

When not to use it

Avoid it on a codebase whose exports are consumed by external projects or are heavily dynamic, since the report would be dominated by false positives.

Security analysis

Safe
Quality score82/100

The skill is purely instructional and focuses on static analysis of dead code. It declares no tools and contains no commands that execute code, modify files, access networks, exfiltrate data, or disable safety mechanisms.

No concerns found

How this analysis is made

Examples

Audit a source folder
@dead-code-detector src/ — scan this folder and give me a full report of unused imports, variables, functions and unreachable code, grouped by safe-to-remove vs needs-review.
Safe cleanup only
@dead-code-detector --safe-only src/services/ — I only want items you are certain are unused. Skip anything exported or possibly referenced dynamically.
Dependency audit
@dead-code-detector --include-tests — also check package.json for installed packages that are never imported, and tell me which dependencies are misclassified between dependencies and devDependencies.

name: dead-code-detector description: Identify unused code, imports, variables, and functions for safe removal.

Dead Code Detector Skill

Identify unused code, imports, variables, and functions for safe removal.

Instructions

You are a dead code detection expert. When invoked:

  1. Scan for Unused Code:

    • Unused imports and dependencies
    • Unreferenced functions and methods
    • Unused variables and parameters
    • Unreachable code paths
    • Commented-out code blocks
    • Deprecated functions still in codebase
    • Unused CSS classes and styles
    • Unused type definitions
  2. Analyze Dependencies:

    • Installed packages not imported anywhere
    • Dev dependencies used in production
    • Production dependencies only used in dev/test
    • Circular dependencies
  3. Check Code Reachability:

    • Functions never called
    • Code after return statements
    • Impossible conditional branches
    • Unused exports in modules
  4. Generate Report: Categorize findings:

    • Safe to Remove: Definitely unused
    • Potentially Unused: Might be used dynamically or in tests
    • Review Required: Exported but not used internally (might be used externally)

Detection Categories

Unused Imports

// Unused
import { foo, bar } from 'module'; // bar is never used

// Recommended
import { foo } from 'module';

Unused Variables

// Unused
const result = calculate();
const unused = 42; // Never referenced

// Dead assignment
let value = 10;
value = 20; // First assignment is dead

Unreachable Code

function example() {
  return true;
  console.log('Never executes'); // Dead code
}

if (false) {
  // Dead code block
}

Unused Functions

// Private function never called
function helperFunction() {
  // ...
}

// Exported but not used anywhere
export function unusedExport() {
  // ...
}

Usage Examples

@dead-code-detector
@dead-code-detector src/
@dead-code-detector --include-tests
@dead-code-detector --aggressive
@dead-code-detector --safe-only

Report Format

# Dead Code Detection Report

## Summary
- Total unused items: 47
- Safe to remove: 32
- Needs review: 15
- Potential savings: ~1,200 lines

## Safe to Remove (32)

### Unused Imports (12)
- src/utils/helpers.js:3
  `import { oldFunction } from './legacy'`

- src/components/Button.jsx:5
  `import { validateProps } from './validation'`

### Unused Variables (8)
- src/services/api.js:23
  `const DEBUG_MODE = false` (never referenced)

### Unreachable Code (5)
- src/handlers/payment.js:67
  Code after return statement (lines 68-72)

### Unused Functions (7)
- src/utils/format.js:45
  `function formatOldDate()` (never called)

## Needs Review (15)

### Exported but Not Used Internally (10)
- src/api/client.js:89
  `export function legacyRequest()`
  ⚠ Public export, might be used by consumers

### Potentially Dynamic Usage (5)
- src/plugins/loader.js:34
  `function loadPlugin()`
  ⚠ Might be called dynamically via string reference

## Dependencies

### Unused npm Packages (5)
- `moment` (use date-fns instead)
- `lodash.debounce` (using native debounce now)
- `axios` (switched to fetch)

### Misclassified Dependencies (2)
- `typescript` in dependencies (should be devDependency)
- `jest` in devDependencies but used in production scripts

## Commented Code (8 blocks)

- src/legacy/auth.js:120-145 (25 lines commented)
- src/components/Modal.jsx:67-82 (15 lines commented)

## Recommendations

1. **Immediate Actions**:
   - Remove 32 safe-to-remove items
   - Delete commented code blocks
   - Uninstall 5 unused packages

2. **Review Required**:
   - Check 10 exported functions with consumers
   - Verify 5 potentially dynamic references

3. **Estimated Impact**:
   - Bundle size reduction: ~45KB
   - Code reduction: ~1,200 lines
   - Dependency reduction: 5 packages

Detection Strategies

Static Analysis

  • Parse AST to find declarations and references
  • Track imports and their usage
  • Identify exported but unused symbols

Coverage-Based

  • Use test coverage to find untested code
  • Identify code never executed in tests
  • Find branches never taken

Type-Based (TypeScript)

  • Find unused type definitions
  • Detect unused interfaces
  • Identify orphaned generics

Edge Cases to Consider

Dynamic References

// Might look unused but called dynamically
const handlers = {
  onClick: handleClick,
  onHover: handleHover
};

// Called via string
window['initApp']();

Test Code

// Used only in tests, might appear unused in main code
export function testHelper() {}

Public API

// Exported for external consumers
export function publicApi() {
  // Not used internally but part of public interface
}

Language-Specific Tools

  • JavaScript/TypeScript: ts-prune, unimported, depcheck, ESLint
  • Python: vulture, autoflake, pycln
  • Java: UCDetector, IntelliJ IDEA inspections
  • Go: unused, deadcode
  • Rust: cargo-udeps, cargo-machete

Best Practices

  • Regular Cleanup: Run detection monthly
  • Pre-Commit Hooks: Catch new dead code early
  • Code Review: Include dead code check in reviews
  • Deprecation: Mark code as deprecated before removal
  • Documentation: Document why code is unused
  • Version Control: Use git to track removed code
  • Public APIs: Be careful with exported functions

Removal Strategy

  1. Start Safe: Remove obvious unused code first
  2. Test After Each: Run tests after each removal
  3. Check Imports: Update import statements
  4. Search Codebase: Grep for string references
  5. Review Exports: Consider semver for public packages
  6. Document: Note why code was removed in commit

Notes

  • Some "unused" code might be used via reflection or dynamic imports
  • Public libraries should be more conservative
  • Check documentation and examples for references
  • Consider deprecation period for public APIs
  • Keep removal commits separate and atomic

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/dead-code-detector-ms2s7czk/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/dead-code-detector-ms2s7czk' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/dead-code-detector-ms2s7czk/download' --output '.skill-downloads/dead-code-detector-ms2s7czk/SKILL.md.part' && mv '.skill-downloads/dead-code-detector-ms2s7czk/SKILL.md.part' '.skill-downloads/dead-code-detector-ms2s7czk/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/dead-code-detector-ms2s7czk/SKILL.md' && test -s '.skill-downloads/dead-code-detector-ms2s7czk/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/dead-code-detector' && cp -R '.skill-downloads/dead-code-detector-ms2s7czk' '.claude/skills/dead-code-detector'

Cursor
test -f '.skill-downloads/dead-code-detector-ms2s7czk/SKILL.md' && test -s '.skill-downloads/dead-code-detector-ms2s7czk/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/dead-code-detector' && cp -R '.skill-downloads/dead-code-detector-ms2s7czk' '.cursor/skills/dead-code-detector'

Codex
test -f '.skill-downloads/dead-code-detector-ms2s7czk/SKILL.md' && test -s '.skill-downloads/dead-code-detector-ms2s7czk/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/dead-code-detector' && cp -R '.skill-downloads/dead-code-detector-ms2s7czk' '.agents/skills/dead-code-detector'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/dead-code-detector-ms2s7czk'

openskills read 'dead-code-detector-ms2s7czk'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/dead-code-detector-ms2s7czk/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills