Guided workflow to eliminate copy-paste duplication detected by jscpd. Refactor clones using extract function, module, constant, or base class strategies.
67
81%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Low
Low-risk findings worth noting
Guided workflow to eliminate copy-paste duplication in source code. Use after running jscpd to detect clones.
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>See the jscpd skill for full option reference, including cross-format group syntax and how to read the summary.
--reporters ai on the target path (add --summary on larger codebases to pick a starting point: files with high dup% and high token counts pay off most)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).
Always ensure:
.js and a .ts file, 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--min-lines 10 to filter noise and focus on meaningful duplicationscf73651
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.