dry-refactoring
Skill6.3k starsChanged 3 months agoMITView on GitHub
Guided workflow to eliminate copy-paste duplication detected by jscpd. Refactor exact, renamed and near-miss clones using extract function, parameterize, module, constant, or base class strategies, starting from the hotspots the summary ranks.
1 other project uses a version of this.
Trending
More talk lately.about the whole repository
Most recently taken up by
- YYH211/Claude-meta-skilltheir own version, first seen Oct 31, 2025
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
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- YYH211/Claude-meta-skill★ 282same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository4 other files it gives its agents.
- codebase-refactoringSkill
- code-migrationSkill
- compare-codebasesSkill
- jscpdSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 3 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 46
Run jscpd with --reporters ai on the target path (add --summary on larger codebases to pick a starting point: files with high dup% and high …
- Distinctive: line 48
Read both code fragments from the source files
- Distinctive: line 88
If the gap changes the meaning rather than adding a step, keep two functions but extract the shared halves.
- Very specific: line 99
All call sites are updated, not just the two reported by jscpd
- Distinctive: line 106
Start with clones that have the highest line count — they have the most impact
- Very specific: line 107
Use the summary's dup% column to order the work: a large file with a high share of duplicated lines pays back first
- Very specific: line 112
Do not gate CI (--threshold, --fail-on-new-clones) on the Type-2/Type-3 passes until the team has reviewed what they report on this …
- Very specific: line 114
Use --min-lines 10 to filter noise and focus on meaningful duplications
- Very specific: line 115
Keep a separate --baseline per set of detection flags when gating CI: renamed and similar runs fingerprint clones differently from exact …
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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
dry-refactoring
Guided workflow to eliminate copy-paste duplication in source code. Use after running jscpd to detect clones.
Prerequisites
First, run jscpd to identify duplications:
npx jscpd --reporters ai <path>In codebases that mix related formats (e.g. JavaScript and TypeScript), add --cross-formats so clones spanning both are detected too:
npx jscpd --reporters ai --cross-formats "js-ts" <path>On larger codebases, add --summary to get a refactoring-hotspot overview alongside the clone list — top files and folders with a dup% column showing how much of each file is duplicated:
npx jscpd --reporters ai --summary <path>The default scan reports only exact copies, and those are the ones to refactor first: an exact clone is almost always a real copy-paste. Two more passes find copies that were edited after pasting. They are noisier: they ignore names, values or a few statements on purpose, so they also surface blocks that merely look alike (models and DTOs, config tables, test setup, generated code, shared idioms). Run them only after the exact clones are dealt with, one family at a time, with tight settings, and treat what they report as leads to read rather than defects to fix:
# Type-2: renamed copies (other variable names, other constants), reported as "(renamed)".
# Raise --min-tokens: with identifiers ignored, a short block is mostly placeholders.
npx jscpd --reporters ai --ignore-identifiers --min-tokens 70 <path>
# Type-3: near-miss copies (one or two edited lines, or JS/TS functions with the same structure),
# reported as "[~0.91 gap]" and "[~0.85 ast]". Widen only if the tight run finds nothing.
npx jscpd --reporters ai --max-gap-lines 1 --similarity 0.85 <path>See the jscpd skill for full option reference, including cross-format group syntax, the clone-kind suffixes and how to read the summary.
Workflow
- Run jscpd with
--reporters aion the target path (add--summaryon larger codebases to pick a starting point: files with highdup%and high token counts pay off most) - Parse each clone line to identify the two duplicated locations (file + line range) and its kind: no suffix is an exact copy,
(renamed)differs only in names or values,[~N gap]has a few edited lines in the middle,[~N ast]is a function pair with the same structure - Read both code fragments from the source files
- Understand what the duplicated code does, and for renamed and similar clones list exactly what differs between the two sides
- Triage renamed and similar clones before touching them. Skip the pair, and say so, when any of these holds: the two sides do different things despite the same shape (a
switchover different enums, two reducers with unrelated semantics); the sameness is intentional boilerplate (models, DTOs, config, route tables, test fixtures); the code is generated; a shared abstraction would need a vague name likeprocessData; or the pair is under about 10 lines. Only a pair that would let you delete code and give the extraction a precise name goes on to the next step - Design a refactoring: extract a shared function, class, module, or constant; the kind decides the strategy (below)
- Apply the refactoring — update both locations and all other usages
- Re-run jscpd with the same flags to confirm the clone is eliminated and the
dup%of the touched files went down; a clone that was(renamed)will not show in a default run, so check with--ignore-identifiersagain - Repeat for remaining clones, highest-impact first: exact clones, then renamed, then similar. Report the skipped candidates separately from the refactored ones, with the reason, so nobody mistakes a normalized run's count for real duplication
Refactoring Strategies
Extract function — when the duplicate is a block of logic:
// Before: same block in two places
// After: shared function called from both placesExtract module/utility — when the duplicate spans multiple files in different domains:
// Move shared logic to a shared utility file and import itExtract constant or config — when the duplicate is repeated data or configuration.
Template/base class — when the duplicate is structural (e.g., repeated class shape).
Parameterize — for (renamed) clones. The two sides are the same algorithm over different names or values, so the things that differ become parameters:
// Before: computeCartTotal(items) and computeBasketTotal(entries), same body, other names;
// limits-dev.js and limits-prod.js, same shape, other numbers
// After: one function whose parameters are the identifiers that differed,
// or one function reading the values that differed from a config objectA renamed clone whose only difference is a literal is a missing constant or config entry, not a missing function.
Unify near-miss copies — for [~N gap] clones. Read the unmatched lines: the gap is the one place the copies diverged, typically a guard, a log call or an extra field. Extract the common body and pass the divergence in:
// Before: saveUser and saveAccount, identical except one inserted validation line
// After: one saveRecord(record, { validate }) with the inserted line behind the option,
// or the inserted line moved to the caller before the shared callIf the gap changes the meaning rather than adding a step, keep two functions but extract the shared halves.
Merge similar functions — for [~N ast] clones. The structure matches but names, literals and some statements do not. Diff the two functions first; the ast score tells how much is shared (0.9 is a copy with one edit, 0.75 a copy with a couple of added statements plus renames). Extract the shared skeleton and inject what differs, as arguments, a strategy object, or a callback:
// Before: buildInvoice(order, customer, taxRate) and buildCreditNote(refund, account, vatRate):
// same loop, same rounding, one extra guard and one extra log call in the second
// After: buildDocument(source, party, rate, { filter, onBuilt }) used by bothBelow about 0.8 the pair usually shares an idiom, not an implementation; leave those alone unless the summary shows the file is a hotspot anyway.
Always ensure:
- All call sites are updated, not just the two reported by jscpd
- Tests still pass after refactoring
- The extracted abstraction has a clear, descriptive name
- The re-run uses the same detection flags as the run that found the clone
Tips
- Start with clones that have the highest line count — they have the most impact
- Use the summary's
dup%column to order the work: a large file with a high share of duplicated lines pays back first - A clone between test files may indicate a missing test helper
- Clones across unrelated modules may signal a missing shared utility
- A cross-format clone (same logic in a
.jsand a.tsfile, found with--cross-formats) often means code was ported without deleting the original — consolidate into one implementation (usually the TypeScript one) and update imports, rather than extracting a third shared copy - Many
(renamed)clones in one file usually mean one abstraction is missing, not many: look for the shared shape before extracting pair by pair. Many(renamed)clones across test files usually mean nothing: test cases are supposed to look alike - Do not gate CI (
--threshold,--fail-on-new-clones) on the Type-2/Type-3 passes until the team has reviewed what they report on this codebase; gate on the exact run --similarityonly covers JavaScript and TypeScript today; for other languages rely on the exact and--max-gap-linespasses- Use
--min-lines 10to filter noise and focus on meaningful duplications - Keep a separate
--baselineper set of detection flags when gating CI: renamed and similar runs fingerprint clones differently from exact runs
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.

