Agent skill

DRY Refactoring With jscpd

by kucherenko in 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.

MITAuto-check passedDevelopment

Install DRY Refactoring With jscpd

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

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

GitHub CLI
$ gh skill install kucherenko/jscpd dry-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/dry-refactoring .claude/skills/dry-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
dry-refactoring
GitHub stars
6.4k
Token cost
~2.1k tokens
SKILL.md length
1,020 words
Files
1
Skills in repo
5
Repo updated
First seen
Licence
MIT

At a glance

Removes copy-paste duplication found by jscpd, starting with exact clones and hotspots, then renamed and near-miss copies, using proven refactoring strategies.

  • Works in 9 steps: Run jscpd with --reporters ai on the… → Parse each clone line to identify the… → Read both code fragments from the source… → …
  • Cleaning up duplicated code that jscpd reported
  • SKILL.md covers Prerequisites, Workflow, Refactoring Strategies and Tips
  • Calls npx

What it does

After running the jscpd copy-paste detector, this skill guides the agent through removing the duplication it found. The detector's AI reporter output is parsed clone by clone, and larger codebases can add a summary that ranks hotspot files and folders by the share of duplicated code.

Exact copies come first, since those are nearly always real copy-paste. Renamed copies and near-miss clones, where a few statements were edited, are noisier and are run only afterward, one family at a time, and treated as leads to read rather than defects. For each clone the agent reads both fragments, lists exactly what differs, and picks a strategy such as extract function, parameterize, move to a module, extract a constant or introduce a base class. A cross-format option catches clones that span languages like JavaScript and TypeScript.

When your agent uses it

  • Cleaning up duplicated code that jscpd reported
  • Choosing where to start from a duplication hotspot summary
  • Merging near-identical functions that differ only in names or values
  • Extracting repeated blocks into shared functions or modules

Example prompts

  • “Run jscpd on src and refactor the exact duplicates first.”
  • “Which files have the highest duplication percentage? Start with those hotspots.”
  • “These two functions are near-identical except for the endpoint; parameterize them.”
  • “Extract the repeated validation block into a shared function.”

Requirements

  • Node.js, to run jscpd through npx

Workflow steps

9 steps, taken from the first numbered list in SKILL.md.

  1. Run jscpd with --reporters ai on the target path (add --summary on larger codebases to pick a starting point: files with high dup% and…
  2. Parse each clone line to identify the two duplicated locations (file + line range) and its kind: no suffix is an exact copy, (renamed)…
  3. Read both code fragments from the source files
  4. Understand what the duplicated code does, and for renamed and similar clones list exactly what differs between the two sides
  5. Triage renamed and similar clones before touching them. Skip the pair, and say so, when any of these holds: the two sides do different…
  6. Design a refactoring: extract a shared function, class, module, or constant; the kind decides the strategy (below)
  7. Apply the refactoring — update both locations and all other usages
  8. 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…
  9. Repeat for remaining clones, highest-impact first: exact clones, then renamed, then similar. Report the skipped candidates separately from…

What it can do on your machine

Read from SKILL.md and the folder at commit 14bc176. 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

DRY Refactoring With jscpd loads about 2.1k tokens when it runs. Until then it costs about 65 tokens; SKILL.md has 1,020 words of instructions outside code blocks.

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

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 14bc176, republished under its MIT licence (© kucherenko). 1,020 words, ~2,112 tokens.

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

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:

bash
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:

bash
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:

bash
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:

bash
# 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/Python 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 <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

  1. 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 token counts pay off most)
  2. 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
  3. Read both code fragments from the source files
  4. Understand what the duplicated code does, and for renamed and similar clones list exactly what differs between the two sides
  5. 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 switch over 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 like processData; 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
  6. Design a refactoring: extract a shared function, class, module, or constant; the kind decides the strategy (below)
  7. Apply the refactoring — update both locations and all other usages
  8. 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-identifiers again
  9. 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
Show full SKILL.md (516 more words)Show less

Refactoring Strategies

Extract function — when the duplicate is a block of logic:

ts
// Before: same block in two places
// After: shared function called from both places

Extract module/utility — when the duplicate spans multiple files in different domains:

ts
// Move shared logic to a shared utility file and import it

Extract 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:

ts
// 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 object

A 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:

ts
// 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 call

If 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:

ts
// 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 both

Below 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 .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
  • 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
  • --similarity covers JavaScript, TypeScript, Python, Java, Kotlin, Scala, C#, Go, Rust, C, C++, PHP, Ruby, Swift and Clojure, also inside Markdown code blocks and Vue, Svelte and Astro scripts; for other languages rely on the exact and --max-gap-lines passes
  • Use --min-lines 10 to filter noise and focus on meaningful duplications
  • Keep a separate --baseline per set of detection flags when gating CI: renamed and similar runs fingerprint clones differently from exact runs

© 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/dry-refactoring of kucherenko/jscpd.

Open the folder on GitHubat commit 14bc176

Compare with similar skills

DRY Refactoring With jscpd 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.

