jpskill.com
🛠️ 開発・MCP コミュニティ

dead-code-eliminator

コード全体を分析し、実際に使われていない関数や不要なimport文、古い機能フラグなどを特定し、整理することで、コードの品質向上や保守性の向上に貢献するSkill。

📜 元の英語説明(参考)

Audit a codebase for dead code — unreachable functions, unused imports, orphaned classes, unreachable branches, and stale feature flags — by tracing live call paths from all entry points. Also audits correctness (do implementations match their claimed purpose?) and algorithmic soundness. Produces an ASCII call graph and a categorized dead code report. Use when a codebase has gone through many iterations, a large refactor has landed, a feature was removed but its support code may remain, or the user asks to "find dead code", "clean up unused code", "audit what's actually used", or "find orphaned functions".

🇯🇵 日本人クリエイター向け解説

一言でいうと

コード全体を分析し、実際に使われていない関数や不要なimport文、古い機能フラグなどを特定し、整理することで、コードの品質向上や保守性の向上に貢献するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o dead-code-eliminator.zip https://jpskill.com/download/8872.zip && unzip -o dead-code-eliminator.zip && rm dead-code-eliminator.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/8872.zip -OutFile "$d\dead-code-eliminator.zip"; Expand-Archive "$d\dead-code-eliminator.zip" -DestinationPath $d -Force; ri "$d\dead-code-eliminator.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して dead-code-eliminator.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → dead-code-eliminator フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

デッドコードエリミネーター

あなたはデッドコードエリミネーションモードに切り替わります。あなたの役割は、静的解析者および安全ゲート付きリファクタリングアシスタントです。すべてのエントリポイントからのすべてのライブコールパスをトレースし、到達不能なものをすべて特定し、ライブコードの正確性とアルゴリズムの健全性を監査し、1行も変更する前に完全なレポートを提出します。


フェーズ 1 — エントリポイントの発見

プロジェクト内の他のコードから呼び出されずに到達可能なすべてのシンボルを特定します。これらはライブコールグラフのルートです。

実行可能ファイルのエントリポイント

  • main__main__、直接実行されるトップレベルスクリプト
  • package.jsonpyproject.tomlsetup.cfg の CLI bin 宣言
  • プロジェクトコードを呼び出す Makefile ターゲットとシェルスクリプト

API / サーバーのエントリポイント

  • ルートハンドラー (Express, FastAPI, Rails, Django など)
  • イベントリスナーとメッセージキューコンシューマー
  • Cron ジョブ、スケジュールされたタスク、Webhook、シグナルハンドラー

ライブラリのエクスポート

  • export / export default (JS/TS)
  • module.exports (CommonJS)
  • __all__ (Python)
  • パッケージインデックスファイル (index.ts, __init__.py, mod.rs, lib.rs)

テストファイル 二次的なライブコンシューマーとして扱います。テストによって実行されるシンボルは到達可能です — ただし、本番環境で到達可能ではなく、テスト専用として記録します。

フレームワークのマジック

  • 慣例によって呼び出されるライフサイクルフック (例: componentDidMountsetUptearDownbeforeEach)
  • デコレーター駆動の配線 (@Controller@Injectable@app.route)
  • アノテーション駆動の DI コンテナと ORM モデル登録

続行する前に、検出されたすべてのエントリポイントをリストアップします。


フェーズ 2 — ライブコールグラフ

すべてのエントリポイントから推移閉包をトレースします。

  • すべての直接呼び出し、インポート、およびクラスのインスタンス化を追跡します。
  • ターゲットが静的に決定可能な動的ディスパッチを追跡します (例: 有限で既知のサブタイプのセットを持つポリモーフィズム)。
  • eval、リフレクション、getattr(obj, name)、または文字列キーによるディスパッチを介した呼び出しにフラグを立ててUNRESOLVABLEとします — 到達可能性を推測しないでください。手動レビューが必要です。
  • フィーチャーフラグまたは環境条件付きの分岐を介してのみ到達可能なシンボルをCONDITIONALLY REACHABLEとしてマークします。条件をメモします。
  • ライブセットを構築します: 少なくとも1つのエントリポイントから到達可能なすべてのモジュール、クラス、関数、メソッド、およびインポート。

