Source profileQuality 95/100

terrylica/cc-skills/plugins/quality-tools/skills/code-clone-assistant/SKILL.md

code-clone-assistant

Detect and refactor code duplication with PMD CPD. TRIGGERS - code clones, DRY violations, duplicate code.

Source repository stars
62
Declared platforms
1
Static risk flags
0
Last source update
2026-08-24
Source checked
2026-08-25

Decision brief

What it does: where it fits

Detect code clones and guide refactoring using PMD CPD (exact duplicates) + Semgrep (patterns).

Best for

  • Finding duplicate code in a codebase
  • Detecting DRY violations
  • Refactoring similar code patterns

Not for

  • Tasks that require unconfirmed production actions or broad system permissions.
  • Environments where the pinned source and install steps cannot be inspected.

Compatibility matrix

Platform support, with evidence labels

PlatformStatusEvidenceWhat to check
CodexNot declaredNo explicit evidencePortability before use
Claude CodeDeclaredSource recordInstall path and trigger
CursorNot declaredNo explicit evidencePortability before use
Gemini CLINot declaredNo explicit evidencePortability before use
Open the compatibility checker

Installation

Inspect first. Install second.

The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.

Source-detected install commandSource
npx skills add https://github.com/terrylica/cc-skills --skill "plugins/quality-tools/skills/code-clone-assistant"
Safe inspection promptEditorial

Inspect the Agent Skill "code-clone-assistant" from https://github.com/terrylica/cc-skills/blob/a5f847b22ee5afa35677e446973a903d098cd1d4/plugins/quality-tools/skills/code-clone-assistant/SKILL.md at commit a5f847b22ee5afa35677e446973a903d098cd1d4. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.

Workflow

What the source asks the agent to do

  1. 01

    Quick Start Workflow

    Review the “Quick Start Workflow” section in the pinned source before continuing.

    Review and apply the “Quick Start Workflow” source section.
  2. 02

    Step 1: Detect exact duplicates (PMD CPD)

    pmd cpd -d . -l python --minimum-tokens 20 -f markdown pmd-results.md

    pmd cpd -d . -l python --minimum-tokens 20 -f markdown pmd-results.md
  3. 03

    Step 2: Detect pattern violations (Semgrep)

    semgrep --config=clone-rules.yaml --sarif --quiet semgrep-results.sarif

    semgrep --config=clone-rules.yaml --sarif --quiet semgrep-results.sarif
  4. 04

    Step 3: Analyze combined results (Claude Code)

    Review the “Step 3: Analyze combined results (Claude Code)” section in the pinned source before continuing.

    Review and apply the “Step 3: Analyze combined results (Claude Code)” source section.
  5. 05

    Step 4: Refactor (Claude Code with user approval)

    Review the “Step 4: Refactor (Claude Code with user approval)” section in the pinned source before continuing.

    Review and apply the “Step 4: Refactor (Claude Code with user approval)” source section.

Permission review

Static risk signals and limitations

No configured static risk pattern was detected

This is not proof of safety. Runtime behavior, indirect dependencies, and hidden external systems are outside the static scan.

Evidence record

Why each signal appears

EvidenceSourceComputedTestedEditorial
SignalValueEvidence typeMeaning
Quality score95/100ComputedDocumentation, specificity, maintenance, and trust rules
Repository stars62SourceRepository attention, not individual Skill quality
Compatibility1 platformsSourceDeclared in the catalog source record
Usage guideautomated source guideEditorialGenerated or reviewed according to the visible evidence level

Pinned source

Provenance and original SKILL.md

Repository
terrylica/cc-skills
Skill path
plugins/quality-tools/skills/code-clone-assistant/SKILL.md
Commit
a5f847b22ee5afa35677e446973a903d098cd1d4
License
MIT
Collected
2026-08-25
Default branch
main
View the original SKILL.md

Code Clone Assistant

Detect code clones and guide refactoring using PMD CPD (exact duplicates) + Semgrep (patterns).

Self-Evolving Skill: This skill improves through use. If instructions are wrong, parameters drifted, or a workaround was needed — fix this file immediately, don't defer. Only update for real, reproducible issues.

Tools

  • PMD CPD v7.17.0+: Exact duplicate detection
  • Semgrep v1.140.0+: Pattern-based detection

Tested: October 2025 - 30 violations detected across 3 sample files Coverage: ~3x more violations than using either tool alone


When to Use This Skill

Use this skill when:

  • Finding duplicate code in a codebase
  • Detecting DRY violations
  • Refactoring similar code patterns
  • Identifying copy-paste code

Why Two Tools?

PMD CPD and Semgrep detect different clone types:

AspectPMD CPDSemgrep
DetectsExact copy-paste duplicatesSimilar patterns with variations
ScopeAcross files ✅Within/across files (Pro only)
MatchingToken-based (ignores formatting)Pattern-based (AST matching)
Rules❌ No custom rules✅ Custom rules

Result: Using both finds ~3x more DRY violations.

Clone Types

