codebase-refactoring
Skill6.3k starsChanged 3 months agoMITView on GitHub
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.
Trending
More talk lately.about the whole repository
Who's talking about kucherenko/jscpd
- A Hacker News story“Jscpd Public Copy/paste detector for programming source code”Hacker News · Jun 29, 2025 · 5 points
- sivagao/blog“2016/03/31 针针见血:怎么消除JavaScript中的代码坏味道”GitHub · Mar 31, 2016 · 5 reactions
- @marmelab.bsky.social“Just came across jscpd: A Copy/paste detector for programming source code. It lets you see if your code can …”Bluesky · Mar 7, 2025 · 4 likes
- A Hacker News story“Show HN: Jscpd start support type2/type3 clones”Hacker News · Sep 11, 2026 · 2 points
- AFI-Protocol/afi-config“chore(deps-dev)(deps-dev): bump jscpd from 4.2.5 to 5.0.12”GitHub · Jul 20, 2026 · 2 reactions
The biggest 5 of 49 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 49
Talked about on GitHub, Hacker News and Bluesky (49 times).
On GitHub · 44
- Mar 31, 20162016/03/31 针针见血:怎么消除JavaScript中的代码坏味道 — sivagao/blog5 reactions · 9 comments
- Jul 20, 2026chore(deps-dev)(deps-dev): bump jscpd from 4.2.5 to 5.0.12 — AFI-Protocol/afi-config2 reactions · 3 comments
- Jun 8, 2026Bump jscpd from 4.2.4 to 5.0.4 — hbmartin/raffy-research2 reactions · 3 comments
- May 31, 2026Bump jscpd from 4.0.9 to 4.2.4 — hbmartin/react-mentions-ts2 reactions · 3 comments
- Aug 8, 2026chore(deps): bump the dev-minor-patch group across 1 directory with 13 updates — juliopolycarpo/mangostudio1 reaction · 7 comments
39 more on GitHub
- Jul 20, 2026build(deps): bump the routine-minor-patch group with 20 updates — zaks-io/splitch1 reaction · 3 comments
- Jul 20, 2026build(deps-dev): bump the dev-dependencies group across 1 directory with 15 updates — zaks-io/splitch1 reaction · 2 comments
- Jul 20, 2026build(deps-dev): bump the dev-dependencies group with 14 updates — zaks-io/splitch1 reaction · 5 comments
- Jul 13, 2026build(deps-dev): bump the dev-dependencies group with 12 updates — zaks-io/splitch1 reaction · 2 comments
- Jul 13, 2026build(deps): Bump jscpd from 4.2.4 to 5.0.12 — zaks-io/insecur1 reaction · 1 comment
- Jul 6, 2026build(deps-dev): bump the dev-dependencies group with 8 updates — zaks-io/splitch1 reaction · 5 comments
- Jun 30, 2026chore(deps): bump jscpd from 4.2.4 to 5.0.11 — zaks-io/insecur1 reaction · 1 comment
- Jun 18, 2026README benchmarks may be outdated after jscpd Rust rewrite — fallow-rs/fallowsays it tested it1 reaction · 5 comments
- Apr 14, 2026chore(deps): bump the npm-deps group across 1 directory with 14 updates — dctmfoo/openai-agents1 reaction · 1 comment
- Jan 24, 2023New linters/formatters — db-ux-design-system/core-web1 reaction · 3 comments
- Oct 5, 2026chore(deps): bump jscpd from 5.0.14 to 5.4.0 — actions-marketplace-validations/Raed2180416_holt0 reactions
- Oct 5, 2026build(deps-dev): bump jscpd from 5.3.1 to 5.4.0 — aurelienbobenrieth/harness0 reactions
- Oct 5, 2026chore(deps): bump jscpd from 5.0.14 to 5.3.3 in /benchmarks — CircuitBoardGames/Fallow-Forgejosays it tested it0 reactions
- Oct 5, 2026chore(deps-dev): bump jscpd from 4.2.5 to 5.4.0 — Axl47/Theoria-Codex0 reactions
- Oct 5, 2026ci(deps): bump kucherenko/jscpd from 5.3.2 to 5.4.0 in the github-actions group — xsyetopz/easel.js0 reactions · 1 comment
- Oct 4, 2026chore(deps-dev): bump jscpd from 4.3.0 to 5.4.0 — GabrielV-Engineer/AILIENANT0 reactions
- Oct 3, 2026chore(deps-dev): bump jscpd from 5.2.1 to 5.4.0 — ZinTrust/zintrust0 reactions · 1 comment
- Oct 3, 2026Bump jscpd from 5.0.12 to 5.1.2 — xiejianjun000/eco-agent0 reactions · 1 comment
- Oct 3, 2026build(deps-dev): bump jscpd from 5.0.12 to 5.1.2 — murilloleonel939-art/deepseek0 reactions · 1 comment
- Oct 1, 2026build(deps-dev): bump the npm-dependencies group with 2 updates — chapmandu/rust-in-peace0 reactions
- Oct 1, 2026chore(deps): bump jscpd from 5.0.16 to 5.3.2 in /benchmarks — actions-marketplace-validations/fallow-rs_fallowsays it tested it0 reactions
- Oct 1, 2026build(deps): bump jscpd from 4.3.0 to 5.3.2 — astubbs/duplicate-code-cross-check0 reactions · 1 comment
- Oct 1, 2026Bump jscpd from 5.0.16 to 5.3.2 — vinceyvincey/agent-readiness0 reactions
- Sep 30, 2026chore(deps): bump jscpd from 5.0.12 to 5.3.2 — fderuiter/equipose-randomization0 reactions · 1 comment
- Sep 29, 2026chore(deps): bump jscpd from 5.0.14 to 5.3.2 — Raed2180416/holt0 reactions
- Sep 29, 2026chore(deps-dev): bump jscpd from 5.0.16 to 5.3.2 — xplorer1/starter-test0 reactions
- Sep 28, 2026Bump jscpd from 3.4.2 to 5.3.2 in /dependencies — asia215/super-linter0 reactions
- Sep 28, 2026chore(deps): bump jscpd from 5.0.14 to 5.3.2 — Dorsey-Creative/secrets-sync-cli0 reactions
- Sep 26, 2026chore(deps-dev): bump jscpd from 5.2.0 to 5.3.0 — mnahkies/shoe-string-server0 reactions
- Sep 23, 2026chore(deps-dev): bump jscpd from 4.3.0 to 5.3.2 — Glock-Boonyarith/school-check0 reactions · 1 comment
- Sep 23, 2026build(deps-dev): bump jscpd from 5.0.15 to 5.3.1 — authenticmemory/gami-cli-verifier0 reactions
- Sep 21, 2026Bump jscpd from 3.3.26 to 5.2.1 in /dependencies — SM-125F/super-linter0 reactions
- Sep 15, 2026build(deps-dev): bump jscpd from 5.0.12 to 5.0.15 — Suife-yuanxing/deepseek-harness-personal0 reactions · 1 comment
- Sep 14, 2026build(deps-dev): bump jscpd from 5.0.12 to 5.0.15 — AStarqx/DeepSeek-Harness-Desktop0 reactions · 1 comment
- Sep 12, 2026chore(deps-dev): bump jscpd from 5.0.14 to 5.2.0 — ninasokolov8/browser-coder0 reactions
- Sep 11, 2026build(deps): Bump jscpd from 5.0.14 to 5.1.2 — codacy/codacy-duplication-jscpd0 reactions · 1 comment
- Sep 10, 2026Bump jscpd from 4.3.0 to 5.1.2 — VISVANTHA/Digital-Sippoy-new0 reactions
- Sep 7, 2026Bump jscpd from 3.5.3 to 5.1.2 in /dependencies — NocturnalGlory/super-linter0 reactions
- Aug 14, 2026jscpdで重複コードを防ぐ仕組みを作る — taka1156/webspaces0 reactions
On Hacker News · 4
- Jun 29, 2025Jscpd Public Copy/paste detector for programming source code5 points
- Sep 11, 2026Show HN: Jscpd start support type2/type3 clones2 points
- Oct 22, 2025jscpd: Copy/paste detector for programming source code2 points
- Jan 30, 2024Copy/paste detector for programming source code, supports 150 formats1 point
On Bluesky · 1
- Mar 7, 2025Just came across jscpd: A Copy/paste detector for programming source code. It lets you see if your code can be “simplified” in certain… — @marmelab.bsky.social4 likes and reposts
In this repository4 other files it gives its agents.
- code-migrationSkill
- compare-codebasesSkill
- dry-refactoringSkill
- jscpdSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 96
Run with --reporters ai (add --dead-code-categories to focus on one category, --include-tests if test-only usage shouldn't count as "used", …
- Very specific: line 111
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 …
- Very specific: line 153
Read each file and name the actual driver: deep nesting, a long function doing several unrelated things, a large switch/if-chain over a …
- Very specific: line 187
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 …
- Distinctive: line 198
Commit each step separately (duplication fixes, dead-code removal, complexity simplification) — a reviewer verifying "did this actually …
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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 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.
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",--include-entry-exportsto also flag an entry file's own unused exports, normally excluded since its whole surface is the public API) - Sort by confidence, high to low. Everything is 0-100; below 90 the finding
carries a stated reason it might be wrong —
eval/getattrcalls, 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 (seestatistics.unparsedFilesin 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 - 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
- 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
- Re-run
--dead-codeafter 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 - 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
Step 3 — Big and complex files
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/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.
Workflow
- Take the top N files by complexity (and, from the
--summaryform, by size — a huge low-complexity file, e.g. a big data table, is a different problem than a small high-complexity one) - 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 - 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
- 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
- Re-run
--complexityon the touched files to confirmcxactually 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
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
--dashboardfirst — 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-inputfile (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/ato 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
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

