# Dry Refactoring

Guided workflow to eliminate copy-paste duplication detected by jscpd.

- Repository: https://github.com/kucherenko/jscpd (6480 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-10-30
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add kucherenko/jscpd --skill dry-refactoring -g -a claude-code -y`
Codex: `npx skills add kucherenko/jscpd --skill dry-refactoring -g -a codex -y`
Cursor: `npx skills add kucherenko/jscpd --skill dry-refactoring -g -a cursor -y`
Gemini CLI: `npx skills add kucherenko/jscpd --skill dry-refactoring -g -a gemini-cli -y`

## 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.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# dry-refactoring

Guided workflow to eliminate copy-paste duplication in source code. Use after running [jscpd](../jscpd/SKILL.md) 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](../jscpd/SKILL.md)** skill for full option reference, including cross-format group syntax, the clone-kind suffixes and how to read the summary.

## Workflow

The rest: https://github.com/kucherenko/jscpd/blob/HEAD/skills/dry-refactoring/SKILL.md
