/code-metrics:audit-duplication [--json] [--keep] [--all] [--base <ref>] [--registry <file>] [<path>...] [--repo <repo> ...]from code-metrics
Measures duplicated code and copy-paste clone groups across a change, path, or tree using jscpd, dupl, or PMD CPD. Reports clone instances excluding repo-sanctioned replication without pass/fail verdicts.
Ships in code-metrics. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Current branch: !git branch --show-current 2>/dev/null || echo "unknown"
Duplication is the measure most likely to report noise, because some replication is deliberate: a repository that vendors one helper into seventeen plugins on purpose has seventeen copies and zero debt. This skill reports the clone groups a detector found, then subtracts the groups the target repository has already declared about itself, and stops there: no pass or fail, no severity, no finding. What to do about a surviving clone is the reader's call.
Collectors, tried in ladder order per language:
| Collector | Languages | Values per clone group | When |
|---|---|---|---|
jscpd | every language | lines, tokens | jscpd resolves on PATH or in ./node_modules/.bin |
dupl | Go only | lines, tokens null | jscpd did not resolve and dupl did |
cpd (PMD) | TypeScript/JavaScript, Python, Go, C# | lines, tokens | jscpd did not resolve and pmd did (never for Bash: CPD has no shell language) |
No collector resolves means the language's row says so with the tool's install hint and the run
continues. This plugin never installs, downloads, or npx-fetches a detector.
"${CLAUDE_SKILL_DIR}/scripts/audit-duplication.sh" # the change: diff from the merge-base plus uncommitted files
"${CLAUDE_SKILL_DIR}/scripts/audit-duplication.sh" src/ lib/ # explicit paths (a missing one is a usage error)
"${CLAUDE_SKILL_DIR}/scripts/audit-duplication.sh" --all # every tracked or untracked-but-not-ignored file
"${CLAUDE_SKILL_DIR}/scripts/audit-duplication.sh" --registry scripts/cross-plugin-source-registry.txt --all
"${CLAUDE_SKILL_DIR}/scripts/audit-duplication.sh" --json --all src/ # the code-metrics/v3 document instead of markdown
"${CLAUDE_SKILL_DIR}/scripts/audit-duplication.sh" --json --keep --all # the document, also kept as the next run's trend baseline
Append --user-file '${user_config.config_file}' to every script call, exactly as written:
it names the file holding your userConfig layer, and an empty or unsubstituted value means none
(${CLAUDE_PLUGIN_ROOT}/reference/config.md).
A target form (--repo <repo> and the others) runs the script once per repository, as
${CLAUDE_PLUGIN_ROOT}/reference/several-repositories.md says, and never passes the form to the
script. Each run finds clones within its own repository and keeps its own trend baseline, and
each registry path, named or configured, resolves against that repository's root. A file copied between repositories is not this script's to find: /coupling:reduce (if enabled)
measures it.
Present the markdown report as printed. It opens with the scope and a "Coverage of this run"
table (language, collector, status, reason), then one row per clone group, largest first, listing
every instance as file:start-end, then a rollup per language and per directory, then the summary
lines: files with clones, the duplicated-line total, how many groups a registry excluded, and
which languages were partial. Files with clones leaves out any file holding nothing but excluded
groups; the scope's count keeps it. When an earlier report of this project with the same scope
mode was kept, the last line is the clone trend: this run's class count, the previous run's, and
the signed delta, then how many classes are new since that run and how many gained copies
(trend in the JSON); the first run in a project prints none. When the report opens with No clone detector ran in any language, offer the user the install command that headline carries (npm install -g jscpd, or a
devDependency) and run it only when they confirm; never install silently and never npx-fetch it.
Keep the --json document when the numbers feed a comparison:
/verification:measure metrics (if enabled) consumes it (treat a
report whose status is empty on either side as INCONCLUSIVE); otherwise keep the JSON beside
your notes and compare by hand.
over_reference.jscpd and PMD CPD report clones as pairs, so
seventeen identical copies arrive as sixteen two-instance rows; this skill merges rows that
share an instance with an identical file and line range into one row per class before it
counts anything. Copies that share only part of a fragment are named with different ranges and
stay separate groups: the merge joins on identity, never on overlap, so a class is never wider
than what the detector called identical.summary.duplicated_lines counts each class once, using the length of the class, not the sum
over its instances: three copies of a 41-line block are 41 duplicated lines, not 82 or 123. The
count is what survived the registries.summary.by_language and summary.by_directory roll the surviving classes up: each maps to
{groups, duplicated_lines}, the directory map for . and every ancestor of each class's first
instance. A class counts once under every ancestor, so a parent includes its children and the
directory rows cannot be summed; by_directory["."] and the per-language sum both restate the
totals. The markdown lists directories to duplication.rollup_depth; the JSON carries all.duplication.max_size (or longer than duplication.max_lines, when set) is
left out of the scan and never silently dropped: the language's run row is partial with how many
files were skipped and the largest one, the document is partial, and the summary carries a
Partial: line naming the language.excluded[] with the registry path, the 1-based line
number, and the line's text. A group is excluded only when one registry line accounts for every
instance and each instance sits under a different carrying directory; two copies inside one
directory are ordinary duplication and stay.summary.clone_groups
with the newest earlier kept document of the same project and scope mode that measured
something, and lists the classes new since then (trend.new_classes) and the classes that
gained copies (trend.grown_classes), so no reader has to open the earlier document. It is a
count with no bar. A markdown run keeps its document as the next run's baseline; a --json run
keeps it only with --keep. An earlier file that is not a regular file under 5 MB, or whose
fields are malformed, is passed over for the next older one. Field details:
${CLAUDE_PLUGIN_ROOT}/reference/report-schema.md ("Clone trend").null, never 0: dupl reports no token count, so
its rows carry tokens: null.status is complete when every language in scope was measured, partial when one was not or
when a cap left files out of one, and empty when nothing was; a run that measured nothing
prints "Measured nothing" and states no duplication figure at all, which is not the same as zero
duplication. A language that skipped every file is still partial: its row says what was skipped.empty one; exit 2 for a usage error such
as a named registry or scope path that does not exist; exit 3 when a detector resolved but
produced nothing parseable, with its stderr in the run table. A detector's own non-zero exit is
not a failure when it produced a report.Everything tunable resolves through the code-metrics layers (team
docs/conventions/code-metrics.yaml, personal override docs/conventions/code-metrics.local.yaml; per-key override; keys in ${CLAUDE_PLUGIN_ROOT}/reference/config.md):
duplication.min_tokens, duplication.min_lines,
duplication.ignore (globs handed to the detector's own ignore option), duplication.max_size
(binary units; a larger file is left out of the scan and reported), duplication.max_lines
(a line cap), duplication.rollup_depth (how deep the markdown per-directory rollup lists), and scope.registries (sanctioned-replication registries, each path
relative to the repository root, each also nameable on the command line with --registry, and
read by every audit in this plugin; duplication.registries is the older name and still resolves
when the scope-level list is empty). A cap of null or 0 means no cap. /code-metrics:setup
writes the team file and probes the collectors.
A registry line has one of two shapes. A plain line is one path-within-plugin, taken whole with
any spaces: a class is excluded when every instance ends with that path and the copies sit in
distinct carrying directories. A cluster line, <canonical> -> <member>..., names a root-relative
canonical copy and the plugin paths or gitignore-style globs that carry it
(lib/hook-utils.sh -> plugins/*/hooks/hook-utils.sh): a class is excluded when every instance is
the canonical or matches a member and the instances' directories are pairwise distinct. Instance
paths are compared root-relative, so a run from a subdirectory matches the same lines, and the
first matching line in file order wins.
This script exports the five tunables to the collector adapters as
CODE_METRICS_DUP_MIN_TOKENS, CODE_METRICS_DUP_MIN_LINES, CODE_METRICS_DUP_IGNORE,
CODE_METRICS_DUP_MAX_LINES, and CODE_METRICS_DUP_MAX_SIZE, which is the only channel an
adapter reads them through. jscpd passes the first three to the tool and applies the two caps
itself before the tool runs; the dupl and cpd adapters apply the minimum after parsing, report
the ignore globs as unused, and scan every file in scope. Which options each tool honors, its own
defaults, and why the caps are applied here rather than passed through move with the tools: the
duplication rows of ${CLAUDE_PLUGIN_ROOT}/reference/collectors.md carry each claim with its
basis, verification date and recheck trigger.
cpd (PMD) sits after jscpd on ${CLAUDE_PLUGIN_ROOT}/scripts/collector-ladder.tsv for every
language but Bash, so it runs only when jscpd does not resolve and pmd does. A repository that
already runs PMD puts it first with languages.<language>.collectors.duplication: [cpd, jscpd]; collector
overrides are validated against the ladder file and an unknown name is dropped with a warning.
check gate exists in this
version.jscpd groups JavaScript with TypeScript and nothing wider), so a C# method reimplemented in
Python is invisible to it.audit-*
skills in this plugin, and /code-metrics:principles explains what each number can and cannot
tell you./verification:measure metrics./code-metrics:principles.--all (the usage error says which).scope.registries that does not exist is a
usage error, not a silent no-op: a stale registry path would otherwise turn every exclusion off
without saying so.--all
or name both paths when that is the question.${CLAUDE_PLUGIN_ROOT}/reference/collectors.md record the
verified case); compare runs made with one detector version, never across a version boundary.duplication.min_tokens finds more and smaller clones, most of them boilerplate the
language forces.evals/evals.json (opens in a new tab)scripts/audit-duplication.sh (opens in a new tab)scripts/audit-duplication.test.sh (opens in a new tab)scripts/cluster-clones.py (opens in a new tab)scripts/registry-filter.py (opens in a new tab)scripts/test_cluster_clones.py (opens in a new tab)scripts/test_registry_filter.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
bashThree short reads, in order
6 skills in this plugin
/auditMeasure code for changed file/diff, path, or tree (`--all`) vs reference (size `--check`): size (lines per file), complexity (per-function cyclomatic complexity, cognitive, Halstead), type-debt (typed ratio, mypy). Use when 'which files are too big', 'how complex is this code', 'how many anys'. Not for CRAP: /code-metrics:audit-coverage./audit-coverageAudit coverageRead coverage artifacts a build already wrote (lcov, Cobertura, coverage.py JSON, Go cover profile) to report line coverage and CRAP per file and function for a change, path, or tree; runs no tests, never gates. Use when 'coverage per function', 'CRAP score', 'read the lcov report'. Not for complexity alone: /code-metrics:audit./audit-suppressionsportability-ok: R6 kept-adapter operation - audit-suppressions.sh C# patternsList lint/type/coverage/security suppression diff/tree: eslint-disable/@ts-expect-error/noqa/type: ignore/pylint/pyright/SuppressMessage/@SuppressWarnings/pragma/shellcheck/nolint/markdownlint/rubocop/istanbul/c8/coverage.py/Stryker/bandit/nosec/nosemgrep/gitleaks; rule/reason/justified/correctness, no gate. Use when 'which noqa have no reason', 'suppressions added in this change'. Not for size: /code-metrics:audit./principlesCode metrics knowledge baseMetric literacy for code-metrics: what each measure means, where reference values come from, and what none of them tell a reader; measures nothing. Use when: 'what does cyclomatic complexity mean', 'is CRAP a real metric', 'what is a good coverage number'. Not for running measurements: /code-metrics:audit./setupConfigure code-metrics: check probes Python, config layers, and collectors; apply writes docs/conventions/code-metrics.yaml (never installs tools).npx claudepluginhub melodic-software/claude-code-plugins --plugin code-metricsOther plugins' skills for the same job