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

codebase-pruner

コード全体を調べて、使われていない機能や不要なファイル、古い設定など、もう必要のないコードを安全に削除して、コードを整理し、無駄を省くSkill。

📜 元の英語説明(参考)

Scan an entire codebase to detect and safely remove dead code such as unused functions, orphaned modules, unreferenced exports, stale configs, dead routes, and leftover workflow artifacts. Use when asked to clean up dead code, remove unused code, prune stale files, find orphaned modules, audit codebase bloat, or delete code left behind after a workflow or architecture change.

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

一言でいうと

コード全体を調べて、使われていない機能や不要なファイル、古い設定など、もう必要のないコードを安全に削除して、コードを整理し、無駄を省くSkill。

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

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

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

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

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

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して codebase-pruner.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → codebase-pruner フォルダができる
  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 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Codebase Pruner

デッドコードをリポジトリ内で監査し、削除リスクを見積もり、検証済みの小さなスライスで確信度の高い候補のみを削除します。ファイル名から推測するのではなく、実際のエントリーポイント、設定参照、およびランタイムの配線から推論します。

コア・ルール

  • デッドコードは、エントリーポイント、設定参照、またはランタイムフックからのライブパスがないコードとして扱います。
  • 何かを削除する前に参照をマッピングします。1つの参照を見逃すと、削除が無効になります。
  • まず Audit を優先します。デッドコードのインベントリが安全に行動できるほど明確になった場合にのみ、Execute を使用します。
  • 候補に動的ディスパッチリスク、リフレクションリスク、または外部統合リスクがある場合は、自動的に削除するのではなく、フラグを立てます。
  • 生成されたファイルを削除しないでください。代わりに、ジェネレーターまたは生成された出力フローを更新します。
  • 関係のない機能の作業やリファクタリングと剪定を混在させないでください。
  • 各スライスの後に検証を行い、狭く、可逆的なスライスを優先します。

ステップ 0: アクティブなエージェントとドキュメントフォルダの検出

レポートまたは編集を行う前に、どのエージェントが実行されているかを検出します。

if .codex/ exists    → agent = codex,     doc folder = .codex/memory/
if .claude/ exists   → agent = claude,    doc folder = .claude/memory/
if .cursor/ exists   → agent = cursor,    doc folder = .cursor/memory/
if .windsurf/ exists → agent = windsurf,  doc folder = .windsurf/memory/
if none found        → doc folder = repo root

自動削除されない候補にフラグを立てる場合は、<agent-folder>/memory/safe-refactor-code.md にメモを書き込み、将来のエージェントが同じ不確実な候補を最初から再発見しないようにします。

リポジトリルートの AGENTS.md は、重要なデッドコードが見つかったり削除されたりすると、常に更新されます。

モード

Audit

スキャンとレポートのみを行います。確信度と爆発半径で優先順位付けされたデッドコードインベントリを作成します。これがデフォルトモードです。

Dry-Run

順序付けられたスライス、ロールバックポイント、および検証コマンドを含む削除計画を作成します。ファイルを編集しないでください。

Execute

各スライスの後に検証を行い、確信度の高い候補をスライスごとに削除します。失敗したら停止します。

Targeted

同じワークフローを実行しますが、ファイル、ディレクトリ、モジュール、またはサブシステムにスコープされます。

ワークフロー

1. 必要な場合にのみスコープを明確にする

スコープが実質的に曖昧な場合にのみ質問します。それ以外の場合は、ローカルで回答を見つけます。

これらの質問が重要な場合は、解決してください。

  • リポジトリ全体またはターゲット領域
  • 意図的に未使用の互換性コードが存在するかどうか
  • テスト、フィクスチャ、生成されたファイル、およびビルドアーティファクトがスコープ内にあるかどうか
  • CI、Docker、cron、および env 配線などの構成ファイルがスコープ内にあるかどうか

ファイルが構成で指定されている場合は、そうでないことが証明されるまで、それをライブ参照として扱います。

2. 最初にライブエントリーポイントをマッピングする

デッドコードのスキャンを開始する前に、ルートのリストを作成します。

