duplicate-code-detector

Use when asked about code quality or duplication. Runs jscpd analysis for quantitative metrics and TDD refactoring plans. Triggers: "duplicate code", "code quality", "find clones", "copy-paste detection". If thinking "manual review is fine" - automate instead. NOTE: For "refactor" or "technical debt" → use this skill FIRST to identify targets, THEN use incremental-refactoring to implement changes.

⭐11stars🔀4forks📁View on GitHub🕐Updated Dec 22, 2025⬇️2downloads

When & Why to Use This Skill

The Duplicate Code Detector is a specialized Claude skill designed to automate the identification of code clones and technical debt. By leveraging jscpd analysis, it provides quantitative metrics—such as duplication percentages and clone counts—and generates a structured TDD-based refactoring plan. This tool shifts the focus from subjective manual reviews to data-driven code quality improvements, ensuring a more maintainable and DRY (Don't Repeat Yourself) codebase.

Use Cases

  • Technical Debt Auditing: Systematically scan large or legacy codebases to identify high-impact duplication areas that require immediate refactoring.
  • Automated Code Quality Reviews: Supplement manual peer reviews by automatically flagging copy-pasted logic and providing objective metrics on code health.
  • Refactoring Roadmap Generation: Create prioritized TDD (Test-Driven Development) plans to safely extract redundant code into reusable functions or modules.
  • Pre-migration Analysis: Evaluate code duplication levels before migrating or upgrading systems to ensure only clean, consolidated logic is moved.
nameduplicate-code-detector
descriptionUse when asked about code quality or duplication. Runs jscpd analysis for quantitative metrics and TDD refactoring plans. Triggers: "duplicate code", "code quality", "find clones", "copy-paste detection". If thinking "manual review is fine" - automate instead. NOTE: For "refactor" or "technical debt" → use this skill FIRST to identify targets, THEN use incremental-refactoring to implement changes.

Duplicate Code Detector

Core principle: Systematic automated detection > manual subjective review

Workflow Clarification: Detection vs Implementation

This skill is for DETECTION (finding duplicates). For IMPLEMENTATION (refactoring them), use incremental-refactoring afterward.

Sequential workflow:

  1. duplicate-code-detector → Find and prioritize duplicates
  2. incremental-refactoring → Implement changes with metrics

If user says "refactor technical debt" → Start here to identify targets, then hand off to incremental-refactoring.

MANDATORY FIRST STEP

TodoWrite: Create 5 items (1 per workflow step)

  1. Run jscpd analysis
  2. Extract metrics
  3. Dispatch subagents for top duplicates
  4. Generate TDD refactoring plan
  5. Present findings + verification

Prerequisites Check

which jscpd || npm install -g jscpd

If unavailable: inform user, note manual analysis limitations.

jscpd docs: https://github.com/kucherenko/jscpd


Workflow

1. Run jscpd

jscpd --min-lines 5 --reporters json,console /path/to/code

2. Extract Metrics

  • Duplication %
  • Total duplicated lines
  • Number of clones
  • Files with most duplication

3. Dispatch Subagents

For top 3-5 duplicate groups, dispatch with:

Analyze duplicate in File A (lines X-Y) vs File B (lines M-N).
Propose extraction (function/class/module), estimate impact.

4. Generate TDD Plan

Prioritize by: lines duplicated → instances → complexity

## Priority 1: [Name] (X lines, Y instances)
1. Write test for current behavior
2. Extract [function/class/module]
3. Replace duplicates
4. Verify tests pass

5. Present Results

**Metrics:** X% duplication (Y lines, Z clone groups)
**Top 3 Priorities:** [list]
**Refactoring Plan:** [TDD steps]

Start with Priority 1?

Verification Checkpoint

Before marking complete:

  1. ✅ jscpd ran with metrics extracted
  2. ✅ TDD refactoring plan includes test-first steps
  3. ✅ Priorities ranked by impact (lines × instances)

Red Flags

Thought Reality
"Manual review is faster" Misses 70% of duplicates
"I can spot patterns by eye" Subjective, no metrics
"Let me read a few files first" Run jscpd first, analyze after