Skip to content
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
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/mushonnif--dead-code-cleaner/badge.svg)](/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
  1. {
  2. "name": "dead-code-cleaner",
  3. "owner": {
  4. "name": "Mushonnif Ahmad"
  5. },
  6. "plugins": [
  7. {
  8. "name": "dead-code-cleaner",
  9. "source": "./",
  10. "description": "Find and delete commented-out code, leftover debug statements, unused imports and unused functions in any language, keeping explanatory comments."
  11. }
  12. ]
  13. }
README.md · README · 131 lines
  1. # dead-code-cleaner: Claude Code skill to remove dead code, unused imports and debug statements
  2. [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
  3. [![Version](https://img.shields.io/badge/version-1.2.0-green.svg)](.claude-plugin/plugin.json)
  4. [![Claude Code plugin](https://img.shields.io/badge/Claude%20Code-plugin%20%26%20skill-orange.svg)](#install)
  5. [![Python 3.8+](https://img.shields.io/badge/python-3.8%2B-blue.svg)](skills/remove-dead-code/scripts/deadcode.py)
  6. **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.
  7. Website: <https://mushonnif.github.io/dead-code-cleaner/>
  8. ## What it removes
  9. - **Commented-out code**: debugging leftovers, old implementations, and disabled calls are deleted. Comments that *explain* code (docs, examples, license headers, TODOs, linter directives) stay.
  10. - **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.
  11. - **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.
  12. - **Unused functions and classes** (optional): reported, verified against framework entry points, then removed.
  13. 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.
  14. ## Install
  15. ### As a plugin (recommended)
  16. ```text
  17. /plugin marketplace add mushonnif/dead-code-cleaner
  18. /plugin install dead-code-cleaner@dead-code-cleaner
  19. ```
  20. ### As a plain skill
  21. Copy `skills/remove-dead-code/` to `~/.claude/skills/` (all projects) or `<project>/.claude/skills/` (one project, shared via git).
  22. ## Use
  23. 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".
  24. Or invoke it directly. The optional first argument picks what to remove, and the rest are paths:
  25. ```text
  26. /remove-dead-code # everything (commented-out + debug + imports), whole repo
  27. /remove-dead-code comments src/ # commented-out code only
  28. /remove-dead-code debug app/ lib/ # debug statements only
  29. /remove-dead-code imports src/ # unused imports only
  30. /remove-dead-code all # all three, explicitly
  31. ```
  32. When installed as a plugin, the command is namespaced: `/dead-code-cleaner:remove-dead-code debug src/`.
  33. Claude then:
  34. 1. checks that the target has no uncommitted changes, so the cleanup is its own diff
  35. 2. scans and triages: removes high-confidence findings and inspects medium ones in batches
  36. 3. removes the approved ranges (the script refuses any range containing live code)
  37. 4. optionally finds unused symbols, preferring native analyzers (vulture, knip, phpstan, staticcheck, …)
  38. 5. runs the project's lint and tests, then reports what was removed and what was kept
  39. ## Scanner CLI
  40. The scanner also works on its own, without Claude:
  41. ```text
  42. deadcode.py scan [PATH...] [--kind comments|debug|imports|all] [--summary] [--level high|medium] [--json] [--exclude GLOB]
  43. deadcode.py show FILE:START-END ... [-C N]
  44. deadcode.py remove FILE:START-END ... | --from FILE | --level high [--kind K] [PATH...] [--dry-run]
  45. deadcode.py unused [PATH...] [--root DIR] [--private-only]
  46. deadcode.py langs
  47. ```
  48. Example output:
  49. ```text
  50. app/models/User.php
  51. 42-47 H 6L // $this->db->where('id', $id);
  52. 88 M^ 1L // return $cache;
  53. # 312 files, 57 findings (41 H, 16 M), 230 lines
  54. ```
  55. `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`).
  56. ### How it stays safe
  57. - 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.
  58. - Files it cannot parse unambiguously are skipped and listed, never touched.
  59. - `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.
  60. - 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.
  61. - Docblocks (`/** */`, `///`, `#!`), license headers, TODO/FIXME notes, linter and type-checker directives, and PHP `#[attributes]` are always kept.
  62. - `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.
  63. - To keep a specific block, add `dead-code: keep` to it.
  64. ### Supported languages
  65. 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.
  66. To add a language, add one `Lang(...)` entry (comment markers, string delimiters) and its extensions in `deadcode.py`.
  67. ## FAQ
  68. ### How do I remove all `console.log` statements from a project?
  69. 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.
  70. ### How do I find and remove unused imports in Python, JavaScript/TypeScript, PHP or Java?
  71. 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`.
  72. ### How do I delete commented-out code but keep real comments?
  73. 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.
  74. ### How do I remove `var_dump`, `dd()` and `print_r` from a PHP or Laravel project?
  75. Run `/remove-dead-code debug app/`. Laravel Blade templates are supported too.
  76. ### Does it work without Claude?
  77. Yes. `skills/remove-dead-code/scripts/deadcode.py` is a standalone Python 3.8+ script with no dependencies. See [Scanner CLI](#scanner-cli).
  78. ### Is it safe to run on a large codebase?
  79. 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.
  80. ## Development
  81. ```bash
  82. python3 -m unittest discover -s tests
  83. ```
  84. ## License
  85. MIT

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.