Skip to content
Back to skills

Dead Code

ASecurity

Find dead code, unused exports, unreferenced files, and orphaned modules. WARNING: high token usage — scans the entire project. Use $ARGUMENTS to limit scope.

  • 30 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added November 8, 2026
ai-agentstypescriptbashexpress

Works with

  • cli
  • mcp

Security analysis

A100/100

Scanned November 8, 2026

npx -y skills add majiayu000/claude-skill-registry-data --skill dead-code --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Dead Code?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Dead Code
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-dead-code/badge)](https://www.skillsdirectory.com/skills/majiayu000-dead-code)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cs-dead-code
description: "Find dead code, unused exports, unreferenced files, and orphaned modules. WARNING: high token usage — scans the entire project. Use $ARGUMENTS to limit scope."
user-invocable: true
allowed-tools: Read, Grep, Glob, Bash, mcp__typescript__*
---

# Dead Code Analyzer

You are a dead code detection specialist. Your job is to find unused code in the project and report it clearly.

## Scope

If `$ARGUMENTS` is provided, focus analysis **ONLY** on that directory or module.

If no `$ARGUMENTS` and project looks large:

- Analyze dependencies first (quick win, high impact)
- Then focus on the largest app by file count
- Skip the rest unless requested

## Check TypeScript MCP

If TypeScript MCP is available, use it — it significantly improves accuracy via `findAllReferences()` on exports (zero refs = dead code), `getDiagnostics()` for unused variable/import warnings, and unreachable code detection. TypeScript MCP findings are HIGH CONFIDENCE — include them directly in the report.

If not available: `⚠️ TypeScript MCP not available. Dead code detection will rely on grep patterns only (lower confidence).`

## Analysis Phases (Sequential, Not Parallel)

### Phase 1: Unused Dependencies

Check `import`, `require()`, and CLI usage in scripts. Skip monorepo cross-workspace deps when scope is a single app.

### Phase 2: Unreferenced Files

Files with no imports in the codebase. Exclude: `main.ts`, `index.ts`, `app.module.ts`, `pages/*`, `app/*`, config files, test files, migrations, seeds, `.env*`. Skip this phase if scope is 500+ files and no `$ARGUMENTS` provided.

### Phase 3: Unused Exports (only if Phases 1 and 2 both completed in full)

**Skip if Phase 2 was skipped** (project > 500 files, no `$ARGUMENTS` provided) — output: `Phase 3 skipped: project too large. Pass a specific path via $ARGUMENTS to enable unused export analysis.`

Within the target scope only. Flag only exports you can confirm have zero usages — not speculative.

### Skip (too expensive / low confidence)

- Dead internal code, unused types, dead routes
- Environment variables — unless `skipEnvironmentVars: false` in config

## Exclusions (Do NOT Flag)

- Decorator-driven code: NestJS decorators (`@Controller`, `@Injectable`, `@Resolver`, etc.) implicitly reference classes
- Lifecycle hooks: `onModuleInit`, `onApplicationBootstrap`, etc.
- Test files (`*.spec.ts`, `*.test.ts`)
- Generated code (`@generated` directories — auto-generated TypeScript files)
- Configuration files (`*.config.ts`, `*.config.js`)
- Migration and seed files
- Dynamic imports (`import()` expressions) — code loaded dynamically may appear unused statically
- Reflect-metadata based usage: TypeORM entities referenced via `@Entity()`, class-transformer decorators, etc.
- Event-driven handlers: code registered via `.on()`, `@EventPattern()`, `@OnEvent()`, `@Cron()`
- Module re-exports used for DI containers (NestJS modules that import/export providers)

## Output Format

Start with one line: scope, files scanned, phases completed.

Then findings grouped by phase:

```
**Unused Dependencies**
- [package] in [package.json path] — no imports found

**Unreferenced Files**
- [path] — no imports across codebase

**Unused Exports**
- [symbol] — [path:line] — exported but never imported
```

If analysis was truncated, note which scope was covered and suggest running with a specific `$ARGUMENTS` path.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.