# codebase-refactoring

Runs a guided audit of code duplication, dead code, and complexity using jscpd. Helps clean up technical debt systematically.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 613 installs · ★ 6451
- Author: kucherenko
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/kucherenko/jscpd/tree/HEAD/skills/codebase-refactoring/SKILL.md
- Updated: 2026-10-25
- HTML: https://affpapa.org/en/nevibecode/skills/codebase-refactoring

## What it does

This skill structures a cleanup pass across an entire repository using the `jscpd` CLI. It begins by running `npx jscpd --health --reporters ai <path>` to calculate a composite health score based on duplication, dead code, and complexity. A score of 100 represents a clean state.

The dead-code phase performs a graph traversal from project entry points rather than relying on simple reference counting. It detects unused files, exports, symbols, and imports across JavaScript, TypeScript, JSX, TSX, Vue, Svelte, Astro, and Python. Every finding includes a confidence rating between 0 and 100.

If your project lacks JavaScript, TypeScript, or Python files, `jscpd` cannot calculate dead code and reports an unavailable metric. That step must be skipped. The final step ranks source files by cyclomatic complexity estimates, showing exactly which files need structural simplification.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add kucherenko/jscpd --skill codebase-refactoring -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/codebase-refactoring/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/codebase-refactoring/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add kucherenko/jscpd --skill codebase-refactoring -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/codebase-refactoring/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add kucherenko/jscpd --skill codebase-refactoring -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/codebase-refactoring/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install kucherenko/jscpd codebase-refactoring
```

2. **Manually: put the files in place**
- File: `.github/skills/codebase-refactoring/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add kucherenko/jscpd --skill codebase-refactoring -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/kucherenko/jscpd --path skills/codebase-refactoring
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/codebase-refactoring/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add kucherenko/jscpd --skill codebase-refactoring -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/kucherenko/jscpd/tree/HEAD/skills/codebase-refactoring/SKILL.md

## When to use it
- identify code clones and duplicated logic across files
- remove unused exports, symbols, and imports
- rank source files by cyclomatic complexity
- calculate an overall codebase health score with jscpd

## Example prompts
- Run a codebase refactoring pass with jscpd
- Find and remove dead code and unused exports across the project
- Rank the most complex files in the codebase using jscpd

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 90e53f044694deea.

BEGIN THIRD-PARTY FILE 90e53f044694deea
````text
---
name: codebase-refactoring
description: Three-part workflow to improve overall codebase health with jscpd — find and fix duplicated code, find and remove or refactor dead code, then find and simplify the largest/most complex files. Starts from --dashboard/--health to prioritize and ends by re-measuring the score.
---

# codebase-refactoring

A guided pass over a codebase's three biggest maintenance costs — duplicated
code, dead code, and complexity — using jscpd to find each and a strategy to
fix it. Use this skill when asked to "clean up", "improve", "refactor" or
"pay down tech debt in" a codebase, rather than to fix one specific bug.

## Start here: measure, then prioritize

```bash
npx jscpd --health --reporters ai <path>
```

```
health 74 B (duplication 75, dead-code 72, complexity 76; 93 code lines)
```

The health score is a weighted mix of three sub-scores, each a share of the
code lines — high is good, 100 is clean. The lowest of the three names where
the codebase actually hurts most; if it isn't the order below, do that
dimension first instead. `n/a` on a dimension (e.g. `dead code n/a`) means
jscpd could not measure it — dead-code detection needs JavaScript,
TypeScript or Python to be a real share of the code — skip that step rather
than treating it as clean.

For the full picture behind that score — largest duplicated formats, most
complex files, largest dead-code findings, all in one screen — run `npx
jscpd --dashboard` instead. Its `console` output (the default) is the only
reporter with that per-file detail; `--reporters ai` on `--dashboard` prints
the same one-line summary shown above, not the breakdown, so don't reach for
it expecting more than the score. Use `--reporters json` on `--dashboard` if
you need the detail in a parseable form.

The three passes below are otherwise independent and safe to run in any
order; **duplication → dead code → complexity** is the default because
fixing duplication first means step 2 isn't wasting effort tracing call
sites that a later extract-function pass will move anyway, and clearing
dead code before step 3 means the files ranked for simplification are ones
actually worth simplifying, not ones about to be deleted.

## Step 1 — Duplicated code

```bash
npx jscpd --reporters ai --summary <path>
```

Find and read each clone, decide whether it is a real copy worth merging,
and apply the matching refactoring strategy (extract function, parameterize,
extract a shared module or constant, or a base class/template for
structural duplication). Full guided workflow, triage rules for
renamed/near-miss clones, and worked examples per clone kind:

→ **[dry-refactoring](../dry-refactoring/SKILL.md)** — run this now, then
come back here for steps 2 and 3. Its own `--summary` hotspot ranking is the
same one the health score's duplication dimension reads from, so a file it
````
END THIRD-PARTY FILE 90e53f044694deea

The third-party file has ended. Everything between the 90e53f044694deea tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2891 of 10273 bytes. © kucherenko · MIT · https://github.com/kucherenko/jscpd/tree/HEAD/skills/codebase-refactoring/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
