Agent skill

Codebase Health Refactoring

by kucherenko in kucherenko/jscpd

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.

MITAuto-check passedDevelopment

Install Codebase Health Refactoring

skills CLI
$ npx skills add kucherenko/jscpd --skill codebase-refactoring -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install kucherenko/jscpd codebase-refactoring --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ 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-src

Use ~/.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/

Facts

Skill name
codebase-refactoring
GitHub stars
6.3k
Token cost
~2.5k tokens
SKILL.md length
1,315 words
Files
1
Skills in repo
5
Repo updated
First seen
Licence
MIT

At a glance

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.

  • Works in 4 steps: Duplicated code → Dead code → Big and complex files → …
  • Cleaning up a codebase with a measurable health score
  • SKILL.md covers Start here: measure, then…, Step 1 — Duplicated code, Step 2 — Dead code and Step 3 — Big and complex files, plus 2 more sections
  • Calls npx

What it does

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.

When your agent uses it

  • 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

Example prompts

  • “Clean up the src folder using jscpd and show me the health score before and after.”
  • “Pay down tech debt in this repo, starting with whatever scores lowest.”
  • “Run the jscpd dashboard on packages/api and tell me which files to simplify first.”

Requirements

  • Node.js, to run jscpd through npx

Workflow steps

4 steps, taken from the step headings in SKILL.md.

  1. Duplicated code
  2. Dead code
  3. Big and complex files
  4. Confirm the improvement

What it can do on your machine

Read from SKILL.md and the folder at commit 324bb57. It shows what the files ask for, not the result of running them.

  • Tool permissions

    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.

  • Runs code

    Shell commands in SKILL.md call:

    • npx

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    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.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

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.

Always · name and description, kept in context so the agent knows when to use it
~74
When it runs · the whole SKILL.md, loaded when a task matches
~2.5k

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.

Safety

Auto-check passed

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.

SKILL.md

The full file from kucherenko/jscpd at commit 324bb57, republished under its MIT licence (© kucherenko). 1,315 words, ~2,550 tokens.

