Getting Started

Agent Skill

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

Overview

jscpd includes an agent skill for skills.sh that teaches AI coding assistants (Claude, Copilot, Gemini, Cursor, and others) how to detect and eliminate code duplication automatically.

Installation

Terminal
npx skills add kucherenko/jscpd

Once installed, the skill is available to your AI assistant in any project.

What the Skill Does

When activated, the 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. Read both duplicated code fragments from the source files
  4. Design a refactoring — extracting a shared function, module, constant, or base class
  5. Apply the refactoring and update all call sites
  6. Re-run jscpd to confirm the duplication is eliminated
  7. Repeat for remaining clones, highest-impact first

How It Uses the AI Reporter

The skill uses the ai reporter, which produces compact, token-efficient output optimized for agent consumption:

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