
dead-code-sweep
This skill should be used when cleaning up codebases that have accumulated dead code, redundant implementations, and orphaned artifacts — especially codebases maintained by coding agents. Triggers on "find dead code", "clean up unused code", "remove redundant code", "prune this codebase", "dead code sweep", "code cleanup", or when a codebase has gone through multiple agent-driven refactors and likely contains overlooked remnants. Systematically identifies cruft, categorizes findings, and removes confirmed dead code with user approval.
- Installs
- 49
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/petekp/claude-code-setup --skill dead-code-sweep- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads dead-code-sweep automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Dead Code Sweep
Systematic identification and removal of dead code, redundant implementations, and orphaned artifacts in codebases — particularly those maintained by coding agents with limited context windows.
Why Agent-Maintained Codebases Accumulate Cruft
Coding agents operate within narrow context windows. When refactoring, they often:
- Re-implement functionality without finding and removing the original
- Leave compatibility shims for interfaces that no longer exist
- Abandon helper functions after inlining their logic
- Create new files without deleting the ones they replace
- Duplicate type definitions across module boundaries
- Leave imports for symbols they stopped using mid-refactor
This cruft compounds. Each orphaned artifact misleads the next agent (or human), who wastes context budget reading code that does nothing.
Workflow
Phase 1: Scope and Inventory
Determine the analysis boundary.
If the user provides a scope (directory, file pattern, module), constrain all analysis to that scope.
If no scope is provided, analyze the full codebase. Start by reading the project structure:
- Identify the primary language(s) and framework(s)
- Map entry points (main files, route definitions, exported modules, test runners)
- Note the build system and dependency configuration
- Check for monorepo structure — analyze each package as a unit
Produce a brief inventory:
Language(s): TypeScript, Python
Entry points: src/index.ts, src/cli.ts
Build: esbuild via package.json scripts
Packages: 1 (single package)
Estimated LOC: ~4,200
Phase 2: Detection
Launch parallel sub-agents to scan for different categories of dead code. Read references/cruft-patterns.md for the full catalog of detection patterns.
Organize detection into these parallel tracks:
| Track | What It Finds |
|---|---|
| Orphaned files | Files not imported, required, or referenced by any other file |
| Unused exports | Exported symbols (functions, classes, types, constants) never imported elsewhere |
| Redundant implementations | Multiple functions/classes doing the same thing under different names |
| Stale compatibility code | Shims, adapters, wrappers, and re-exports that bridge interfaces that no longer differ |
| Dead branches | Conditional paths that can never execute (always-true/false guards, unreachable returns) |
| Orphaned tests | Test files testing functions or modules that no longer exist |
| Orphaned dependencies | Packages in dependency manifests not imported anywhere in source |
For each track, the sub-agent should:
- Read
references/cruft-patterns.mdfor detection strategies specific to that track - Search the codebase using Grep and Glob
- Verify each candidate by tracing references — a symbol is only dead if zero live code paths reach it
3b. Search CI scripts and shell test fixtures for path references to the
candidate:
rg <filename> -- scripts/ tests/ .github/. Files consumed as ratchet-check arguments or Bats test fixtures are NOT dead even if zero source files import them. - Record findings with file path, line range, and evidence
Verification is critical. Common false positives to watch for:
- Symbols used via dynamic dispatch, reflection, or string-based lookups
- Framework-magic exports (e.g., Next.js page components, pytest fixtures, Rails conventions)
- Public API surface intended for external consumers
- Conditional imports behind feature flags or environment checks
- Decorator-registered or plugin-registered handlers
- CLI entry points referenced in package.json
binfields - CSS class names referenced in templates or JSX as dynamic strings
- CI scripts and shell test fixtures that reference files by path — e.g.,
check_file_contains "name" "path/to/file"inscripts/ci/, orcat "$PROJECT_ROOT/path/to/file"intests/**/*.bats. These are string arguments, not imports, so import-tracing tools miss them entirely.
When uncertain, mark as "needs review" rather than "confirmed dead."
Phase 3: Report
Consolidate all findings into a structured report at .claude/dead-code-report.md.
Organize findings by confidence level, then by category:
# Dead Code Sweep Report
**Scope:** [full codebase | specific path]
**Date:** [date]
**Estimated removable lines:** [count]
## Confirmed Dead (high confidence)
### Orphaned Files
- `src/utils/old-parser.ts` — Not imported anywhere. Superseded by `src/parser/index.ts`.
- ...
### Unused Exports
- `formatDate()` in `src/helpers.ts:42-58` — Exported but zero imports across codebase.
- ...
[...other categories...]
## Needs Review (uncertain)
### Possibly Dynamic
- `handleLegacyEvent()` in `src/events.ts:91` — No static imports, but may be registered dynamically.
- ...
For each finding, include:
- File path and line range
- What it is (function, class, file, type, constant, dependency)
- Why it appears dead (no imports, no references, superseded by X)
- Confidence (confirmed / needs review)
Phase 4: Cleanup with Approval
Present the report summary to the user and ask for approval before removing anything.
Use AskUserQuestion to present findings by category:
Found 12 confirmed dead items and 3 needing review.
Confirmed dead by category:
- 3 orphaned files (~280 lines)
- 5 unused exports (~120 lines)
- 2 redundant implementations (~90 lines)
- 2 orphaned dependencies
Which categories should I clean up?
Options: Remove all confirmed / Select categories / Review each item / Skip cleanup
For each approved category:
- Remove the dead code
- Clean up any imports that referenced the removed code
- Remove empty files left after cleanup
- Remove orphaned dependencies from the manifest
- Run the project's lint/typecheck/build commands to verify nothing broke
If any removal causes a build or type error, immediately revert that specific removal and move the item to "needs review."
After cleanup, update the report with what was removed and what was kept.
Detection Principles
Trace from entry points, not from suspects
Start from known entry points and trace what's reachable, rather than starting from a suspect symbol and trying to prove it's used. The reachability approach has fewer false negatives.
Respect the module boundary
A symbol exported from a package's public API may be consumed by external code not visible in this repository. When analyzing libraries or packages with external consumers, only flag internal (non-public-API) dead code as "confirmed." Flag public API dead code as "needs review."
Look for clusters, not just individuals
Agent-generated cruft tends to cluster. When one dead function is found, examine its neighbors — the agent likely abandoned the entire section during a refactor. A dead file often has sibling dead files created in the same commit.
Use git history as a signal
When available, check when suspect code was last meaningfully modified. Code untouched across several refactor commits is more likely dead. Use git log --follow to trace renames and detect superseded files.
Check CI and test infrastructure, not just source code
Files may have zero source-code references but be consumed by CI scripts (scripts/ci/, .github/workflows/), shell test fixtures (tests/**/*.bats), or verification tooling (.verifier/). These references appear as string arguments to shell functions — invisible to import tracing. Always run rg <filename> -- scripts/ tests/ .github/ before classifying a file as orphaned.
FAQ
What does the dead-code-sweep skill do?
This skill should be used when cleaning up codebases that have accumulated dead code, redundant implementations, and orphaned artifacts — especially codebases maintained by coding agents. Triggers on "find dead code", "clean up unused code", "remove redundant code", "prune this codebase", "dead code sweep", "code cleanup", or when a codebase has gone through multiple agent-driven refactors and likely contains overlooked remnants. Systematically identifies cruft, categorizes findings, and removes confirmed dead code with user approval.
How do I install dead-code-sweep?
Run npx skills add https://github.com/petekp/claude-code-setup --skill dead-code-sweep in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/dead-code-sweep/ (personal) or .claude/skills/dead-code-sweep/ (project).
Which AI agents can use dead-code-sweep?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is dead-code-sweep safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains dead-code-sweep?
It is published by petekp in petekp/claude-code-setup. It has 49 recorded installs.
More from petekp/claude-code-setup
code-comments
petekp/claude-code-setup
Write, review, or remove code comments. Use when adding comments or doc comments, reviewing the comments in a diff, or cleaning up or removing comments.
deep-research
petekp/claude-code-setup
Investigate a question that requires sustained research across sources and produce cited findings. Use for deep research requests; skip ordinary lookups and single-document reviews.
exhaustive-systems-analysis
petekp/claude-code-setup
Open the skill to read its SKILL.md instructions.
typography
petekp/claude-code-setup
Open the skill to read its SKILL.md instructions.
claude-code-audit
petekp/claude-code-setup
Forensic audit of the user's recent Claude Code sessions to surface step-change workflow improvements — not marginal ones. Use when the user asks to "audit my Claude Code sessions", "analyze how I use Claude Code", "find patterns in my usage", "improve my Claude Code workflow", "review my sessions", "find leverage in my setup", or wants to understand where their Claude Code setup is leaking time. Samples dozens of real transcripts, extracts quantitative signal via scripts, uses parallel subagents for deep reads, then synthesizes into a short prioritized report with drafted implementations (new skills, CLAUDE.md rules, hooks, settings diffs) that the user can install directly. Trigger even when the user doesn't say the word "audit" — if they're asking about improving or reviewing their Claude Code habits at scale, use this skill.
literate-guide
petekp/claude-code-setup
Create a narrative guide to a codebase or feature in the style of Knuth's Literate Programming — code and prose interwoven as a single essay, ordered for human understanding rather than compiler needs. Use when the user asks to 'explain this codebase as a story', 'write a literate guide', 'create a narrative walkthrough', 'tell the story of this code', 'Knuth-style documentation', 'weave a guide for this feature', or when they want deep, readable documentation that treats the program as literature. Also trigger when someone wants a document that a thoughtful reader could follow from start to finish and come away understanding both WHAT the code does and WHY every design choice was made.
Popular code quality & workflow skills
grill-me
mattpocock/skills
A relentless interview to sharpen a plan or design.
improve-codebase-architecture
mattpocock/skills
Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
handoff
mattpocock/skills
Compact the current conversation into a handoff document for another agent to pick up.
domain-modeling
mattpocock/skills
Build and sharpen a project's domain model. Use when discussing codebase terminology, writing or editing a GLOSSARY.md, or recording or editing an ADR.
codebase-design
mattpocock/skills
Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.
diagnosing-bugs
mattpocock/skills
Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.