TypeDescriptionPMD CPDSemgrep
Type-1Exact copies✅ Default
Type-2Renamed identifiers--ignore-*
Type-3Near-miss with variations⚠️ Partial✅ Patterns
Type-4Semantic clones (same behavior)

Quick Start Workflow

# Step 1: Detect exact duplicates (PMD CPD)
pmd cpd -d . -l python --minimum-tokens 20 -f markdown > pmd-results.md

# Step 2: Detect pattern violations (Semgrep)
semgrep --config=clone-rules.yaml --sarif --quiet > semgrep-results.sarif

# Step 3: Analyze combined results (Claude Code)
# Parse both outputs, prioritize by severity

# Step 4: Refactor (Claude Code with user approval)
# Extract shared functions, consolidate patterns, verify tests


Accepted Exceptions (Known Intentional Duplication)

Not all code duplication is a problem. Some codebases deliberately use copy-and-adapt patterns where refactoring would be harmful. When running clone detection, always check for accepted exceptions before recommending refactoring.

When Duplication Is Acceptable

PatternWhy AcceptableExample
Generation-per-directory experimentsEach generation is an immutable, self-contained experiment. Sharing code across generations would break provenance and make past experiments non-reproducible.SQL templates, sweep scripts where each gen{NNN}/ is independent
SQL templates with placeholder substitutionSQL has no import/include mechanism. Templates use sed placeholder replacement (__PLACEHOLDER__), not function calls. Extracting shared CTEs into separate files would break the single-file execution model.ClickHouse sweep templates sharing signal detection + metrics CTEs
Protocol/schema boilerplateSerialization formats, API contracts, and wire protocols require exact structure in each location. Abstracting them hides the contract.NDJSON telemetry line construction in wrapper scripts
Test fixtures and golden filesTest data intentionally duplicates production patterns to verify behavior. Sharing fixtures creates brittle cross-test dependencies.Test setup code, expected output snapshots

How to Report Accepted Exceptions

When clone detection finds duplication that matches an accepted exception pattern:

  1. Report it — always show the user what was found (lines, tokens, files)
  2. Flag as accepted — explicitly state it matches a known exception pattern
  3. Explain why — cite the specific reason refactoring is not recommended
  4. Do NOT recommend refactoring — this is the key difference from actionable findings

Example output format:

Code Clone Analysis Results

PMD CPD Findings:
  Clone 1: 115 lines (575 tokens) — base_bars → signals CTEs
    gen610_template.sql:33 ↔ gen710_template.sql:38
    Status: ACCEPTED EXCEPTION (generation-per-directory experiment)
    Reason: Each generation is immutable. Shared CTEs would break
            experiment provenance and reproducibility.

  Clone 2: 36 lines (478 tokens) — metrics aggregation
    gen610_template.sql:207 ↔ gen710_template.sql:244
    Status: ACCEPTED EXCEPTION (SQL template without include mechanism)

Actionable Findings: 0
Accepted Exceptions: 2

Project-Level Exception Configuration

Projects can declare accepted exception patterns in their CLAUDE.md:

## Code Clone Exceptions

- `sql/gen*_template.sql` — generation-per-directory experiments (immutable)
- `scripts/gen*/` — copy-and-adapt sweep scripts (no shared infrastructure)
- `tests/fixtures/` — intentional duplication for test isolation

When this section exists in a project's CLAUDE.md, the code-clone-assistant should check it before classifying findings.


Reference Documentation

For detailed information, see:


Troubleshooting

IssueCauseSolution
PMD CPD not foundNot installed or not in PATHbrew install pmd or download from PMD releases
Semgrep timeoutLarge codebase scanUse --exclude to limit scope
No duplicates detectedminimum-tokens too highLower --minimum-tokens value (try 15)
Too many false positivesminimum-tokens too lowIncrease --minimum-tokens (try 30+)
Language not recognizedWrong -l flagCheck PMD CPD supported languages list
SARIF parse errorSemgrep output malformedUpgrade Semgrep to latest version
Memory error on large repoJava heap too smallSet PMD_JAVA_OPTS=-Xmx4g
Missing clone rules fileCustom rules not createdCreate clone-rules.yaml or use default config

Post-Execution Reflection

After this skill completes, check before closing:

  1. Did the command succeed? — If not, fix the instruction or error table that caused the failure.
  2. Did parameters or output change? — If the underlying tool's interface drifted, update Usage examples and Parameters table to match.
  3. Was a workaround needed? — If you had to improvise (different flags, extra steps), update this SKILL.md so the next invocation doesn't need the same workaround.

Only update if the issue is real and reproducible — not speculative.

Frequently asked questions

What to verify before installation and use

What does the code-clone-assistant source document cover?

Detect code clones and guide refactoring using PMD CPD (exact duplicates) + Semgrep (patterns).

How do I install code-clone-assistant?

The source record exposes this install command: npx skills add https://github.com/terrylica/cc-skills --skill "plugins/quality-tools/skills/code-clone-assistant". Inspect the command and pinned source before running it.

Which Agent platforms does the source record declare?

The pinned source record declares support for: claude code.

Alternatives

Compare before choosing