/code-metrics:audit-coverage [--json] [--all] [--base <ref>] [--artifacts <path>]... [<path>...] [--repo <repo> ...]from code-metrics
Parses existing coverage artifacts (lcov, Cobertura, coverage.py JSON, Go cover profile) to report line coverage and CRAP score per file and function. Does not run tests.
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"
Coverage is a dynamic measure. This skill reads it statically: it parses an artifact a test run already wrote and joins it to the functions in scope. Running the tests is the project's own job and stays there, so nothing here executes a test command, starts a runner, or installs a tool.
Two numbers come out. Line coverage per file and per function is read from the artifact. CRAP per
function is derived: comp^2 * (1 - cov/100)^3 + comp, where comp is the function's cyclomatic
complexity from the audit skill's audit-complexity.sh script, run over the same scope.
| Format | Written by | What the join gets from it |
|---|---|---|
lcov .info | most JavaScript and C/C++ toolchains, coverage lcov | line hits; function records in either lcov record shape, which is where a function end line can come from at all |
| Cobertura XML | gcovr, coverlet, kcov (which is how a Bash language gets an artifact) | line hits, <sources> prefixes, and <method> regions with their hit flag |
| coverage.py JSON | coverage json | executed and missing lines, and per-function regions |
| Go cover profile | go test -coverprofile | statement counts over line ranges, which is not a line table: the profile never says which lines carry the statements, so a Go file reports the statement ratio go tool cover -func prints, labels it cov_source: statement-ratio, and reports lines_executable and lines_hit as null. The format names no functions either, so a Go function reports coverage_pct and crap as null, and its line counts as null unless a line-measuring artifact also covered the file |
The record shape and version behind each format are its row under "Coverage artifacts" in
${CLAUDE_PLUGIN_ROOT}/reference/collectors.md, which carries each claim with its basis, date and
recheck trigger.
The SQLite data file coverage.py writes while measuring is never read; why is the coverage.py
SQLite row of that file. Run coverage json or coverage lcov and point this skill at the result.
"${CLAUDE_SKILL_DIR}/scripts/audit-coverage.sh" # the change, with the artifact auto-discovered
"${CLAUDE_SKILL_DIR}/scripts/audit-coverage.sh" --artifacts build/lcov.info src/ # an explicit artifact and an explicit scope
"${CLAUDE_SKILL_DIR}/scripts/audit-coverage.sh" --all --artifacts coverage.xml --artifacts cover.out
"${CLAUDE_SKILL_DIR}/scripts/audit-coverage.sh" --json --all # the code-metrics/v3 document instead of markdown
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).
With no --artifacts and no coverage.artifacts in the config, the well-known names are looked
for under the repository root, at most two directory levels deep and never inside node_modules,
.git or vendor: coverage/lcov.info, lcov.info, coverage.xml, cobertura.xml,
coverage.json, coverage.out, cover.out. Each artifact's format is detected from its content,
not its extension.
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 repository reads its own artifacts under its own root: an --artifacts path must be
relative and is read from each root, so name artifacts only when every repository writes them to
that path.
Present the markdown report as printed: the scope, the "Coverage of this run" table, the
references with their provenance, then one row per file and per function. Keep the --json
document when the numbers feed a comparison: pass it to /verification:measure metrics (if enabled), treating status: empty on either side as INCONCLUSIVE;
otherwise keep the JSON beside your notes and compare by hand.
A run that finds no artifact reports every language unavailable, lists the paths it searched, and
ends its markdown with a line saying so, because the remedy is the project's to apply: this skill
runs no test and installs nothing. The project's own test run writes the artifact, in one of the
formats above. Pass its path with --artifacts, or list it under coverage.artifacts, when it
does not land on one of the well-known names.
coverage_pct, lines_executable, lines_hit.
A file a Go cover profile covers is the exception: the profile weighs statements, so the
percentage is its statement ratio, cov_source reads statement-ratio, and both line counts
are null.coverage_pct, cyclomatic, crap, and, in the JSON, cov_source and hit.--json document, which is not
capped.cov_source says where the coverage came from: artifact-region when the artifact carried the
function's own region (coverage.py functions, a Cobertura <method>, an lcov 2.2 FNL end
line), line-range when the range came from the complexity collector, in which case nested
function ranges are subtracted from the parent first, statement-ratio on a file row whose
percentage came from a Go profile's statements rather than from a line table, and ambiguous
on a function the join refused. The markdown table renders the values; the per-row cov_source
and hit fields are in the --json document.run
methods in one file and a record named run are one function's coverage, and the range says
whose. Where nothing separates the candidates, because the artifact placed none of them at a
line or because two of them fall inside the same range, the join is refused rather than guessed:
the row reads cov_source: ambiguous; coverage, line counts, hit, and CRAP are null because
those numbers would be a guess, while cyclomatic from the complexity row is kept because that
collector already measured it; it carries a coverage-ambiguous label, and the language's run row
turns partial and names the functions it left unjoined. A missing coverage number an operator
can see beats a wrong number they cannot.hit is the artifact's function-hit flag. When it says the function was never entered,
coverage_pct is 0 rather than the 1/N a declaration line executed at import would produce.coverage_pct: null and
crap: null, never 0: a fabricated 0 percent would produce a fabricated maximal CRAP. Its
lines_executable and lines_hit are 0 when an artifact that measures lines covers the file
and carries none in that range, and null when no artifact covering the file measures lines at
all, which is every function of a file only a Go profile covers./code-metrics:principles carries the provenance, the rename history, and the caveats; read it
before you quote a CRAP number at anyone.<language>/crap
row with status: not-applicable and that reason. Bash is that language in this version: no
maintained Bash collector reports an end line, so Bash CRAP is a stated gap, not a null.<language>/crap row with status: unavailable naming that collector and its reason, whatever the
language's coverage row says. CRAP needs both numbers, and the missing one is the cause worth
reading; when the coverage row is not ok either, its reason follows the collector's on the
same row, so a partial count or a no-artifact search never hides a collector failure and the
collector never hides them. Functions: 0 in the summary reads with that row.status: partial and the reason
partial, N of M scope files present in the artifacts, so a total miss never reads as "no
executable lines" and the document cannot settle as complete while a row says N of M. A language
no artifact covers is unavailable with that count; when no artifact was found at all, the
reason lists every path searched. A language that left a function unjoined is partial for that
reason too.N of M count also says which files: its reason names the first five scope
files no artifact mentions (; missing: a, b, c, d, e, +N more in the JSON) and the JSON row's
missing key lists all of them, root-relative and sorted. The count alone cannot tell a test
file an artifact never records from a source file the suites never reach; the paths can./mutation-testing:audit (if enabled) owns that question;
without it, say that the coverage number is an execution count and stop there.<language>/crap
row, and the summary carries an Exit 3: line naming the language and collector, so the markdown
alone says why the run has no function rows.Everything tunable resolves through the code-metrics layers (layers and keys in
${CLAUDE_PLUGIN_ROOT}/reference/config.md):
| Key | Effect |
|---|---|
coverage.artifacts | Explicit artifact paths; empty means auto-discover. A listed path that does not exist is a usage error, so a stale entry is loud |
coverage.path_prefix_strip | Prefixes removed from artifact paths before the join, for compiled-output layouts (dist/, build/) |
coverage.reference | A number counts rows below it as over_reference and nothing else; unset, there is no bar |
coverage.crap.reference | As coverage.reference, for CRAP; no standard sets one |
/code-metrics:setup writes the team file and probes the collectors.
/verification:measure metrics./mutation-testing:audit./code-metrics:principles.<language>/crap row is unavailable
naming the collector's own reason. File-level coverage is unaffected: the scope the join keys on
is the one the audits measure, not the files a complexity collector emitted rows for, so a file
with no functions still reports its lines.pkg/a.py) stays unmatched and shows up in the partial count,
because attributing it to either would credit one service with the other's coverage. The
basename fallback needs a single winner on the artifact side too, counted across every artifact
read rather than within one: when two services each ship a handler.go and only one is in
scope, the out-of-scope path stays unmatched instead of merging its coverage into the scoped
file, even though the scope names exactly one candidate.start.col,end.col identity and are totaled
after that, so two test shards that entered different blocks report what they covered between
them rather than what the luckier shard covered alone..go file do not average or overwrite each
other: the profile's statement ratio is that file's exact native measure and wins the
percentage, the row says statement-ratio, and the line counts stay null rather than reading as
the counts behind a number they did not produce. The language's collector still names both formats
read. Function rows are line-based, so a Go function does take its region from a line artifact
when one covers it.<source> roots is read against all of them: a relative class
filename takes the first root under which that path exists in the scanned tree, and falls back
to the first root when no candidate exists. Two roots that both hold the file is an ambiguity
the report cannot settle, so the first one wins and the class lands under it. The probe settles
anything only when the roots are relative, or absolute and present on the machine running the
audit. A report built elsewhere declares absolute roots (the usual coverlet, kcov and gcovr shape
for a CI run) naming directories this machine does not have, so every candidate misses and every
class lands under the first root. Rewriting a root from another machine onto the local tree
needs a mapping the report does not carry.A.run and B.run) can bind to
each other's artifact region when the artifact carries only the short name; the file-level
numbers are unaffected.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-duplicationAudit duplicationMeasure duplicated code and redundant copy-paste clone classes (DRY) across a change, path, or tree with instance spans, excluding repo-sanctioned replication. Reports, never gates. Use when 'find copy-paste code', 'clone detection', 'duplication report'. Not for file length: /code-metrics:audit size./npx claudepluginhub melodic-software/claude-code-plugins --plugin code-metricsOther plugins' skills for the same job