Back to search
dead-code-cleaner
MarketplaceWorks with Claude CodeGitHub
Claude Code skill & plugin to remove dead code: commented-out code, console.log/var_dump/print debug statements, unused imports and unused functions in 40+ languages
Safety scan
A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.
Checked today
Badge for your README
Markdown
[](/listings/mushonnif--dead-code-cleaner)HTML
<a href="/listings/mushonnif--dead-code-cleaner"><img src="/api/listings/mushonnif--dead-code-cleaner/badge.svg" alt="findsafeskills safety rating" /></a>Install
Install instructions from the README
As written by the repo's author. findsafeskills has not verified these steps.
As a plugin (recommended)
/plugin marketplace add mushonnif/dead-code-cleaner /plugin install dead-code-cleaner@dead-code-cleaner
As a plain skill
Copy `skills/remove-dead-code/` to `~/.claude/skills/` (all projects) or `<project>/.claude/skills/` (one project, shared via git).
What was scanned
The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.
.claude-plugin/marketplace.json · Manifest · 13 lines
- {
- "name": "dead-code-cleaner",
- "owner": {
- "name": "Mushonnif Ahmad"
- },
- "plugins": [
- {
- "name": "dead-code-cleaner",
- "source": "./",
- "description": "Find and delete commented-out code, leftover debug statements, unused imports and unused functions in any language, keeping explanatory comments."
- }
- ]
- }
README.md · README · 131 lines
- # dead-code-cleaner: Claude Code skill to remove dead code, unused imports and debug statements
- [](LICENSE)
- [](.claude-plugin/plugin.json)
- [](#install)
- [](skills/remove-dead-code/scripts/deadcode.py)
- **dead-code-cleaner** is a Claude Code skill and plugin that removes dead code from any codebase: commented-out code, leftover `console.log` / `var_dump` / `print` / `debugger` statements, unused imports, and unused functions. It works in 40+ languages (JavaScript, TypeScript, PHP, Python, Java, Go, Rust, and more) and keeps the comments that explain your code.
- Website: <https://mushonnif.github.io/dead-code-cleaner/>
- ## What it removes
- - **Commented-out code**: debugging leftovers, old implementations, and disabled calls are deleted. Comments that *explain* code (docs, examples, license headers, TODOs, linter directives) stay.
- - **Debug statements**: `console.log`, `debugger`, `var_dump`/`dd`/`print_r`, `print`/`breakpoint()`, `binding.pry`, `dbg!`, `fmt.Println`, `System.out.println`, `IO.inspect`, … Only standalone statements are removed. A statement whose removal would break code is flagged for a hand fix instead: the body of a braceless `if`, the only statement in a Python block, or the body of a `dd()`-style helper.
- - **Unused imports**: Python `import`/`from … import`, JS/TS `import` and `require`, Vue/Svelte (template usage included), PHP `use`, Java, Kotlin and Groovy. Whole unused statements are removed; a statement with only some unused names is flagged as `partial` for a hand edit. Side-effect imports, `__init__.py` re-exports, and lines marked `# noqa`/`eslint-disable` are left alone.
- - **Unused functions and classes** (optional): reported, verified against framework entry points, then removed.
- A bundled scanner keeps it fast and token-cheap. `scripts/deadcode.py` (Python 3.8+, no dependencies) lexes every file once and prints one line per finding, so Claude reviews a whole repository without opening files. On a real 3,700-file PHP/JS project, a full scan takes about 2 seconds.
- ## Install
- ### As a plugin (recommended)
- ```text
- /plugin marketplace add mushonnif/dead-code-cleaner
- /plugin install dead-code-cleaner@dead-code-cleaner
- ```
- ### As a plain skill
- Copy `skills/remove-dead-code/` to `~/.claude/skills/` (all projects) or `<project>/.claude/skills/` (one project, shared via git).
- ## Use
- Ask in plain language, for example "remove the dead code in `src/`", "clean up commented-out code", "remove console.log and debug prints", "clean up unused imports", or "find unused functions".
- Or invoke it directly. The optional first argument picks what to remove, and the rest are paths:
- ```text
- /remove-dead-code # everything (commented-out + debug + imports), whole repo
- /remove-dead-code comments src/ # commented-out code only
- /remove-dead-code debug app/ lib/ # debug statements only
- /remove-dead-code imports src/ # unused imports only
- /remove-dead-code all # all three, explicitly
- ```
- When installed as a plugin, the command is namespaced: `/dead-code-cleaner:remove-dead-code debug src/`.
- Claude then:
- 1. checks that the target has no uncommitted changes, so the cleanup is its own diff
- 2. scans and triages: removes high-confidence findings and inspects medium ones in batches
- 3. removes the approved ranges (the script refuses any range containing live code)
- 4. optionally finds unused symbols, preferring native analyzers (vulture, knip, phpstan, staticcheck, …)
- 5. runs the project's lint and tests, then reports what was removed and what was kept
- ## Scanner CLI
- The scanner also works on its own, without Claude:
- ```text
- deadcode.py scan [PATH...] [--kind comments|debug|imports|all] [--summary] [--level high|medium] [--json] [--exclude GLOB]
- deadcode.py show FILE:START-END ... [-C N]
- deadcode.py remove FILE:START-END ... | --from FILE | --level high [--kind K] [PATH...] [--dry-run]
- deadcode.py unused [PATH...] [--root DIR] [--private-only]
- deadcode.py langs
- ```
- Example output:
- ```text
- app/models/User.php
- 42-47 H 6L // $this->db->where('id', $id);
- 88 M^ 1L // return $cache;
- # 312 files, 57 findings (41 H, 16 M), 230 lines
- ```
- `H`/`M` is the confidence level. `^` means the comment line above is prose (often a label for the dead code). `!reason` marks a debug statement that is unsafe to delete on its own (`braceless-body`, `only-statement`, `inside-expression`, `debug-helper`), or an import with only some names unused (`partial`).
- ### How it stays safe
- - A real lexer per language tracks strings, template literals, triple-quoted strings, heredocs, and block comments. Text inside strings is never treated as a comment.
- - Files it cannot parse unambiguously are skipped and listed, never touched.
- - `remove` re-parses each file and accepts only ranges made entirely of comment-only lines, whole block comments, whole standalone debug statements in a safe context, or whole import statements whose every name is unused.
- - Real logging (`console.error`, loggers) and user-facing `alert()` are not treated as debug code. `print`-style calls and `die`/`exit` lines are only ever medium confidence.
- - Docblocks (`/** */`, `///`, `#!`), license headers, TODO/FIXME notes, linter and type-checker directives, and PHP `#[attributes]` are always kept.
- - `vendor/`, `node_modules/`, `dist/`, `build/`, minified, and generated files are excluded by default (`--no-default-excludes` turns this off). In git repos, `.gitignore` is respected.
- - To keep a specific block, add `dead-code: keep` to it.
- ### Supported languages
- C/C++/Obj-C, C#, Java, Kotlin, Scala, Groovy, Go, Rust, Swift, Dart, Zig, JavaScript/TypeScript, Vue/Svelte/Astro, PHP (incl. Blade), Python, Ruby, Perl, Shell, PowerShell, Lua, SQL, Haskell/Elm, Elixir, Erlang, Julia, Lisp/Clojure, R, VB, Ada/VHDL, assembly, HTML/XML, CSS/SCSS/Less, Twig/Jinja, Handlebars, ERB, YAML/TOML/HCL/Terraform, Dockerfile, Makefile. Run `deadcode.py langs` for the extension list.
- To add a language, add one `Lang(...)` entry (comment markers, string delimiters) and its extensions in `deadcode.py`.
- ## FAQ
- ### How do I remove all `console.log` statements from a project?
- Install the plugin, then run `/remove-dead-code debug src/` (or ask "remove console.log and debug prints"). Standalone `console.log`, `console.debug` and `debugger` lines are removed. `console.error` and real loggers are kept. A call whose removal would break code, such as the body of a braceless `if`, is flagged for a hand fix.
- ### How do I find and remove unused imports in Python, JavaScript/TypeScript, PHP or Java?
- Run `/remove-dead-code imports src/`, or use the scanner on its own: `deadcode.py scan src/ --kind imports`. Whole unused statements are removed. Statements with only some unused names are reported as `partial`.
- ### How do I delete commented-out code but keep real comments?
- Run `/remove-dead-code comments`. The scanner tells code-shaped comments apart from prose, so docblocks, license headers, TODO/FIXME notes and linter directives are kept.
- ### How do I remove `var_dump`, `dd()` and `print_r` from a PHP or Laravel project?
- Run `/remove-dead-code debug app/`. Laravel Blade templates are supported too.
- ### Does it work without Claude?
- Yes. `skills/remove-dead-code/scripts/deadcode.py` is a standalone Python 3.8+ script with no dependencies. See [Scanner CLI](#scanner-cli).
- ### Is it safe to run on a large codebase?
- The `remove` command re-parses every file and refuses any range that contains live code. Files it cannot parse are skipped. Claude also checks for uncommitted changes first, so the whole cleanup lands as one reviewable git diff.
- ## Development
- ```bash
- python3 -m unittest discover -s tests
- ```
- ## License
- MIT
Ratings and comments
Sign in to rate this skill.
Sign inFree to use. If it’s helped, pass it on.