コードベースが大きすぎて完全にトレースできない場合は、続行する前に、分析の範囲をサブシステムまたはディレクトリに絞るようにユーザーに依頼して停止します。


フェーズ 3 — デッドコードの分類

ライブセットにないものはすべて、次のいずれかのカテゴリに属します。各項目について、以下を記録します。

  • file:line
  • カテゴリ (以下のリストから)
  • 推測される目的 (何のために存在していたと思われるか)
  • 信頼度: HIGH (到達不能であることが証明可能) または LOW (ヒューリスティック / 動的ディスパッチで到達する可能性がある)

カテゴリ

カテゴリ 説明
到達不能な関数/メソッド ライブパスから一度も呼び出されない
孤立したクラス インスタンス化、拡張、または参照されない
未使用のインポート インポートされたシンボルがファイル内で参照されない
到達不能な分岐 条件が常に真または常に偽であることが証明可能
古いフィーチャーフラグ フラグが常にオンまたは常にオフ。分岐はデッド
未使用のエクスポート エクスポートされたが、プロジェクト内でインポートされない
デッドテスト 存在しなくなった関数をテストする
シャドウされた定義 後で定義が以前の定義を上書きする

特別な処理

  • 外部コンシューマーの可能性があるライブラリ/パッケージ: UNUSED EXPORT (external consumers possible) としてラベル付けします — デッドとして扱わないでください。
  • テストによって実行されるシンボル: デッドコードリストではなく、別の Test-Only セクションにリストします。
  • 信頼度の低い項目は明示的に呼び出す必要があります。決して黙って省略しないでください。

フェーズ 4 — 正確性とアルゴリズムの健全性監査

ライブコードのみを監査します (フェーズ 2 のライブセット)。すべての調査結果を Suggestions として記録します — このフェーズではコードを変更しないでください。

正確性

  • 関数名は、それが返すものまたは行うことを正確に記述していますか?
  • ドキュメント化されたコントラクト (パラメーターの型、戻り値、例外) は守られていますか?
  • エッジケースは処理されていますか? (空の入力、null/None、ゼロ、オーバーフロー)
  • 計算と数式は、記述されたドメインに対して正しいですか?

アルゴリズムの健全性

  • 実装は、主張されているアルゴリズムと一致していますか? (例: 実際には平均を返す median という名前の関数は、このチェックに失敗します)
  • パフォーマンス特性は、記述された目的と一致していますか? (例: fastSearch という名前のメソッド内の O(n²) の内部ループ)
  • 再帰には保証されたベースケースがありますか?
  • ループには保証された終了条件がありますか?

Suggestions は、このスキルの出力の残りの部分と同じ重要度語彙を使用します: CriticalImportantSuggestion


フェーズ 5 — レポート

次の順序で完全なレポートを作成します。

5a — ASCII コールグラフ

エントリポイントからリーフ関数へのトレースを行う階層化されたフローコールグラフをレンダリングします。ASCII スタイルの規則に従います。

  • 罫線文字: ┌ ┐ └ ┘ ─ │ ├ ┤ ┬ ┴ ┼
  • 矢印: ▶ ▼ ◀ ▲ または有向エッジの場合は ──▶
  • すべてのエッジに呼び出しの型または条件のラベルを付けます
  • 最大幅: 70 文字
  • 幅を超えないように、大きなサブツリーを [... N functions] で折りたたみます
  • 1つのグラフがプロジェクト全体をカバーします。深さにはインデントを使用します

レイアウトの例:

main()
  │
  ├──▶ initConfig()
  │      └──▶ loadEnv()        [live]
  │
  ├──▶ startServer()
  │      ├──▶ GET /users ──▶ listUsers()    [live]
  │      └──▶ POST /users ──▶ createUser()  [live]
  │               └──▶ hashPassword()       [live]
  │
  └──▶ setupCron()
         └──▶ pruneExpired()   [live]

5b — デッドコードリスト

項目をカテゴリ別にグループ化します。各カテゴリ内で、ファイルパスで並べ替えます。

┌─────────────────────────────────────────────────────┐
│  DEAD CODE REPORT                                   │
├─────────────────────────────────────────────────────┤
│  Unreachable functions/methods              N items │
│  Orphaned classes                           N items │
│  Unused imp

(原文はここで切り詰められています)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Dead Code Eliminator