これらのエントリーポイントクラスを確認してください。

  • mainserverindex、または CLI エントリスクリプトなどのアプリケーションエントリファイル
  • ルート、ミドルウェア、プラグイン、およびフックなどのフレームワークロードファイル
  • package.json スクリプト、パッケージエクスポート、および bin エントリ
  • テストのみのコードが関連する場合のテストランナーエントリファイル
  • Dockerfile、compose ファイル、CI ワークフロー、cron ジョブ、リバースプロキシ、およびデプロイスクリプトからの構成駆動型エントリーポイント

ファイルが構成で名前が付けられている場合は、そうでないことが証明されるまで、それをライブ参照として扱います。

3. 参照グラフを構築する

すべてのエントリーポイントから、インポート、require、include、再エクスポート、および構成参照をトラバースします。

候補ごとに、次のように分類します。

  • Live: エントリーポイントまたは構成参照から到達可能
  • Dead (confirmed): ライブパスがなく、意味のある動的参照リスクもありません
  • Dead (suspected): 静的パスが見つかりませんが、動的または外部参照リスクが存在します
  • Excluded: 生成されたファイル、ベンダーの依存関係、ビルド出力、またはその他のスコープ外のマテリアル

文字列で構築されたインポート、イベントレジストリ、リフレクションヘビーなシステム、またはプラグインローダーは、未使用であることを証明できない限り、安全な削除ターゲットとして扱わないでください。

4. 候補タイプを分類する

一般的なカテゴリ:

  • 孤立したモジュール
  • 未使用のエクスポート
  • デッド関数
  • 古いルート
  • レガシーアダプター
  • コメントアウトされたブロック
  • 古い構成
  • 孤立したテスト
  • 放棄されたフィーチャーフラグ
  • デッド env 変数

これは、最も安全なものから最もリスクの高いものへと作業を整理するのに役立ちます。

5. 爆発半径を見積もる

すべての候補について:

  1. 直接参照を検索します。
  2. 再エクスポート、動的名、リフレクション、生成された参照、および構成の言及などの間接参照を検索します。
  3. 影響を受けるファイルまたはシステムをカウントします。
  4. 爆発半径を分類します。
    • Zero: 何も参照していません
    • Local: 同じモジュールのみ
    • Cross-module: 複数のサブシステム
    • External: 構成、CI、Docker、または外部コンシューマーによって参照されます

爆発半径がゼロでない場合は、最初に呼び出し元を更新し、更新されたグラフがクリーンになった後にのみ削除します。

6. 確信度をスコアリングする

これらの削除しきい値を使用します。

  • High: 参照なし、動的リスクなし、構成の言及なし
  • Medium: 静的参照はありませんが、動的パターンが近くに存在します
  • Low: 文字列の言及、ドキュメント、または名前の衝突などの弱い証拠のみ

Execute モードでは、High の確信度の候補のみを自動削除します。ユーザーがよりリスクの高いパスを明示的に要求しない限り、Medium および Low にフラグを立てます。

7. スライスを計画する

削除を小さく、順序付けられたスライスとして表現します。各スライスには、以下を含める必要があります。

  • 狭い目標
  • 触れられたファイル
  • 保持された不変条件
  • 検証コマンド
  • ロールバックアクション

推奨される順序:

  1. コメントアウトされたブロック
  2. 既に削除されたモジュールの孤立したテスト
  3. モジュール内の未使用のエクスポート
  4. モジュール内のデッド関数
  5. 孤立したモジュール
  6. 古いルート
  7. レガシーアダプター
  8. 古い構成

複数のリスクのあるカテゴリを1つのスライスに結合しないでください。

8. 削除前のチェックを実行する

スライスを削除する前に、以下を確認します。

  • ワークツリーの状態が理解されている
  • 候補が完全な関連グラフに対してスキャンされた
  • 必要に応じて、生成された参照が更新された
  • 候補がパッケージエクスポート、プラグインレジストリ、デプロイスクリプト、またはランタイム登録パスの一部ではない

ワークツリーがダーティで、削除が危険な場合は、ユーザーがローカルでの実行を明確に希望しない限り、Audit または Dry-Run を優先します。

(原文はここで切り詰められています)

📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Codebase Pruner

