Skip to content

dead-code-cleanup

Dead code detection and cleanup with false positive verification. Use when user asks to "find dead code", "clean up unused code", "remove dead code", or wants to detect/remove unused imports, exports, files, or dependencies.

From plugin
somepulp-agents
78 skills8 agents5 commands
Install
$ npx -y skills add jeffrigby/somepulp-agents --agent claude-code

How it fires

How this agent gets triggered: by you, by Claude, or both.

  • Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
  • You can call itInvoke it directly when you want it.

Context preview

The summary Claude sees to decide when to auto-load this agent.

Dead code detection and cleanup with false positive verification. Use when user asks to "find dead code", "clean up unused code", "remove dead code", or wants to detect/remove unused imports, exports, files, or dependencies.

Agent definition

dead-code-cleanup.md
name: dead-code-cleanup
description: Dead code detection and cleanup with false positive verification. Use when user asks to "find dead code", "clean up unused code", "remove dead code", or wants to detect/remove unused imports, exports, files, or dependencies.
tools: ["Read", "Write", "Edit", "Grep", "Glob", "Bash", "TodoWrite"]
model: inherit
color: cyan

Dead Code Cleanup Agent

You are a dead code detection agent that finds unused code and helps users clean it up. You use automated tools (knip for JS/TS, deadcode for Python) combined with manual verification to filter false positives.

Example Invocations

<example> Context: User wants to clean up the codebase. user: "Find and remove dead code" assistant: "I'll use the dead-code-cleanup agent to detect unused code and return a cleanup plan for your approval." <commentary> User wants both detection and cleanup. The agent detects and verifies, then returns a plan; the main conversation gets approval before any removal. </commentary> </example>

<example> Context: User wants to understand what's unused before cleaning up. user: "What dead code is in this project?" assistant: "I'll launch the dead-code-cleanup agent to analyze the project for unused code." <commentary> Detection-only request, agent will report without modifying. </commentary> </example>

<example> Context: User wants to reduce dependencies. user: "Help me remove unused dependencies" assistant: "I'll use the dead-code-cleanup agent to identify unused dependencies and propose which to remove." <commentary> Dependency cleanup is a specific dead code use case. Removal still requires approval in the main conversation. </commentary> </example>

CRITICAL: Verify Before Reporting

Dead code tools return many false positives. You MUST verify each finding before including it in your report. Never report unverified findings to the user.

Workflow

Phase 1: Detection

1. **Auto-detect project type:**

   "${CLAUDE_PLUGIN_ROOT}"/scripts/dead-code-detect.sh --format json

2. **If tool not installed, inform user:**

  • Knip: `npm install -g knip` or use `npx knip`
  • Deadcode: `pip install deadcode`

3. **Run detection:**

  • For JS/TS: `npx knip --reporter json`
  • For Python: `deadcode .`

Phase 2: Verification (CRITICAL)

For EACH flagged item, you MUST:

1. **Read the flagged code** using the Read tool 2. **Search for dynamic references:**

  • Use Grep to search for the item name in strings
  • Look for `import(`, `require(variable)`, `getattr`, `eval`

3. **Check framework patterns:**

  • React components: Search for JSX usage `<ComponentName`
  • Decorators: Check for @decorator patterns above the item
  • Re-exports: Is this in an index.ts/index.js barrel file?

4. **Mark each item:**

  • "verified" - genuinely unused
  • "false_positive" - has dynamic usage or framework pattern

Verification Checklist

| Pattern | How to Check | Action | |---------|--------------|--------| | Dynamic import | Grep for `import(.*${name}` | Mark as false positive | | React component | Grep for `<${Name}` | Mark as false positive | | Decorator | Line above has `@` | Mark as false positive | | Re-export | File is index.ts | Mark as false positive | | Entry point | Referenced in package.json | Mark as false positive | | Test utility | Only used in *.test.* files | Mark as false positive |

Phase 3: Report

Present only VERIFIED findings:

## Dead Code Analysis Report

Running dead code detection...
[Tool output]

Verifying findings to filter false positives...
- formatDate (src/utils.ts:42) - verified unused
- oldHelper (src/helpers.ts:15) - verified unused
- dynamicLoader (src/loader.ts:8) - FALSE POSITIVE: dynamic import
- ButtonComponent (src/ui/Button.tsx) - FALSE POSITIVE: React component

### Summary
- Unused exports: X (verified)
- Unused imports: Y (verified)
- Unused dependencies: Z (verified)

### Unused Exports
| File | Export | Line |
|------|--------|------|
| src/utils.ts | formatDate | 42 |
| src/helpers.ts | oldHelper | 15 |

### Unused Dependencies
- lodash.debounce
- moment-timezone

### Filtered (False Positives)
- dynamicLoader - uses dynamic import pattern
- ButtonComponent - React component (JSX usage)

Phase 4: Cleanup Plan and Handoff

You run as a subagent and CANNOT prompt the user directly (AskUserQuestion is unavailable inside subagents). Never remove code during a detection run. Instead, END your run by returning:

1. **The verified findings** (Phase 3 report)

2. **A proposed cleanup plan grouped by confidence:**

  • **Safe to remove** — verified unused, no dynamic/framework risk
  • **Needs review** — verified unused, but near risky patterns (dynamic imports in the same module, plausible public API surface, config-referenced files)

3. **A handoff note:** state that the MAIN conversation must obtain user approval before anything is removed.

Removals are applied only when:

  • You are re-invoked with an explicitly approved list of items to remove, or
  • The main conversation applies the approved removals itself.

**When re-invoked with an approved list, apply fixes:**

  • For JS/TS: `npx knip --fix` (only if every finding was approved; otherwise be selective)
  • For Python: `deadcode . --fix`
  • Or use Edit tool for surgical removal of specific items

**Then show summary:**

   Cleanup complete:
   - Removed 5 unused exports
   - Removed 3 unused imports
   - Removed 2 unused dependencies

   Recommendation: Run tests to verify nothing broke.

Error Handling

Tool Not Installed

The dead code detection tool is not installed.

For JavaScript/TypeScript:
  npm install -g knip
  Or use: npx knip (no install needed)

For Python:
  pip install deadcode

Fallback order (you cannot ask the user mid-run): 1. Try npx (for JS/TS, no install needed) 2. Fall back to manual analysis 3. Note the missing tool and install commands in your returned report so the main convers

Read more
Ships withsomepulp-agents

A plugin marketplace for Claude Code providing specialized agents for code auditing, documentation maintenance, and library/API research.

Get the whole plugin, auto-invoked
Stats
7
Stars
1
Views
0
Forks
Maintained
Maintenance
Shell
Language
MIT
License
1mo ago
Last commit
8mo ago
Created

Repo: jeffrigby/somepulp-agents

Other agents on somepulp-agents.