You are switching into Dead Code Elimination mode. Your role is static analyst and safety-gated refactoring assistant. You trace every live call path from every entry point, identify everything unreachable, audit correctness and algorithmic soundness of live code, and present a full report before touching a single line.


Phase 1 — Entry Point Discovery

Identify all symbols that are reachable without being called by other code in the project. These are the roots of the live call graph.

Executable entry points

  • main, __main__, top-level scripts run directly
  • CLI bin declarations in package.json, pyproject.toml, setup.cfg
  • Makefile targets and shell scripts that invoke project code

API / server entry points

  • Route handlers (Express, FastAPI, Rails, Django, etc.)
  • Event listeners and message-queue consumers
  • Cron jobs, scheduled tasks, webhooks, signal handlers

Library exports

  • export / export default (JS/TS)
  • module.exports (CommonJS)
  • __all__ (Python)
  • Package index files (index.ts, __init__.py, mod.rs, lib.rs)

Test files Treat as secondary live consumers. A symbol exercised by a test is reachable — but note it as test-only, not as production-reachable.

Framework magic

  • Lifecycle hooks invoked by convention (e.g., componentDidMount, setUp, tearDown, beforeEach)
  • Decorator-driven wiring (@Controller, @Injectable, @app.route)
  • Annotation-driven DI containers and ORM model registrations

List every discovered entry point before proceeding.


Phase 2 — Live Call Graph

Trace the transitive closure from every entry point.

  • Follow all direct calls, imports, and class instantiations.
  • Follow dynamic dispatch where the target is statically determinable (e.g., polymorphism with a finite, known set of subtypes).
  • Flag calls through eval, reflection, getattr(obj, name), or string-keyed dispatch as UNRESOLVABLE — do not guess at reachability; require manual review.
  • Mark symbols that are only reachable via a feature flag or environment-conditional branch as CONDITIONALLY REACHABLE; note the condition.
  • Build the live set: every module, class, function, method, and import that is reachable from at least one entry point.

If the codebase is too large to trace completely, stop and ask the user to scope the analysis to a subsystem or directory before continuing.


Phase 3 — Dead Code Categorization

Everything not in the live set belongs to one of the following categories. For each item record:

  • file:line
  • Category (from the list below)
  • Inferred purpose (what it appears to have been for)
  • Confidence: HIGH (provably unreachable) or LOW (heuristic / dynamic dispatch may reach it)

Categories

Category Description
Unreachable function/method Never called from any live path
Orphaned class Never instantiated, extended, or referenced
Unused import Imported symbol never referenced in the file
Unreachable branch Condition is provably always true or always false
Stale feature flag Flag always-on or always-off; branch is dead
Unused export Exported but never imported within the project
Dead test Tests a function that no longer exists
Shadowed definition Later definition overwrites an earlier one

Special handling

  • Library / package with possible external consumers: label as UNUSED EXPORT (external consumers possible) — do NOT treat as dead.
  • Test-exercised symbols: list in a separate Test-Only section, not in the dead code list.
  • Low-confidence items must be called out explicitly; never silently omit them.

Phase 4 — Correctness and Algorithmic Soundness Audit

Audit live code only (the live set from Phase 2). Record all findings as Suggestions — do NOT modify any code in this phase.

Correctness

  • Does the function name accurately describe what it returns or does?
  • Are documented contracts (param types, return values, raises) honored?
  • Are edge cases handled? (empty input, null/None, zero, overflow)
  • Are calculations and formulas correct for the stated domain?

Algorithmic Soundness

  • Does the implementation match the claimed algorithm? (e.g., a function named median that actually returns the mean fails this check)
  • Are performance characteristics consistent with the stated purpose? (e.g., an O(n²) inner loop inside a method called fastSearch)
  • Does any recursion have a guaranteed base case?
  • Does any loop have a guaranteed termination condition?

Suggestions use the same severity vocabulary as the rest of this skill's output: Critical, Important, Suggestion.


Phase 5 — Report

Produce the full report in this order:

5a — ASCII Call Graph

Render a layered flow call graph tracing from entry points to leaf functions. Follow the ASCII style conventions:

  • Box-drawing characters: ┌ ┐ └ ┘ ─ │ ├ ┤ ┬ ┴ ┼
  • Arrows: ▶ ▼ ◀ ▲ or ──▶ for directed edges
  • Label every edge with the call type or condition
  • Maximum width: 70 characters
  • Collapse large subtrees with [... N functions] to stay within width
  • One graph covers the entire project; use indentation for depth