Audit a repo for dead code, estimate deletion risk, and remove only high-confidence candidates in small verified slices. Reason from real entrypoints, config references, and runtime wiring instead of guessing from filenames.

Core Rules

  • Treat dead code as code with no live path from any entrypoint, config reference, or runtime hook.
  • Map references before deleting anything. One missed reference invalidates the deletion.
  • Prefer Audit first. Use Execute only after the dead-code inventory is clear enough to act safely.
  • If a candidate has dynamic dispatch risk, reflection risk, or external integration risk, flag it instead of deleting it automatically.
  • Never delete generated files. Update the generator or generated output flow instead.
  • Never mix pruning with unrelated feature work or refactors.
  • Prefer narrow, reversible slices with verification after each slice.

Step 0: Detect Active Agent and Doc Folder

Before reporting or editing, detect which agent is running:

if .codex/ exists    → agent = codex,     doc folder = .codex/memory/
if .claude/ exists   → agent = claude,    doc folder = .claude/memory/
if .cursor/ exists   → agent = cursor,    doc folder = .cursor/memory/
if .windsurf/ exists → agent = windsurf,  doc folder = .windsurf/memory/
if none found        → doc folder = repo root

When flagging candidates that are not auto-deleted, write a note into <agent-folder>/memory/safe-refactor-code.md so future agents do not rediscover the same uncertain candidates from scratch.

AGENTS.md at repo root is always updated when significant dead code is found or removed.

Modes

Audit

Scan and report only. Produce a prioritized dead-code inventory with confidence and blast radius. This is the default mode.

Dry-Run

Produce a deletion plan with ordered slices, rollback points, and verification commands. Do not edit files.

Execute

Delete high-confidence candidates slice by slice with verification after each slice. Stop on failure.

Targeted

Run the same workflow, but scoped to a file, directory, module, or subsystem.

Workflow

1. Clarify Scope Only When Needed

Ask a question only if the scope is materially ambiguous. Otherwise discover the answers locally.

Resolve these questions if they matter:

  • full repo or targeted area
  • whether intentionally-unused compatibility code exists
  • whether tests, fixtures, generated files, and build artifacts are in scope
  • whether config files such as CI, Docker, cron, and env wiring are in scope

2. Map Live Entrypoints First

Build the list of roots before scanning for dead code.

Check these entrypoint classes:

  • application entry files such as main, server, index, or CLI entry scripts
  • framework-loaded files such as routes, middleware, plugins, and hooks
  • package.json scripts, package exports, and bin entries
  • test runner entry files when test-only code is relevant
  • config-driven entrypoints from Dockerfiles, compose files, CI workflows, cron jobs, reverse proxies, and deploy scripts

If a file is named in config, treat that as a live reference until proven otherwise.

3. Build the Reference Graph

Traverse imports, requires, includes, re-exports, and config references from every entrypoint.

For each candidate, classify it as:

  • Live: reachable from an entrypoint or config reference
  • Dead (confirmed): no live path and no meaningful dynamic-reference risk
  • Dead (suspected): no static path found, but dynamic or external-reference risk exists
  • Excluded: generated files, vendored dependencies, build output, or other out-of-scope material

Do not treat string-built imports, event registries, reflection-heavy systems, or plugin loaders as safe deletion targets unless you can prove they are unused.

4. Classify Candidate Type

Common categories:

  • orphaned modules
  • unused exports
  • dead functions
  • stale routes
  • legacy adapters
  • commented-out blocks
  • stale configs
  • orphaned tests
  • abandoned feature flags
  • dead env vars

This helps order the work from safest to riskiest.

5. Estimate Blast Radius

For every candidate:

  1. Search for direct references.
  2. Search for indirect references such as re-exports, dynamic names, reflection, generated references, and config mentions.
  3. Count the affected files or systems.
  4. Classify blast radius:
    • Zero: nothing references it
    • Local: same module only
    • Cross-module: multiple subsystems
    • External: referenced by config, CI, Docker, or outside consumers

When blast radius is not zero, update callers first and delete only after the updated graph is clean.

6. Score Confidence

Use these deletion thresholds:

  • High: zero references, no dynamic risk, no config mentions
  • Medium: zero static references, but dynamic patterns exist nearby
  • Low: only weak evidence such as string mentions, docs, or naming collisions