DRY Refactoring With jscpd compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
DRY Refactoring With jscpd this skillkucherenko/jscpd6.4k—~2.1kAutomated safety check: PassMIT
Dead Code Removal with Knipshift-editor/shift348—~1.8kAutomated safety check: PassApache-2.0
Code RefinerMathews-Tom/armory328—~3.1kAutomated safety check: PassMIT
Typescript Best Practicesjwynia/agent-skills169—~2.5kAutomated safety check: PassMIT
Code ReviewerLeoYeAI/openclaw-master-skills2.2k1 repos~1.2kAutomated safety check: PassMIT
Typescript Writeaiskillstore/marketplace4302 repos~1.7kAutomated safety check: PassNone

Similar skills

  • Dead Code Removal with Knip

    shift-editor/shift

    Finds unused files, exports and class members with Knip, then verifies each candidate through reference tracing before removing anything, never using knip --fix.

    348 GitHub stars~1.8k tokensUpdated today
    DevelopmentAuto-check passed
  • Code Refiner

    Mathews-Tom/armory

    Deep code simplification and refactoring preserving behavior across Python, Go, TypeScript, Rust.

    328 GitHub stars~3.1k tokensUpdated 3 days ago
    DevelopmentAuto-check passed
  • Typescript Best Practices

    jwynia/agent-skills

    Guide AI agents through TypeScript coding best practices including type safety, error handling, code organization, and architecture patterns.

    169 GitHub stars~2.5k tokensUpdated 7 mo ago
    DevelopmentAuto-check passed
  • Code Reviewer

    LeoYeAI/openclaw-master-skills

    Code review automation for TypeScript, JavaScript, Python, Go, Swift, Kotlin.

    2.2k GitHub starsUsed in 1 repo~1.2k tokens
    DevelopmentAuto-check passed
  • Typescript Write

    aiskillstore/marketplace

    Write TypeScript and JavaScript code following Metabase coding standards and best practices.

    430 GitHub starsUsed in 2 repos~1.7k tokens
    DevelopmentAuto-check passed
  • Code Reviewer

    borghei/Claude-Skills

    Code review automation for TypeScript, JavaScript, Python, Go, Swift, and Kotlin.

    886 GitHub stars~1.7k tokensUpdated yesterday
    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.4k 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.4k GitHub stars~3.2k tokensUpdated today
    Auto-check passed
  • 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.

    6.4k GitHub stars~2.5k 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.4k GitHub stars~4.5k tokensUpdated today
    Auto-check passed

Categories

Questions about DRY Refactoring With jscpd

What does DRY Refactoring With jscpd do?

Removes copy-paste duplication found by jscpd, starting with exact clones and hotspots, then renamed and near-miss copies, using proven refactoring strategies. After running the jscpd copy-paste detector, this skill guides the agent through removing the duplication it found. The detector's AI reporter output is parsed clone by clone, and larger codebases can add a summary that ranks hotspot files and folders by the share of duplicated code.

When should I use DRY Refactoring With jscpd?

DRY Refactoring With jscpd fits situations like: cleaning up duplicated code that jscpd reported; choosing where to start from a duplication hotspot summary; merging near-identical functions that differ only in names or values; extracting repeated blocks into shared functions or modules.

How do I install DRY Refactoring With jscpd in Claude Code?

Run `npx skills add kucherenko/jscpd --skill dry-refactoring -a claude-code`. Or copy the skill folder (skills/dry-refactoring in kucherenko/jscpd) into .claude/skills/dry-refactoring in your project. Claude Code loads it when a task matches its description.

How do I install DRY Refactoring With jscpd in Codex?

Run `npx skills add kucherenko/jscpd --skill dry-refactoring -a codex`. Or copy the skill folder (skills/dry-refactoring in kucherenko/jscpd) into .agents/skills/dry-refactoring in your project. Codex loads it when a task matches its description.

Can I use DRY Refactoring With jscpd 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 dry-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/dry-refactoring, .gemini/skills/dry-refactoring, .github/skills/dry-refactoring and .opencode/skills/dry-refactoring in your project.

What does DRY Refactoring With jscpd need to run?

Going by SKILL.md and its folder, DRY Refactoring With jscpd needs the command-line tools its instructions call (npx). Our summary lists: Node.js, to run jscpd through npx.

Does DRY Refactoring With jscpd 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 DRY Refactoring With jscpd 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 DRY Refactoring With jscpd use?

DRY Refactoring With jscpd 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 DRY Refactoring With jscpd use?

About 2.1k tokens (SKILL.md is roughly 8.4k 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 DRY Refactoring With jscpd?

Skills that share tags, products or a category with DRY Refactoring With jscpd: Dead Code Removal with Knip (shift-editor/shift, 348 stars), Code Refiner (Mathews-Tom/armory, 328 stars), Typescript Best Practices (jwynia/agent-skills, 169 stars) and Code Reviewer (LeoYeAI/openclaw-master-skills, 2.2k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains DRY Refactoring With jscpd?

kucherenko (a GitHub user) maintains it in kucherenko/jscpd, which has 6,361 GitHub stars. The repository holds 5 skills in this directory. The repository was last updated on October 9, 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.