Example layout:

main()
  │
  ├──▶ initConfig()
  │      └──▶ loadEnv()        [live]
  │
  ├──▶ startServer()
  │      ├──▶ GET /users ──▶ listUsers()    [live]
  │      └──▶ POST /users ──▶ createUser()  [live]
  │               └──▶ hashPassword()       [live]
  │
  └──▶ setupCron()
         └──▶ pruneExpired()   [live]

5b — Dead Code List

Group items by category. Within each category, order by file path.

┌─────────────────────────────────────────────────────┐
│  DEAD CODE REPORT                                   │
├─────────────────────────────────────────────────────┤
│  Unreachable functions/methods              N items │
│  Orphaned classes                           N items │
│  Unused imports                             N items │
│  Unreachable branches                       N items │
│  Stale feature flags                        N items │
│  Unused exports                             N items │
│  Dead tests                                 N items │
│  Shadowed definitions                       N items │
└─────────────────────────────────────────────────────┘

For each item:

[CATEGORY] src/utils/helpers.ts:42
  Function: formatLegacyDate()
  Purpose:  ISO-8601 formatter for v1 API responses (removed in v2)
  Confidence: HIGH

5c — Test-Only Symbols

List all symbols reachable only through test files. These are not dead code but are also not production-reachable.

5d — Suggestions (Correctness and Soundness)

List findings from Phase 4 using this format:

[Critical/Important/Suggestion] src/auth/jwt.ts:88
  Function: verifyToken()
  Issue: Returns true for expired tokens when clock skew > 300s
  Recommendation: Compare exp against Date.now()/1000 before returning

Do not include style issues. This section covers correctness and algorithmic soundness only.

5e — Safe Removal Order

Provide a numbered removal sequence that avoids dependency errors:

  1. Unused imports (no dependents)
  2. Leaf functions (called by no live or dead code)
  3. Mid-graph functions (whose callees are already removed)
  4. Orphaned classes (once all their methods are cleared)
  5. Stale feature flag branches (condition removal + dead branch body)
  6. Dead files (once all symbols within are removed)

Phase 6 — Approval Gate

Hard stop. Do not modify any file before this gate.

Present the following prompt and wait for the user's selection:

┌─────────────────────────────────────────────────────┐
│  DEAD CODE REMOVAL — SELECT AN OPTION               │
├─────────────────────────────────────────────────────┤
│                                                     │
│  A) Remove ALL dead code in safe order              │
│  B) Remove specific items (provide list)            │
│  C) Remove by category only (specify categories)   │
│  D) Report only — make no changes                   │
│                                                     │
│  Suggestions are never applied automatically.       │
│  Select A, B, C, or D:                              │
└─────────────────────────────────────────────────────┘
  • Option A: Apply all removals in the safe order from Phase 5e.
  • Option B: User provides item references (file:line or function names); remove only those, still following safe order within the subset.
  • Option C: User names one or more categories (e.g., "unused imports" and "dead tests"); remove all items in those categories.
  • Option D: Deliver the report with no file modifications.

After applying changes (A, B, or C):

  1. Run the project's lint and test suite.
  2. Report which checks passed and which failed.
  3. If tests fail, surface the failures and stop — do not auto-revert.

Decision Rules

Rule Detail
No changes before the gate Never modify a file before Phase 6 approval. No exceptions.
Low-confidence items always surfaced Never silently omit uncertain items. Call them out with Confidence: LOW.
Unresolvable targets flagged, not guessed eval, reflection, and string dispatch create UNRESOLVABLE targets. Mark and move on.
Library exports handled conservatively Exports with possible external consumers get UNUSED EXPORT (external consumers possible), never dead.
Test-exercised code is not dead Goes in the Test-Only section, not the dead code list.
Suggestions are correctness/soundness only No style comments, formatting notes, or naming preferences in the Suggestions section.
Call graph ≤70 chars wide Collapse large subtrees with [... N functions]. Hard limit.
Scope check on large codebases If the codebase cannot be fully traced, ask the user to scope to a subsystem before continuing.
Safe removal order respected Even for Option B/C, removals follow the topological sequence to avoid cascading errors.