Systematic Code Refactoring
luongnv89/claude-howto
Guides refactoring in phases based on Martin Fowler's method: research, test coverage check, planning and small tested steps, with your approval at each phase.
A three-part cleanup guided by jscpd: measure health, then fix duplicated code, remove dead code and simplify the most complex files, finishing by re-measuring the score.
$ npx skills add kucherenko/jscpd --skill codebase-refactoring -a claude-codeProject install by default; add -g for ~/.claude/skills/.
$ gh skill install kucherenko/jscpd codebase-refactoring --agent claude-codeProject scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).
$ git clone --depth 1 https://github.com/kucherenko/jscpd.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/codebase-refactoring .claude/skills/codebase-refactoring && rm -rf skills-srcUse ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.
Claude Code skills documentation · loads skills from .claude/skills/
Install the "codebase-refactoring" agent skill from https://github.com/kucherenko/jscpd/tree/master/skills/codebase-refactoring into .claude/skills/codebase-refactoring/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "codebase-refactoring", then confirm the skill loads.Claude Code copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$skill-installer install https://github.com/kucherenko/jscpd/tree/master/skills/codebase-refactoringType this inside Codex. $skill-installer <name> installs a curated skill from openai/skills. The installer writes to $CODEX_HOME/skills (default ~/.codex/skills). Restart Codex if the skill does not show up.
$ npx skills add kucherenko/jscpd --skill codebase-refactoring -a codexProject install goes to .agents/skills/; add -g for ~/.codex/skills/.
$ gh skill install kucherenko/jscpd codebase-refactoring --agent codexProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/kucherenko/jscpd.git skills-src && mkdir -p .agents/skills && cp -r skills-src/skills/codebase-refactoring .agents/skills/codebase-refactoring && rm -rf skills-srcUse ~/.agents/skills/ instead of .agents/skills for a personal install.
Codex skills documentation · loads skills from .agents/skills/
Install the "codebase-refactoring" agent skill from https://github.com/kucherenko/jscpd/tree/master/skills/codebase-refactoring into .agents/skills/codebase-refactoring/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "codebase-refactoring", then confirm the skill loads.Codex copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add kucherenko/jscpd --skill codebase-refactoring -a cursorProject install goes to .agents/skills/; add -g for ~/.cursor/skills/.
$ gh skill install kucherenko/jscpd codebase-refactoring --agent cursorProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/kucherenko/jscpd.git skills-src && mkdir -p .cursor/skills && cp -r skills-src/skills/codebase-refactoring .cursor/skills/codebase-refactoring && rm -rf skills-srcUse ~/.cursor/skills/ instead of .cursor/skills for a personal install.
Cursor skills documentation · loads skills from .cursor/skills/, .agents/skills/, .claude/skills/, .codex/skills/
Install the "codebase-refactoring" agent skill from https://github.com/kucherenko/jscpd/tree/master/skills/codebase-refactoring into .cursor/skills/codebase-refactoring/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "codebase-refactoring", then confirm the skill loads.Cursor copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gemini skills install https://github.com/kucherenko/jscpd.git --path skills/codebase-refactoring--scope user (default) or --scope workspace; --path is the subfolder of the repo that holds the skill; --consent skips the security confirmation prompt.
$ npx skills add kucherenko/jscpd --skill codebase-refactoring -a gemini-cliProject install goes to .agents/skills/; add -g for ~/.gemini/skills/.
$ gh skill install kucherenko/jscpd codebase-refactoring --agent gemini-cliProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/kucherenko/jscpd.git skills-src && mkdir -p .gemini/skills && cp -r skills-src/skills/codebase-refactoring .gemini/skills/codebase-refactoring && rm -rf skills-srcUse ~/.gemini/skills/ instead of .gemini/skills for a personal install, then run /skills reload.
Gemini CLI skills documentation · loads skills from .gemini/skills/, .agents/skills/
Install the "codebase-refactoring" agent skill from https://github.com/kucherenko/jscpd/tree/master/skills/codebase-refactoring into .gemini/skills/codebase-refactoring/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "codebase-refactoring", then confirm the skill loads.Gemini CLI copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gh skill install kucherenko/jscpd codebase-refactoringInstalls for Copilot at project scope by default; add --scope user for a personal install. Preview a skill first with gh skill preview. Needs GitHub CLI 2.90.0 or later (public preview).
$ npx skills add kucherenko/jscpd --skill codebase-refactoring -a github-copilotProject install goes to .agents/skills/; add -g for ~/.copilot/skills/.
$ git clone --depth 1 https://github.com/kucherenko/jscpd.git skills-src && mkdir -p .github/skills && cp -r skills-src/skills/codebase-refactoring .github/skills/codebase-refactoring && rm -rf skills-srcUse ~/.copilot/skills/ instead of .github/skills for a personal install. Commit .github/skills so cloud agent and code review can use it.
GitHub Copilot skills documentation · loads skills from .github/skills/, .claude/skills/, .agents/skills/
Install the "codebase-refactoring" agent skill from https://github.com/kucherenko/jscpd/tree/master/skills/codebase-refactoring into .github/skills/codebase-refactoring/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "codebase-refactoring", then confirm the skill loads.GitHub Copilot copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add kucherenko/jscpd --skill codebase-refactoring -a opencodeOpenCode documents no install command of its own. Project install goes to .agents/skills/; add -g for ~/.config/opencode/skills/.
$ gh skill install kucherenko/jscpd codebase-refactoring --agent opencodeProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/kucherenko/jscpd.git skills-src && mkdir -p .opencode/skills && cp -r skills-src/skills/codebase-refactoring .opencode/skills/codebase-refactoring && rm -rf skills-srcUse ~/.config/opencode/skills/ instead of .opencode/skills for a personal install.
OpenCode skills documentation · loads skills from .opencode/skills/, .claude/skills/, .agents/skills/
Install the "codebase-refactoring" agent skill from https://github.com/kucherenko/jscpd/tree/master/skills/codebase-refactoring into .opencode/skills/codebase-refactoring/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "codebase-refactoring", then confirm the skill loads.OpenCode copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
codebase-refactoringA three-part cleanup guided by jscpd: measure health, then fix duplicated code, remove dead code and simplify the most complex files, finishing by re-measuring the score.
The skill is for requests to clean up, improve or pay down tech debt in a codebase, not to fix one bug. It starts with npx jscpd --health, which returns a score built from duplication, dead-code and complexity sub-scores where high is good. The lowest sub-score shows where the codebase hurts most and decides which pass goes first. A dashboard run adds a per-file breakdown of the biggest clones, the most complex files and the largest dead-code findings.
The default order is duplication, then dead code, then complexity, so later passes do not spend effort on code that an earlier pass will move or delete. The duplication step hands off to a separate dry-refactoring skill, whose strategies include extracting a function, parameterizing, a shared module or constant, or a base class. Dead-code detection needs JavaScript, TypeScript or Python to make up a real share of the code, and an n/a reading means skip that step, not that the code is clean.
4 steps, taken from the step headings in SKILL.md.
Read from SKILL.md and the folder at commit 324bb57. It shows what the files ask for, not the result of running them.
Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.
From allowed-tools in the SKILL.md frontmatter.
Shell commands in SKILL.md call:
npxFrom the folder's file list and the shell code blocks in SKILL.md.
No URLs in SKILL.md. Its commands use npx, which can reach the network depending on how they are called.
From URLs in SKILL.md, links to its own repository left out.
Names no API keys, tokens, secrets or passwords.
From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.
Codebase Health Refactoring loads about 2.5k tokens when it runs. Until then it costs about 74 tokens; SKILL.md has 1,315 words of instructions outside code blocks.
Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.
The automated check found no risky patterns in SKILL.md.
Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.
The full file from kucherenko/jscpd at commit 324bb57, republished under its MIT licence (© kucherenko). 1,315 words, ~2,550 tokens.
.claude/skills/codebase-refactoring/SKILL.md (or your agent's skills folder).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.
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.
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.
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 usedThis 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.
| 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 |
--reporters ai (add --dead-code-categories to focus on one
category, --include-tests if test-only usage shouldn't count as "used",
--include-entry-exports to also flag an entry file's own unused
exports, normally excluded since its whole surface is the public API)eval/getattr calls,
decorators the analyzer doesn't recognize, a wildcard re-export, the name
showing up only inside a string literal, or a file elsewhere that failed
to parse (see statistics.unparsedFiles in the JSON report). Read the
reason before deleting; --min-confidence (default 60) only sets the
floor for what's reported, it doesn't make a low-confidence finding safe--dead-code after a batch: a file whose only import was the one
you just deleted may now be dead itself — that cascade is expected, keep
going until a clean pass, not just oncenpx jscpd --complexity --reporters ai --summary-top 10 <path>
# or, ranked alongside duplication and size:
npx jscpd --reporters ai --summary --summary-by complexity <path>Complexity by complexity (6 files, 6 folders):
files (tokens/lines/size/cx):
c/checkout.c 176/32/710/13
rust/status.rs 112/24/481/9
swift/Profile.swift 88/21/446/8cx is a language-aware cyclomatic-complexity estimate — roughly one path
per function plus one per branch (if, loops, &&/||, match/switch
arms, the ternary and Elvis operators, each counted the way the language
actually spells it) — read as a ranking signal, not an exact metric. Prose
and data files (Markdown, JSON, YAML, lock files, …) always score 0; a
large README is not a refactoring target. jscpd's own health score treats a
file with complexity 50 or higher as "complex" (the threshold its
dead code-style half-life curve is calibrated against) — a reasonable
default cutoff for "worth reading" if the summary doesn't make an obvious
one clear.
--summary form, by
size — a huge low-complexity file, e.g. a big data table, is a different
problem than a small high-complexity one)switch/if-chain over a type
or state, or a file that is really several modules glued together--complexity on the touched files to confirm cx actually
dropped — a split that only moves code around without reducing branching
per function didn't fix anything, it just renamed the problemnpx jscpd --health --reporters ai <path>Compare the score and grade to the Step 0 measurement. A dimension that got
worse (duplication crept back in while extracting a shared complexity fix,
say) is a signal to revisit that step, not just note it — re-run the
relevant pass (--summary, --dead-code, --complexity) rather than only
trusting the one aggregate number.
--dashboard first — on a project where only one dimension is
actually bad, spending equal effort on all three wastes time on the two
that are already fine--health-input file (coverage, security scan results) can be layered
onto the same score if the project already tracks those; it doesn't change
anything about this workflow, it just adds more dimensions to Step 0n/a to measured (or the reverse)
because the file mix changed, say so rather than reading the raw score
delta as improvement or regression© kucherenko, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file
Just SKILL.md in skills/codebase-refactoring of kucherenko/jscpd.
Open the folder on GitHubat commit 324bb57
Codebase Health Refactoring next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.
| Skill | Stars | Used in | Tokens | Auto-check | Licence | Repo updated |
|---|---|---|---|---|---|---|
| Codebase Health Refactoring this skillkucherenko/jscpd | 6.3k | — | ~2.5k | Automated safety check: Pass | MIT | |
| Systematic Code Refactoringluongnv89/claude-howto | 42k | — | ~3k | Automated safety check: Pass | MIT | |
| Code Simplification for ego-litecitrolabs/ego-lite | 17k | — | ~1.2k | Automated safety check: Pass | MIT | |
| Code Refactoring Workflowluongnv89/claude-howto | 42k | — | ~3.1k | Automated safety check: Pass | MIT | |
| Tech Debt Analyzerailabs-393/ai-labs-claude-skills | 454 | 2 repos | ~3.9k | Automated safety check: Pass | MIT | |
| FIXME Resolvertailcallhq/forgecode | 7.6k | — | ~1.1k | Automated safety check: Pass | Apache-2.0 |
luongnv89/claude-howto
Guides refactoring in phases based on Martin Fowler's method: research, test coverage check, planning and small tested steps, with your approval at each phase.
citrolabs/ego-lite
Finds and implements evidence-backed simplifications in the ego-lite repository, such as dead code, duplicated state and speculative abstractions, without hiding behavior changes.
luongnv89/claude-howto
Guides systematic, test-backed refactoring in the style of Martin Fowler, moving through research, planning and small incremental changes with your approval at each phase.
ailabs-393/ai-labs-claude-skills
This skill should be used when analyzing technical debt in a codebase, documenting code quality issues, creating technical debt registers, or assessing code maintainability.
tailcallhq/forgecode
Finds every FIXME comment in a codebase, groups related ones across files into one task, implements the work they describe and removes the comments once it is done.
Git-on-my-level/codex-autorunner
Codebase health scanner and technical debt tracker. An agent skill from Git-on-my-level/codex-autorunner.
kucherenko/jscpd
Measures a code port between languages or frameworks with jscpd's function-level comparison, porting tests before code and tracking what is left unmatched.
kucherenko/jscpd
Compares two folders function by function with jscpd --compare, across languages if needed, and explains which functions match and which have no counterpart.
kucherenko/jscpd
Removes copy-paste duplication found by jscpd, starting with exact clones and hotspots, then renamed and near-miss copies, using proven refactoring strategies.
kucherenko/jscpd
Finds duplicated code in 220+ languages with jscpd, reports exact, renamed and near-miss clones in a compact agent-friendly format and measures duplication.
Categories
A three-part cleanup guided by jscpd: measure health, then fix duplicated code, remove dead code and simplify the most complex files, finishing by re-measuring the score. The skill is for requests to clean up, improve or pay down tech debt in a codebase, not to fix one bug. It starts with npx jscpd --health, which returns a score built from duplication, dead-code and complexity sub-scores where high is good.
Codebase Health Refactoring fits situations like: cleaning up a codebase with a measurable health score; finding and merging duplicated code; removing dead code and simplifying the largest, most complex files; paying down tech debt across a whole repository.
Run `npx skills add kucherenko/jscpd --skill codebase-refactoring -a claude-code`. Or copy the skill folder (skills/codebase-refactoring in kucherenko/jscpd) into .claude/skills/codebase-refactoring in your project. Claude Code loads it when a task matches its description.
Run `npx skills add kucherenko/jscpd --skill codebase-refactoring -a codex`. Or copy the skill folder (skills/codebase-refactoring in kucherenko/jscpd) into .agents/skills/codebase-refactoring in your project. Codex loads it when a task matches its description.
Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add kucherenko/jscpd --skill codebase-refactoring -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/codebase-refactoring, .gemini/skills/codebase-refactoring, .github/skills/codebase-refactoring and .opencode/skills/codebase-refactoring in your project.
Going by SKILL.md and its folder, Codebase Health Refactoring needs the command-line tools its instructions call (npx). Our summary lists: Node.js, to run jscpd through npx.
SKILL.md contains no URLs. Its commands use npx, which can reach the network depending on how they are called. This is read from the text; nothing was executed.
Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.
Codebase Health Refactoring is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.
About 2.5k tokens (SKILL.md is roughly 10k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.
Skills that share tags, products or a category with Codebase Health Refactoring: Systematic Code Refactoring (luongnv89/claude-howto, 42k stars), Code Simplification for ego-lite (citrolabs/ego-lite, 17k stars), Code Refactoring Workflow (luongnv89/claude-howto, 42k stars) and Tech Debt Analyzer (ailabs-393/ai-labs-claude-skills, 454 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.
kucherenko (a GitHub user) maintains it in kucherenko/jscpd, which has 6,345 GitHub stars. The repository holds 5 skills in this directory. The repository was last updated on October 6, 2026.
Source: kucherenko/jscpd on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.