Getting Started

Agent Skill

Use jscpd with AI coding assistants to automatically detect and refactor code duplications.

Overview

jscpd ships two agent skills for skills.sh that teach AI coding assistants (Claude, Copilot, Gemini, Cursor, and others) how to detect and eliminate code duplication:

  1. jscpd — tool reference skill. Covers all CLI options, the AI reporter output format, and configuration file syntax.
  2. dry-refactoring — refactoring workflow skill. A guided process for reading clone output, choosing the right extraction strategy, applying the refactor, and verifying the clone is eliminated.

Installation

Terminal
# Install both skills
npx skills add kucherenko/jscpd

# Or install individually
npx skills add kucherenko/jscpd --skill jscpd
npx skills add kucherenko/jscpd --skill dry-refactoring

Once installed, ask your agent to "find and fix code duplication" and it will invoke jscpd with the right options and act on the results.

jscpd Skill

The jscpd skill instructs the agent to:

  1. Run jscpd with the ai reporter on the target path
  2. Parse the detected clone pairs (file paths + line ranges)
  3. Report back with a summary of duplications

Key Options

OptionDescription
--reporters aiUse the AI-optimized reporter (compact clone list)
--reporters htmlGenerate HTML report
--min-tokens NMinimum tokens for a duplication (default: 50)
--min-lines NMinimum lines for a duplication (default: 5)
--ignore "glob"Ignore patterns (comma-separated)
--format "list"Limit to specific languages
--store "type"Accepted for compatibility; external stores not available in v5 (detection is fast enough)
--store-path "path"Accepted for compatibility; not used in v5
--noTipsDisable tips in output (also suppressed by --silent)
--skipCommentsAlias for --mode weak (strip comments before detection)
--formats-names "map"Map filenames to formats
--mode "mode"Detection quality: strict, mild, weak
--blameBlame authors of duplications from git
--silentDo not write detection progress and results to console
--absoluteUse absolute paths in reports
--ignoreCaseIgnore case of symbols in code (experimental)
--exitCode NExit code when duplications are detected
--verboseShow full information during detection process

Example Configuration

.jscpd.json
{
  "threshold": 0,
  "reporters": ["ai"],
  "ignore": ["**/node_modules/**", "**/dist/**", "**/*.min.*"],
  "format": ["typescript", "javascript"],
  "minLines": 5,
  "minTokens": 50,
  "output": "./reports/jscpd"
}

dry-refactoring Skill

The dry-refactoring skill guides the agent through eliminating duplications:

  1. Run jscpd with --reporters ai on the target path
  2. Parse each clone line to identify the two duplicated locations (file + line range)
  3. Read both code fragments from the source files
  4. Understand what the duplicated code does
  5. Design a refactoring — extract a shared function, class, module, or constant
  6. Apply the refactoring — update both locations and all other usages
  7. Re-run jscpd to confirm the clone is eliminated
  8. Repeat for remaining clones, highest-impact first

Refactoring Strategies

StrategyWhen to use
Extract functionDuplicate is a block of logic
Extract module/utilityDuplicate spans multiple files in different domains
Extract constant/configDuplicate is repeated data or configuration
Template/base classDuplicate has a repeated class shape

Tips

  • Start with clones that have the highest line count — most impact
  • A clone between test files may indicate a missing test helper
  • Clones across unrelated modules may signal a missing shared utility
  • Use --min-lines 10 to filter noise and focus on meaningful duplications

How It Uses the AI Reporter

The skills use the ai reporter, which produces compact, token-efficient output:

Terminal
npx jscpd --reporters ai ./src

Example output:

Clones:
src/utils/ auth.ts:10-25 ~ helpers.ts:40-55
src/utils/auth.ts 30-45 ~ 80-95
---
2 clones · 3.1% duplication

This format uses ~79% fewer tokens than the default reporter, keeping context usage low while giving the agent everything it needs to locate and fix each duplication.

More Information