codebase-refactoring
できること
このスキルは、プロジェクト全体の整理の計画を案内します。繰り返されるコード、使われていないコード、複雑すぎるファイルを扱います。保守の作業を減らしたい開発者向けです。
使う場面
- ✓チームが、プロジェクトの整理や技術的負債の返済を求めているとき。
- ✓開発者が、コードベースのどの部分に最初に最も手を入れる必要があるかを知りたいとき。
- ✓チームが、整理の前後でプロジェクトの健全性スコアを測りたいとき。
スキルのリンク
https://github.com/kucherenko/jscpd/blob/master/skills/codebase-refactoring/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“このプロジェクトを整理してください。最も大きな問題から始め、その後に健全性スコアを見せてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
このスキルはコード分析ツールを実行して問題を順位づけし、AIが重複、使われていないコード、複雑なファイルを修正するのを案内します。最後にもう一度スコアを測ります。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
codebase-refactoring
A guided pass over a codebase's three biggest maintenance costs — duplicated code, dead code, and complexity — using jscpd to find each and a strategy to fix it. Use this skill when asked to "clean up", "improve", "refactor" or "pay down tech debt in" a codebase, rather than to fix one specific bug.
Start here: measure, then prioritize
npx jscpd --health --reporters ai <path>
health 74 B (duplication 75, dead-code 72, complexity 76; 93 code lines)
The health score is a weighted mix of three sub-scores, each a share of the
code lines — high is good, 100 is clean. The lowest of the three names where
the codebase actually hurts most; if it isn't the order below, do that
dimension first instead. n/a on a dimension (e.g. dead code n/a) means
jscpd could not measure it — dead-code detection needs JavaScript,
TypeScript or Python to be a real share of the code — skip that step rather
than treating it as clean.
For the full picture behind that score — largest duplicated formats, most
complex files, largest dead-code findings, all in one screen — run npx jscpd --dashboard instead. Its console output (the default) is the only
reporter with that per-file detail; --reporters ai on --dashboard prints
the same one-line summary shown above, not the breakdown, so don't reach for
it expecting more than the score. Use --reporters json on --dashboard if
you need the detail in a parseable form.
The three passes below are otherwise independent and safe to run in any order; duplication → dead code → complexity is the default because fixing duplication first means step 2 isn't wasting effort tracing call sites that a later extract-function pass will move anyway, and clearing dead code before step 3 means the files ranked for simplification are ones actually worth simplifying, not ones about to be deleted.
Step 1 — Duplicated code
npx jscpd --reporters ai --summary <path>
Find and read each clone, decide whether it is a real copy worth merging, and apply the matching refactoring strategy (extract function, parameterize, extract a shared module or constant, or a base class/template for structural duplication). Full guided workflow, triage rules for renamed/near-miss clones, and worked examples per clone kind:
→ dry-refactoring — run this now, then
come back here for steps 2 and 3. Its own --summary hotspot ranking is the
same one the health score's duplication dimension reads from, so a file it
flags as a duplication hotspot is the same file that dragged the score down.
Step 2 — Dead code
npx jscpd --dead-code --reporters ai <path>
basta dead code report — 18 findings across 30 files (22.1% of 272 lines)
Confidence is 0-100; anything below 90 has a listed reason it may be wrong. Verify a finding before deleting the code.
unused-file typescript/src/legacy-export.ts:1:1 confidence=95 typescript/src/legacy-export.ts is never imported and is not an entry point
unused-export typescript/src/invoice.ts:21:17 confidence=85 exported function `renderReceipt` is never imported
unused-symbol typescript/src/invoice.ts:29:10 confidence=90 function `describeTotal` is never used in typescript/src/invoice.ts
unused-import typescript/src/invoice.ts:2:10 confidence=100 `roundToCents` is imported but never used
This is a graph traversal from the project's entry points (package.json
main/bin/exports/scripts, pyproject.toml scripts, framework
conventions, or --entry <glob>), not a reference count — a helper whose
only caller is itself dead is reported too, so deleting one finding can make
another true that wasn't reported yet. Covers JavaScript, TypeScript, JSX,
TSX, Vue, Svelte, Astro and Python.
The four categories, and what to do with each
| Category | Meaning | Usual fix |
|---|---|---|
unused-file |
Never imported anywhere, not an entry point | Delete the file |
unused-export |
Exported, but no other file imports it | Delete it, or drop the export keyword if something in the same file still uses it |
unused-symbol |
A module-private declaration nothing in its own file references | Delete it |
unused-import |
Imported but never referenced in the file | Delete the import line |
Workflow
- Run with
--reporters ai(add--dead-code-categoriesto focus on one category,--include-testsif test-only usage shouldn't count as "used", `--i
よくある質問
何を最初に直すかはどう決めますか?
重複、使われていないコード、複雑さにわたる健全性スコアを使い、最も低いものから始めます。
すべての言語で機能しますか?
使われていないコードの検出には、JavaScript、TypeScript、Pythonがコードの大部分を占める必要があります。
バグを修正しますか?
特定のバグではなく、保守上の問題を対象としています。
詳細
作者による元の説明
Three-part workflow to improve overall codebase health with jscpd — find and fix duplicated code, find and remove or refactor dead code, then find and simplify the largest/most complex files. Starts from --dashboard/--health to prioritize and ends by re-measuring the score.
repo: kucherenko/jscpd
人気
- GitHubのスター
- 6.5k
- ランキング
- #14188
- ライセンス
- MIT
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
code-migration
6.5kエージェントが、テストを先に書き、元のコードに対する進捗を測りながら、1度に1つの関数ずつ、ある言語やフレームワークから別のものへコードを移植できるよう支援します。
compare-codebases
6.5kエージェントが、言語が異なる場合でも、2つのコードフォルダを関数ごとに比べ、どの関数が一致し、どれが欠けているかを確認できるよう支援します。
dry-refactoring
6.5kエージェントが、最も大きな重複から始めて、繰り返されるブロックを共有の関数にまとめ、プロジェクトからコピー&ペーストされたコードを取り除けるよう支援します。
jscpd
6.5kエージェントが、完全一致、名前を変えた一致、近いコピーの形で、プロジェクト内のコピー&ペーストされたコードを見つけ、どれだけのコードが重複しているかを測れるよう支援します。
似ているスキル
diffs
394k編集内容の実際の共有可能な差分を、手書きの要約ではなく、ビューアーのリンクや画像ファイルとして作成するようエージェントを支援します。
coding-agent
394kCodex、Claude Code、OpenCodeに大きめのコーディング作業をバックグラウンドのワーカーとして渡し、その進捗を確認するようエージェントを支援します。
gh-issues
394kGitHubのイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。