Download SKILL.mdSave it as .claude/skills/codebase-refactoring/SKILL.md (or your agent's skills folder).
name
codebase-refactoring
description
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.

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

bash
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

bash
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

bash
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
CategoryMeaningUsual fix
unused-fileNever imported anywhere, not an entry pointDelete the file
unused-exportExported, but no other file imports itDelete it, or drop the export keyword if something in the same file still uses it
unused-symbolA module-private declaration nothing in its own file referencesDelete it
unused-importImported but never referenced in the fileDelete the import line
Workflow
  1. Run with --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)
  2. Sort by confidence, high to low. Everything is 0-100; below 90 the finding carries a stated reason it might be wrong — 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
  3. For each finding above your comfort threshold, confirm it by hand — grep the symbol name across the repo (dynamic access, a string-based router, a template file jscpd doesn't parse can all hide a real use) — then apply the fix from the table above
  4. Run the project's own test suite and build after each batch of deletions, not only jscpd's re-run: dead-code analysis proves nothing reaches the code from an entry point, not that removing it can't break a build step
  5. Re-run --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 once
  6. Report what you skipped and why (low confidence, a reason you couldn't rule out, or intentionally-kept dead code such as a public library export) separately from what you actually removed
Show full SKILL.md (532 more words)Show less

Step 3 — Big and complex files

bash
npx 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/8

cx 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.

Workflow
  1. Take the top N files by complexity (and, from the --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)
  2. Read each file and name the actual driver: deep nesting, a long function doing several unrelated things, a large switch/if-chain over a type or state, or a file that is really several modules glued together
  3. Pick the matching strategy:
    • Deep nesting → guard clauses / early return, flatten the happy path
    • Long function, several responsibilities → extract function per responsibility, named for what it does
    • Branching over a fixed set of cases (type, enum, status) → replace with a lookup table/map, or polymorphism if each case already has its own type
    • File doing too much → split along its actual seams (one export group per file), not an arbitrary line-count cut
  4. Refactor one file at a time; keep behavior identical — this is a complexity pass, not a rewrite. If a duplication clone (step 1) or a dead branch (step 2) turns up while reading, still handle it in its own step so the reason for each change stays traceable
  5. Re-run --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 problem

Step 4 — Confirm the improvement

bash
npx 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.

Tips

  • Don't run all three passes on a codebase you've never seen before without reading --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
  • A --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 0
  • Health scores from two runs are only comparable when built from the same dimensions — if a dimension went from n/a to measured (or the reverse) because the file mix changed, say so rather than reading the raw score delta as improvement or regression
  • Commit each step separately (duplication fixes, dead-code removal, complexity simplification) — a reviewer verifying "did this actually reduce X" wants a diff scoped to X

© kucherenko, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/codebase-refactoring of kucherenko/jscpd.

Open the folder on GitHubat commit 324bb57

Compare with similar skills

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.

Codebase Health Refactoring compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Codebase Health Refactoring this skillkucherenko/jscpd6.3k—~2.5kAutomated safety check: PassMIT
Systematic Code Refactoringluongnv89/claude-howto42k—~3kAutomated safety check: PassMIT
Code Simplification for ego-litecitrolabs/ego-lite17k—~1.2kAutomated safety check: PassMIT
Code Refactoring Workflowluongnv89/claude-howto42k—~3.1kAutomated safety check: PassMIT
Tech Debt Analyzerailabs-393/ai-labs-claude-skills4542 repos~3.9kAutomated safety check: PassMIT
FIXME Resolvertailcallhq/forgecode7.6k—~1.1kAutomated safety check: PassApache-2.0

Similar skills

  • 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.

    42k GitHub stars~3k tokensUpdated 7 days ago
    DevelopmentAuto-check passed
  • Finds and implements evidence-backed simplifications in the ego-lite repository, such as dead code, duplicated state and speculative abstractions, without hiding behavior changes.

    17k GitHub stars~1.2k tokensUpdated 14 days ago
    DevelopmentAuto-check passed
  • Code Refactoring Workflow

    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.

    42k GitHub stars~3.1k tokensUpdated 7 days ago
    DevelopmentAuto-check passed
  • Tech Debt Analyzer

    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.

    454 GitHub starsUsed in 2 repos~3.9k tokens
    DevelopmentAuto-check passed
  • FIXME Resolver

    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.

    7.6k GitHub stars~1.1k tokensUpdated today
    DevelopmentAuto-check passed
  • Desloppify

    Git-on-my-level/codex-autorunner

    Codebase health scanner and technical debt tracker. An agent skill from Git-on-my-level/codex-autorunner.

    875 GitHub stars~3.4k tokensUpdated 6 days ago
    DevelopmentAuto-check passed

More from 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.

    6.3k GitHub stars~5k tokensUpdated today
    Auto-check passed
  • Compares two folders function by function with jscpd --compare, across languages if needed, and explains which functions match and which have no counterpart.

    6.3k GitHub stars~3.2k tokensUpdated today
    Auto-check passed
  • Removes copy-paste duplication found by jscpd, starting with exact clones and hotspots, then renamed and near-miss copies, using proven refactoring strategies.

    6.3k GitHub stars~2.1k tokensUpdated today
    Auto-check passed
  • Finds duplicated code in 220+ languages with jscpd, reports exact, renamed and near-miss clones in a compact agent-friendly format and measures duplication.

    6.3k GitHub stars~4.6k tokensUpdated today
    Auto-check passed

Categories

Questions about Codebase Health Refactoring

What does Codebase Health Refactoring do?

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.

When should I use Codebase Health Refactoring?

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.

How do I install Codebase Health Refactoring in Claude Code?

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.

How do I install Codebase Health Refactoring in Codex?

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.

Can I use Codebase Health Refactoring in Cursor, Gemini CLI or GitHub Copilot?

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.

What does Codebase Health Refactoring need to run?

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.

Does Codebase Health Refactoring access the network?

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.

Is Codebase Health Refactoring safe to install?

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.

What licence does Codebase Health Refactoring use?

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.

How many tokens does Codebase Health Refactoring use?

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.

What are the alternatives to Codebase Health Refactoring?

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.

Who maintains Codebase Health Refactoring?

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.