Only auto-delete High confidence candidates in Execute mode. Flag Medium and Low unless the user explicitly asks for a riskier pass.

7. Plan Slices

Express removals as small, ordered slices. Each slice must include:

  • narrow goal
  • touched files
  • preserved invariant
  • verification command
  • rollback action

Preferred order:

  1. commented-out blocks
  2. orphaned tests for already-deleted modules
  3. unused exports within a module
  4. dead functions within a module
  5. orphaned modules
  6. stale routes
  7. legacy adapters
  8. stale configs

Do not combine multiple risky categories into one slice.

8. Run the Pre-Delete Check

Before deleting a slice, verify:

  • the worktree state is understood
  • the candidate was scanned against the full relevant graph
  • generated references were refreshed if needed
  • the candidate is not part of a package export, plugin registry, deploy script, or runtime registration path

If the worktree is dirty and deletion would be risky, prefer Audit or Dry-Run unless the user clearly wants execution on top of local changes.

9. Execute With Verification

After each slice:

  1. run the narrowest useful verification
  2. fix one clear follow-up issue if the deletion exposed something small
  3. stop if the slice does not stabilize quickly

Prefer checks such as:

  • lint
  • type-check
  • targeted tests
  • focused build or compile probe
  • targeted runtime/manual probe when automation is absent

If verification fails and the issue is not immediately repairable, roll back that slice only and report the blocker.

10. Summarize Clearly

Return:

  • active agent detected and doc folder used
  • files scanned and entrypoints mapped
  • candidates found by category and confidence
  • removals completed
  • flagged candidates not removed and why
  • verification run per slice
  • remaining risks or dynamic-reference uncertainties

Output Shapes

Audit Output

Agent detected: codex → doc folder: .codex/memory/
Entrypoints mapped: 7
Files scanned: 184

Dead code inventory:
[HIGH] Orphaned module: src/adapters/old-client.ts - no live imports or config references
[HIGH] Dead function: src/utils/date.ts:legacyFormatDate - 0 callers
[MEDIUM] Suspected dead: src/handlers/webhook-v1.ts:handleEvent - dynamic dispatch risk
[LOW] Stale env var: OLD_REDIS_URL - not read in scanned files

Total confirmed dead: 2
Total suspected dead: 2
Recommended next step: Dry-Run

Dry-Run Output

Removal plan:
Slice 1 - Remove commented-out blocks in src/utils/date.ts
  Files: src/utils/date.ts
  Invariant: no behavior change
  Verification: npm run lint
  Rollback: restore touched file from VCS or local backup

Slice 2 - Remove orphaned module src/adapters/old-client.ts
  Files: src/adapters/old-client.ts
  Invariant: no live caller exists
  Verification: import scan + npm run lint
  Rollback: restore touched file from VCS or local backup

Flagged for manual review:
  src/handlers/webhook-v1.ts:handleEvent - dynamic dispatch risk
  → noted in .codex/memory/safe-refactor-code.md

Execute Output

Slice 1 complete: removed commented-out blocks in src/utils/date.ts
  Verification: lint passed

Slice 2 complete: removed src/adapters/old-client.ts
  Verification: lint passed, import scan clean

Summary:
  Agent: codex → docs saved to .codex/memory/
  Removed: 1 file, 1 function, 5 commented blocks
  Flagged: 1 candidate (noted in .codex/memory/safe-refactor-code.md)

Hard Rules

  • Never delete a file with unresolved dynamic-reference risk without explicit user approval.
  • Never delete generated files.
  • Never delete a module exposed via package exports or public API without verifying consumer risk.
  • Never delete code named by CI, Docker, cron, deploy scripts, or runtime config without checking those references directly.
  • Never continue past a failing verification.
  • Never assume "unused today" means safe to remove; check runtime wiring and recent intent where relevant.

Escalation

If widespread dead code appears beyond the user's requested area, switch to full-repo Audit mode before deleting more. Always note flagged but unremoved candidates in <agent-folder>/memory/safe-refactor-code.md so future agents do not rediscover the same uncertain candidates from scratch.