Read-only hunt for dead and unused code via 4 analyzers (Knip TS/JS, vulture Python, gopls Go, grep shell/C#/other), adjudicated dead, uncertain, or alive. Use when: 'find dead code', 'remove unused code', unused exports, functions, orphaned files, or if anything calls a symbol. Find-and-delete starts here; deleting is /code-tidying:tidy.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Audit Dead Code?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/melodic-software-audit-dead-code)
---
# portability-ok: R6 kept-adapter operation - dead-code-scan.sh grep analyzer
description: "Read-only hunt for dead and unused code via 4 analyzers (Knip TS/JS, vulture Python, gopls Go, grep shell/C#/other), adjudicated dead, uncertain, or alive. Use when: 'find dead code', 'remove unused code', unused exports, functions, orphaned files, or if anything calls a symbol. Find-and-delete starts here; deleting is /code-tidying:tidy."
argument-hint: "[--max N] [--analyzer knip|vulture|gopls|grep] [target] [--repo <repo> ...]"
user-invocable: true
disable-model-invocation: false
allowed-tools: ["Bash(${CLAUDE_SKILL_DIR}/scripts/dead-code-scan.sh:*)", "Bash(git grep:*)", "Bash(git log:*)", "Bash(grep:*)"]
metadata:
workflow-stage: anytime
summary: Whole-repo dead-code hunt across four labeled analyzers with adjudicated candidates
---
# Audit dead code
## Purpose
Find code nothing has touched in a long time, which a rotated tidying focus area and a diff-scoped
simplification pass cannot see, and answer *what here is no longer reachable, and how confident are
we?* Every candidate is adjudicated against the dynamic-usage patterns static analyzers miss, so the
report is a list of decisions a human can act on, not an analyzer dump to re-verify.
## The four analyzers are not peers
Present them as four analyzers of unequal strength, each labeled. A report that treats them as equals
is wrong even when every finding in it is right.
| Analyzer | Covers | Measured character | How it fails |
|---|---|---|---|
| **knip** | TS/JS: unused files, exports, types, enum members. **Not** class members (Knip 6 rejects `--include classMembers`) | **60% precision / 100% recall** on trap fixtures | Unrestored, it **manufactures false positives** (a failed config load produced 2 phantom "unused files"); its `ERROR:` line goes to stderr, which the JSON reporter discards |
| **vulture** | Python: unused function, class, method, variable, attribute, plus unreachable code | **16.7% precision / 100% recall**; all five trap classes false-positived at 100% | Low precision by construction. Its output is a worklist, never a verdict |
| **gopls** | Go: **unexported symbols only** (`gopls check -severity=hint`), the analyzer's declared coverage | Correct on every measured symbol; 2.1s | An unresolved module graph **suppresses hints**: false **negatives**, the opposite of knip. Never describe the two degradations with one phrase |
| **grep** | Shell and PowerShell functions; `function`/`class`/`const`/`let`/`var` declarations in JS/TS no `package.json` root owns (`ts-unreferenced-symbol`); C# type declarations and members with an access modifier, read as text and never built (`cs-unreferenced-private`, `cs-unreferenced-symbol`); unreferenced source files (`unreferenced-file`) | Shell symbols: **4/4 true positives, 0 false** over 546 `.sh` files (shellcheck found 0 of the 4). JS/TS symbols: **75% precision / 100% recall** (derived 2026-11-28 from the candidate set the scan test asserts, not a separate scan). C# private: **66.7% / 66.7%**; other C#: **33.3% / 100%** (2026-10-29). `unreferenced-file` precision unmeasured | Low recall: `$`, `-`, `.` are non-word characters, so an adjacent hit reads as a reference and saves a possibly dead symbol. A JS/TS export only an entry point or outside consumer calls is a false candidate; a name in a comment saves a dead one. A C# member reached by a computed reflection name, assembly scanning or a serializer is a false candidate <!-- portability-ok: R6 kept-adapter operation - dead-code-scan.sh grep analyzer --> |
Every figure comes from this plugin's trap fixtures under `evals/fixtures/`, as recorded on
2026-08-23 (JS/TS symbol figures derived 2026-11-28 from `scripts/dead-code-scan.test.sh`'s asserted candidates, C# figures 2026-10-29). Recheck trigger: a major <!-- portability-ok: R6 kept-adapter operation - dead-code-scan.sh grep analyzer -->
version bump in any analyzer's detector, or a change to the fixture corpus. Re-measure before quoting
one to a user.
**Orphaned files.** The grep analyzer emits `unreferenced-file` (tier 2) for a source file no other
tracked file names, C# and languages with no analyzer (Rust, F# and VB among them) included. A reference in a CI <!-- portability-ok: R6 kept-adapter operation - dead-code-scan.sh grep analyzer -->
workflow, settings file, manifest or doc saves the file; a computed path or glob does not, so the
candidate is **uncertain, not dead**. Its input set, the no-analyzer extension list, per-analyzer
invocation, coverage accounting and degradation detail: [context/analyzers.md](context/analyzers.md)
"Analyzer reference".
## Candidate shapes and default tiers
The detector emits **candidates**, not verdicts. A shape's tier is its prior, taken from the
measured precision of the analyzer that produced it.
| Shape | Analyzer | Default tier |
|---|---|---|
| `ts-unused-file` | knip | 2 |
| `ts-unused-export` | knip | 2 |
| `ts-unused-type` | knip | 2 |
| `ts-unused-enum-member` | knip | 2 |
| `py-unused-symbol` | vulture | 2 |
| `py-unreachable` | vulture | 1 |
| `go-unused-unexported` | gopls | 1 |
| `unreferenced-symbol` | grep | 1 |
| `ts-unreferenced-symbol` | grep | 2 |
| `cs-unreferenced-private` | grep | 2 |
| `cs-unreferenced-symbol` | grep | 2 |
| `unreferenced-file` | grep | 2 |
| `detector-drift` | any | 3 |
`ts-unreferenced-symbol` is tier 2, unlike the shell `unreferenced-symbol`, because its derived
precision is 3 of 4 and an entry point or public export nothing in the repository calls reads as
unreferenced. Both C# shapes are tier 2 because each yields a false dead on the trap fixtures. <!-- portability-ok: R6 kept-adapter operation - dead-code-scan.sh grep analyzer -->
A consumer's own `CLAUDE.md` or rules may refine these defaults.
## Running the detector
```bash
${CLAUDE_SKILL_DIR}/scripts/dead-code-scan.sh # whole repo, every analyzer
${CLAUDE_SKILL_DIR}/scripts/dead-code-scan.sh --max 20 # cap the adjudication set
${CLAUDE_SKILL_DIR}/scripts/dead-code-scan.sh --analyzer grep src/ # one analyzer, scoped candidates
${CLAUDE_SKILL_DIR}/scripts/dead-code-scan.sh --root <root> # another repository's root (--repo alias)
${CLAUDE_SKILL_DIR}/scripts/dead-code-scan.sh --json # structured JSON output
${CLAUDE_SKILL_DIR}/scripts/dead-code-scan.sh --unattended --json # read-only unattended run (skips knip so no repo JS/TS config executes)
${CLAUDE_SKILL_DIR}/scripts/dead-code-scan.sh --help # usage and exit codes
```
Exit is 0 on every scan path and 2 only on a usage error; no detector's exit code is propagated.
Present the `Analyzer:` lines with the findings: they make a clean report a claim rather than an
absence. A `target` narrows which files *produce* candidates; the reference search stays
repository-wide, because a reference from anywhere saves a symbol.
## Over several repositories
With no target form, the scan covers this checkout. A target form (`--repo`,
`--repos-from`, `--owner`, `--fleet`, `--skip`, or the same request in words) selects several
repositories, which resolve, count, fan out and merge as
[`${CLAUDE_PLUGIN_ROOT}/reference/target-scope.md`](../../reference/target-scope.md) "Target
forms", "Resolving repositories", "Fan-out" and "Merging findings" say. Strip the target-form
tokens before reading `--max`, `--analyzer` and `target`. What differs here:
- **One scan per repository, root anchored.** Each repository's subagent runs
`dead-code-scan.sh --root <root>` with the run's `--max`, `--analyzer` and `target`, so the
reference search stays inside that repository: a reference in one repository never saves a
symbol in another. A `target` resolves under each root; a repository where it does not exist is
reported skipped. `--max` caps each repository's candidates.
- **The scan reads the clone on disk.** It cannot read `origin/HEAD` without a worktree, which
would be a write. So after the fetch, a repository other than the session's own whose
checked-out `HEAD` is not `origin/HEAD`, or whose working tree has uncommitted changes, is
scanned as it stands, and the report says so for that repository.
- **One consent gate.** Report each repository's `Summary candidates:` line and the total, and
take one go-ahead before any repository is adjudicated.
- **Nothing is written in any repository.** The hard rules hold per repository, and the
suppression entries of the convergence loop are handed over per repository, for that
repository's own detector config.
## Run states. Five, not two
| State | Meaning |
|---|---|
| `ran` | the analyzer resolved a binary, invoked it, and read trustworthy output |
| `skipped` | no resolvable local binary, or a located binary that failed to invoke. Nothing was fetched; no package runner is ever called |
| `degraded` | the analyzer ran but its output is not trustworthy. **It emits no records**, its line says why, and its files are uncovered (`analyzer degraded`) |
| `scanned-zero-files` | the analyzer had zero in-scope input files it **owns** (a nested project root's files belong to that root). Indistinguishable from clean in the detectors' own output |
| `no-manifest` | the analyzer's language is in scope but no manifest root exists (`package.json` for knip, `go.mod` for gopls). Those files are uncovered unless another analyzer took them (grep takes JS/TS no `package.json` root owns). Not a missing binary |
`files=` on an `Analyzer:` line is the number of files that analyzer took as input, including `skipped` and
`no-manifest`; it is not the number of findings.
A run where no analyzer reached `ran` and no source file is uncovered is **a scan of nothing, not a
clean bill**, and the script says so. A run that leaves any in-scope source file uncovered, even
with some analyzer `ran`, is not a clean bill either: the clean-result note prints only when
`Summary coverage:` reports `uncovered=0`.
## Adjudication
Bounded by design. Evidence catalogue: [context/adjudication.md](context/adjudication.md)
"Evidence patterns".
1. **Consent gate.** Report the candidate count and the `--max` cap from `Summary candidates:` and
get a go-ahead before adjudicating. Never quote a time or token estimate; there is no
measurement behind one. Done when the operator has explicitly approved adjudication or declined it
(report-only).
2. **Order is git recency, oldest-untouched first**, as the script emits them. There is no
confidence key: vulture pins every symbol-level finding at 60 and knip has none.
3. **Adjudicate each candidate to `dead`, `uncertain`, or `alive`** against the dynamic-usage
patterns detectors cannot see: string-name dispatch, DI and serialization, reflection, decorator
and route registration, test-only entry points, public API surface, generated code. An
`unreferenced-file` a computed path or glob could load is `uncertain`, not `dead`.
4. **Every `alive` cites the evidence that saved it.** An unevidenced `alive` is a guess.
5. Fan out to fresh-context subagents in batches when the set is large; if spawn depth is
exhausted, say so and adjudicate inline at the same cap rather than silently shrinking the set
(the depth-limit pointer record is in
[context/adjudication.md, Bounding the pass](context/adjudication.md#bounding-the-pass)).
6. **Optional LSP assist**, never required and never an analyzer: when Claude Code's `LSP` tool is
available, `findReferences` on one candidate is one more evidence source. Read what it returns
in [LSP tool behavior](https://code.claude.com/docs/en/tools-reference#lsp-tool-behavior)
before reading a count as dead. Done when every emitted candidate has a `dead`, `uncertain` or
`alive` verdict with evidence, or the cap stopped the batch and the report says so.
## Hard rules
- **Read-only and never fetch.** No `Edit`, no `Write`, no mutating Bash, and no file written, not
even a findings file; every deletion is the human's. Detectors run only from a resolvable local
binary (PATH, the repo-local `node_modules/.bin` walk, or `.venv/bin`) or the analyzer is `skipped`;
the script invokes no package runner. The one exception is installing or fetching a detector,
only through "When coverage is incomplete" step 3, after an explicit yes.
- **Tiers.** Detector tiers are candidate priors: T1 high-confidence, T2 uncertain, T3 **detector
drift** (output no parser recognized). In the adjudicated report `dead` → T1 and `uncertain` →
T2. **`alive` is never emitted as a record**: it is a saved candidate, and emitting it would make
`Summary total:` mean two things.
- **T3 is the drift bucket.** An unrecognized detector line is recorded, never dropped and never
counted as a finding. A fourth verdict landing there is the alarm, not the answer.
- **Exit codes are never run health.** Run health comes from the detector's output, never its
exit code. The documented codes: [vulture](https://github.com/jendrikseipp/vulture#exit-codes),
[knip](https://knip.dev/reference/cli#--no-exit-code)..
- **Presence is proven by invocation**, never by a locator hit (measured: `command -v
rust-analyzer` succeeds while invocation fails).
- **knip executes a repo-controlled config module.** Disclose it on every run that loads one.
It is narrower than a build, which is why the analyzer accepts it; vulture, measured, is pure. The
observation behind both is in [context/analyzers.md](context/analyzers.md) "knip: TS/JS".
- **`**/fixtures/**`, `**/__fixtures__/**`, and `**/testdata/**` (including `**/evals/fixtures/**`) are never scanning input**: a test or detector fixture corpus is not the consumer's dead code.
## When coverage is incomplete
A `skipped`, `degraded`, `no-manifest` or `scanned-zero-files` analyzer, or source files with no analyzer,
are gaps, not a clean bill. After presenting the analyzer roster:
1. **Name each gap** from `Summary coverage:` and each `Note: uncovered` line: the path and the
reason (`no analyzer for the language`, `no manifest root`, `tool not installed`, `analyzer degraded`,
`tool could not parse it`, or `analyzer not selected`). Rust, F# and VB are a policy exclusion (`no
analyzer for the language`), not a forgotten detector. C# gets the grep analyzer's text-only pass, never <!-- portability-ok: R6 kept-adapter operation - dead-code-scan.sh grep analyzer -->
a build.
2. **Offer to file an issue** against this plugin with the file count and language, pre-filled for
the operator to edit and submit. Do nothing unless they agree.
3. **Offer research and install**: with consent, run `/discovery:research` (if enabled) to pick a detector for
the language, show the choice and its install command, and install or invoke it only after an
explicit yes. Record its precision as **unmeasured** until trap fixtures cover it.
Consent-gated analyzers that may compile or execute project code remain out of scope.
## Output schema
The script emits flat records; the adjudicated report is what the human reads.
```text
Analyzer: knip | root=. | state=ran | files=19 | detail=19 candidate(s); 269 finding(s) this root does not own dropped ...
Note: knip evaluated knip.config.ts through jiti — a DISCLOSED exception ...
File: src/legacy/format.ts
Finding tier: 2
Finding shape: ts-unused-export
Finding line: 13
Finding excerpt: formatLegacyRow
---
Summary file: src/legacy/format.ts | T1=0 T2=1 T3=0
Summary analyzers: ran=3 skipped=1 degraded=0 scanned-zero-files=2 no-manifest=0
Summary coverage: covered=19 uncovered=2
Summary candidates: total=370 emitted=15 dropped-by-cap=355 cap=15
Summary total: files-with-findings=15 T1=0 T2=15 T3=0
Note: uncovered cmd/tool/main.go — no manifest root
Note: uncovered src/main.rs — no analyzer for the language
```
`files-with-findings=` counts files that emitted at least one candidate. `Summary coverage:`
counts every in-scope source file as covered by an analyzer in `ran`, or uncovered with one of the
reasons above; markdown, JSON, YAML and other non-source files are not in it. The grep analyzer covers
files with no symbol analyzer, so `no analyzer for the language` remains only when that analyzer is not
selected.
Present per file: verdict, shape, line, the evidence checked, and for `alive` what saved it. Close
with the analyzer roster, the candidate count against the cap, and `n dropped by cap`.
## Convergence loop
The skill writes nothing, so the memory lives in the repository: adjudicate a bounded batch, hand
the operator suppression entries for each detector's **native** config (Knip `ignore` entries, a
vulture whitelist; formats in [context/adjudication.md](context/adjudication.md) "Suppression
formats"), and the next run reaches new code. Each step is done when the operator has the batch's
verdicts and suppression text, has declined them, or the batch is explicitly deferred; the loop ends when a follow-up scan is
scheduled or the operator stops after one batch.
Only knip and vulture converge. **Go and the grep analyzer get no suppression directive**: those
verdicts live in the report and in a comment at the declaration, and the same candidates return.
Say so rather than emitting a directive. The probe behind the Go half is in
[context/adjudication.md](context/adjudication.md#suppression-formats) "Suppression formats"; `//lint:ignore` belongs
to staticcheck, per
[Ignoring problems with linter directives](https://staticcheck.dev/docs/configuration/#ignoring-problems-with-linter-directives).
`dead` and `uncertain` verdicts are session-scoped: an un-suppressed `uncertain` returns next run.
A committed vulture whitelist raises `F821` under a consumer's ruff config; say so when you emit
one.
## What this skill does not do
- `/code-tidying:tidy` applies Beck's Dead Code tidying inside one rotated focus area; this hunts the
whole repository and reports.
- `/code-tidying:batch-simplify` sweeps recently changed files; this targets the long-untouched
ones a recency window excludes.
- Comment residue is `/code-tidying:remove-comments audit`.
- Not a dependency, asset, or feature-flag auditor, and not coverage-based runtime detection.
## Next
`/code-tidying:tidy`
Adjudicated `dead` verdicts are applied there. This skill only reports.
## Gotchas
- **No `package.json` means knip scans no `.js`/`.mjs`/`.cjs`.** Its analyzer is `no-manifest` with
the real file count, and the grep analyzer takes those files, and any JS/TS outside every
`package.json` root, for `ts-unreferenced-symbol` and `unreferenced-file`. A symbol used only
inside its own file counts as referenced.
- **A `degraded` analyzer is not a quiet analyzer.** knip degraded means invented findings were withheld;
gopls degraded means real findings were never produced. Report which. Either way its files are
listed uncovered, so the clean-result note cannot print.
- **A grep hit adjacent to `$`, `-`, or `.` needs inspection**; it is never an automatic `alive`.
- **knip runs once per `package.json` root**, and each root reports only the files it owns, so one
degraded workspace neither condemns the others nor has its withheld findings re-manufactured by an
outer root's run.
- **vulture is handed only `*.py`.** A parse error on another file is an input note, not a
degraded analyzer.
- **`--max` counts candidates, not files**, so a cap can truncate a file's block: `Summary file:`
reflects what was emitted, not what exists.
Files in this skill
SKILL.md12.7 KB
context/adjudication.md7 KB
context/lanes.md10.1 KB
evals/evals.json9.9 KB
evals/fixtures/dead-and-dynamic.go602 B
evals/fixtures/dead-and-dynamic.py1022 B
evals/fixtures/dead-and-dynamic.sh1.2 KB
evals/fixtures/dead-and-dynamic.ts674 B
evals/fixtures/gopls-hints.txt77 B
evals/fixtures/knip-degraded.stderr.txt142 B
evals/fixtures/knip-report.json676 B
evals/fixtures/py-entry.py352 B
evals/fixtures/ts-entry.ts591 B
evals/fixtures/ts-orphan.ts347 B
evals/fixtures/ts-used.ts234 B
evals/fixtures/vulture-parse-error-input.toml449 B