dead-code-detector

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

242 stars

Best use case

dead-code-detector is best used when you need a repeatable AI agent workflow instead of a one-off prompt. It is especially useful for teams working in multi. Identify unused code, imports, variables, and functions for safe removal.

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

Users should expect a more consistent workflow output, faster repeated execution, and less time spent rewriting prompts from scratch.

Practical example

Example input

Use the "dead-code-detector" skill to help with this workflow task. Context: Identify unused code, imports, variables, and functions for safe removal.

Example output

A structured workflow result with clearer steps, more consistent formatting, and an output that is easier to reuse in the next run.

When to use this skill

  • Use this skill when you want a reusable workflow rather than writing the same prompt again and again.

When not to use this skill

  • Do not use this when you only need a one-off answer and do not need a reusable workflow.
  • Do not use it if you cannot install or maintain the related files, repository context, or supporting tools.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/dead-code-detector/SKILL.md --create-dirs "https://raw.githubusercontent.com/aiskillstore/marketplace/main/skills/curiouslearner/dead-code-detector/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/dead-code-detector/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How dead-code-detector Compares

Feature / Agentdead-code-detectorStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

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

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# 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
```javascript
// Unused
import { foo, bar } from 'module'; // bar is never used

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

### Unused Variables
```javascript
// Unused
const result = calculate();
const unused = 42; // Never referenced

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

### Unreachable Code
```javascript
function example() {
  return true;
  console.log('Never executes'); // Dead code
}

if (false) {
  // Dead code block
}
```

### Unused Functions
```javascript
// 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

```markdown
# 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
```javascript
// Might look unused but called dynamically
const handlers = {
  onClick: handleClick,
  onHover: handleHover
};

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

### Test Code
```javascript
// Used only in tests, might appear unused in main code
export function testHelper() {}
```

### Public API
```javascript
// 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

Related Skills

seo-cannibalization-detector

242
from aiskillstore/marketplace

Analyzes multiple provided pages to identify keyword overlap and potential cannibalization issues. Suggests differentiation strategies. Use PROACTIVELY when reviewing similar content.

azure-ai-anomalydetector-java

242
from aiskillstore/marketplace

Build anomaly detection applications with Azure AI Anomaly Detector SDK for Java. Use when implementing univariate/multivariate anomaly detection, time-series analysis, or AI-powered monitoring.

pattern-detector

242
from aiskillstore/marketplace

Detect design patterns and anti-patterns in code with recommendations.

dead-code-removal

242
from aiskillstore/marketplace

Detects and safely removes unused code (imports, functions, classes) across multiple languages. Use after refactoring, when removing features, or before production deployment. Includes safety checks and validation.

azure-quotas

242
from aiskillstore/marketplace

Check/manage Azure quotas and usage across providers. For deployment planning, capacity validation, region selection. WHEN: "check quotas", "service limits", "current usage", "request quota increase", "quota exceeded", "validate capacity", "regional availability", "provisioning limits", "vCPU limit", "how many vCPUs available in my subscription".

DevOps & Infrastructure

raindrop-io

242
from aiskillstore/marketplace

Manage Raindrop.io bookmarks with AI assistance. Save and organize bookmarks, search your collection, manage reading lists, and organize research materials. Use when working with bookmarks, web research, reading lists, or when user mentions Raindrop.io.

Data & Research

zlibrary-to-notebooklm

242
from aiskillstore/marketplace

自动从 Z-Library 下载书籍并上传到 Google NotebookLM。支持 PDF/EPUB 格式,自动转换,一键创建知识库。

discover-skills

242
from aiskillstore/marketplace

当你发现当前可用的技能都不够合适(或用户明确要求你寻找技能)时使用。本技能会基于任务目标和约束,给出一份精简的候选技能清单,帮助你选出最适配当前任务的技能。

web-performance-seo

242
from aiskillstore/marketplace

Fix PageSpeed Insights/Lighthouse accessibility "!" errors caused by contrast audit failures (CSS filters, OKLCH/OKLAB, low opacity, gradient text, image backgrounds). Use for accessibility-driven SEO/performance debugging and remediation.

project-to-obsidian

242
from aiskillstore/marketplace

将代码项目转换为 Obsidian 知识库。当用户提到 obsidian、项目文档、知识库、分析项目、转换项目 时激活。 【激活后必须执行】: 1. 先完整阅读本 SKILL.md 文件 2. 理解 AI 写入规则(默认到 00_Inbox/AI/、追加式、统一 Schema) 3. 执行 STEP 0: 使用 AskUserQuestion 询问用户确认 4. 用户确认后才开始 STEP 1 项目扫描 5. 严格按 STEP 0 → 1 → 2 → 3 → 4 顺序执行 【禁止行为】: - 禁止不读 SKILL.md 就开始分析项目 - 禁止跳过 STEP 0 用户确认 - 禁止直接在 30_Resources 创建(先到 00_Inbox/AI/) - 禁止自作主张决定输出位置

obsidian-helper

242
from aiskillstore/marketplace

Obsidian 智能笔记助手。当用户提到 obsidian、日记、笔记、知识库、capture、review 时激活。 【激活后必须执行】: 1. 先完整阅读本 SKILL.md 文件 2. 理解 AI 写入三条硬规矩(00_Inbox/AI/、追加式、白名单字段) 3. 按 STEP 0 → STEP 1 → ... 顺序执行 4. 不要跳过任何步骤,不要自作主张 【禁止行为】: - 禁止不读 SKILL.md 就开始工作 - 禁止跳过用户确认步骤 - 禁止在非 00_Inbox/AI/ 位置创建新笔记(除非用户明确指定)

internationalizing-websites

242
from aiskillstore/marketplace

Adds multi-language support to Next.js websites with proper SEO configuration including hreflang tags, localized sitemaps, and language-specific content. Use when adding new languages, setting up i18n, optimizing for international SEO, or when user mentions localization, translation, multi-language, or specific languages like Japanese, Korean, Chinese.