/software-writer:sweeping-dead-codefrom software-writer
Finds unused code across a path, repository, or branch and reports it in a read-only ledger. Never edits files. Activates when the user asks to find, list, audit, or sweep dead code.
Ships in software-writer. 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.
This skill finds unused code in a stated scope and reports it. Never edit, delete, stage, or format a project file. Run only tool commands that are read-only by construction (the tool references' commands) or that the user approved for this sweep (sweep.tools commands, Step 4). Write the ledger in the system temporary directory, outside the repository.
The workflow below can be extended by content earlier in context. Two shapes are recognized:
## Pre-Step-N. If it does, execute its content as additional instructions, then continue with Step N. After Step N, do the same check for ## Post-Step-N.`sweep.exclude`). When such a name appears, check whether earlier context assigns a value to it. If yes, use the assigned value; otherwise use the inline default.Both checks default to no-op. When earlier context contains no matching section or assignment, the skill runs entirely on the defaults documented inline. Extension content may cite project files by path; read a cited file when the step that cites it runs, not before.
digraph sweeping_dead_code {
"Start" [shape=doublecircle];
"Step 1: Resolve the scope" [shape=box];
"Scope stated?" [shape=diamond];
"Ask for the scope" [shape=box];
"Step 2: Detect stacks and load references" [shape=box];
"Step 3: Enumerate definitions into the ledger" [shape=box];
"Step 4: Run installed tools read-only" [shape=box];
"Step 5: Collect evidence and classify" [shape=box];
"Step 6: Refute dead and test-only candidates" [shape=box];
"Refutation found a live reference?" [shape=diamond];
"Step 7: Check coverage" [shape=box];
"Every ledger entry has a final class?" [shape=diamond];
"Step 8: Report" [shape=box];
"Done" [shape=doublecircle];
"Start" -> "Step 1: Resolve the scope" -> "Scope stated?";
"Scope stated?" -> "Step 2: Detect stacks and load references" [label="yes"];
"Scope stated?" -> "Ask for the scope" [label="no"];
"Ask for the scope" -> "Step 2: Detect stacks and load references";
"Step 2: Detect stacks and load references" -> "Step 3: Enumerate definitions into the ledger" -> "Step 4: Run installed tools read-only" -> "Step 5: Collect evidence and classify" -> "Step 6: Refute dead and test-only candidates" -> "Refutation found a live reference?";
"Refutation found a live reference?" -> "Step 5: Collect evidence and classify" [label="yes: add the reference, clear classes, re-mark"];
"Refutation found a live reference?" -> "Step 7: Check coverage" [label="no"];
"Step 7: Check coverage" -> "Every ledger entry has a final class?";
"Every ledger entry has a final class?" -> "Step 5: Collect evidence and classify" [label="no"];
"Every ledger entry has a final class?" -> "Step 8: Report" [label="yes"];
"Step 8: Report" -> "Done";
}
Take one of three scopes from the request:
sweep.exclude, in the report as not swept.sweep.exclude.git diff <base>...HEAD (base default main). The ledger holds every definition that encloses an added or changed line of that diff — the nearest Step 3 pattern match above that line in the same file whose body extends past the line; when the extent is unclear, include the definition — plus every definition elsewhere in the repository whose name appears on a removed line of that diff. The commands that take scope paths run over the whole repository; only the definitions this rule names become rows.When the request names no scope, ask which one; never default silently.
Never enumerate a path in sweep.exclude; default if not otherwise stated: dependency and build directories (vendor/, node_modules/, .venv/, venv/, dist/, build/, target/) and files whose header marks them as generated. Apply a sweep.exclude entry that is not a path, such as the generated-header default, for the whole sweep: the files it describes get no ledger row, and their tool findings are not evidence.
Detect the stacks in scope from file extensions and manifests. Detect bash from .sh, .bash and .bats files and from extensionless files whose first line is a #! naming sh or bash; a .bats file also detects the bats framework. Detect python from *.py files and from extensionless files whose first line is a #! naming python. project.stacks overrides detection; default if not otherwise stated: detect from files and project signals.
For each stack (bash, go, php, python, typescript), load references/tools/<stack>.md and references/stacks/<stack>/indirect-references.md. For each detected test framework, load references/stacks/<stack>/<framework>-referenced-by-name.md:
| Stack | Referenced-by-name files |
|---|---|
bash | bats |
go | stdlib-testing, testify, ginkgo-gomega |
php | phpunit, pest |
python | pytest, unittest |
typescript | jest, vitest, mocha, node-test |
Sweep a stack or framework without a file with the plain-name search only, and name the forms left unchecked in the report.
Enumerate every definition in scope by running the search commands from the stack's ## Definition patterns section — never by reading files and listing what looks unused.
Write the ledger as JSON Lines to ${TMPDIR:-/tmp}/sweeping-dead-code-<timestamp>.jsonl, one object per definition:
| Field | Value |
|---|---|
id | sequential integer from 1 |
stack | the stack |
kind | file, type, function, method, constant, variable, member (enum cases, namespace members, and properties), or dependency (a declared package dependency) |
name, file, line | the definition |
class | null |
references | empty list |
evidence | empty list of strings |
Each stack gets the file rows its tool reference defines; an executable file gets no file row. State the ledger path in the conversation.
Run each tool listed in the stack's tool reference only when the project already has it (a lockfile or manifest entry, vendor/bin/, node_modules/.bin/, or the PATH); never install one. Invoke it from where it was found: node_modules/.bin/<tool>, vendor/bin/<tool>, or the bare name on the PATH, replacing the tool name at the start of the reference command.
sweep.tools replaces or adds tool commands per stack; default if not otherwise stated: the commands in the tool reference. Reject a sweep.tools command that contains a flag the tool reference lists under "Never pass", or any of >, |, ;, &, a backtick, or $(, and say so in the report. Before the first run of each remaining sweep.tools command in this sweep, show the exact command to the user and run it only after the user approves it in the conversation; skip a declined command and report it.
Before each run:
sweep.tools, and never pass a flag the reference lists under "Never pass".{ git status --porcelain=v1 --untracked-files=all; git diff HEAD --binary; git ls-files -o --exclude-standard -z | xargs -0 shasum; } | shasum.After each run, record the fingerprint again. When the two differ, stop the sweep: report the tool, the command, and the paths that changed, and run no further tool. Restore nothing; the user decides. The guard does not cover git-ignored files.
Read findings from the tool's parsed output, never from its exit code. Treat a tool finding as evidence for a ledger row, never as a verdict. A finding with no matching row is not a row.
For every row without a final class, search the scope and the whole repository for:
Record each reference in the row's references list as {file, line, side, from}. side is production or test; the framework's referenced-by-name file lists the test-side forms. from is the id of the innermost ledger row whose definition encloses the reference — for top-level code in a file that has a file row, that row — or root when no ledger row encloses it (configuration, templates, CI, top-level code of an executable script, files outside the scope).
Mark first, then classify.
Roots. A row is published when it is a library's public API, an entry file (a package.json main, bin, or exports target, a Python __main__ module or [project.scripts] target, a PHP front controller), an entry point the framework calls by convention, a route, a command, a documented CLI flag, or a name in sweep.entry_points (default if not otherwise stated: none). Published rows are roots, and so is every row with a production reference whose from is root.
Reachability. A row is reachable when a root reaches it through production references (from pointing at a reachable row). Rows that reference only each other and no root are unreachable.
Uncertain seeds. A dynamic form from the indirect-references file (a computed getattr, a string-built call, a dynamic import) anywhere in production code — inside a reachable row, an unreachable row, or root code — makes every unreachable row it could reach an uncertain seed. Narrow the reach as far as the static facts allow: the receiver's type for an attribute lookup, the module or directory of an import base, the literal prefix or suffix of a built name. With nothing to narrow it, the reach is every unreachable row of the kind the form can reach (methods and attributes, functions, files) in the scope. Every unreachable row reachable from an uncertain seed through production references is uncertain too, naming the seed.
Then assign one class per row:
| Class | Rule |
|---|---|
published | The row is a published surface (see Roots). |
live | Reachable from a root through production references. |
uncertain | Not reachable, and an uncertain seed or reachable from one. The row names the dynamic form with its file:line, and the seed when it is not the row itself. |
test-only | Not reachable, not uncertain, and at least one test reference. |
dead | Not reachable, not uncertain, and no test reference. |
Send every dead and test-only row to an independent refutation before it can be reported. Spawn one fresh subagent per batch of sweep.refutation_batch_size rows (default if not otherwise stated: 10) with the prompt from references/refutation-prompt.md, filled in with the rows, the stack's indirect-references file content, and the framework's referenced-by-name file content. Do not pass the evidence collected in Step 5. When the host cannot spawn subagents, run the refutation in the session and mark every row refuted in the session "refutation not independent" in the report.
For a row the refutation shows reachable, add the reference to its references, set its class to null, and set every other row's class to null too; then return to Step 5, which re-marks reachability from the roots. Rows already refuted keep their refutation result and are not sent to refutation again unless their class changes. A row that survives keeps its class and records "refutation: none found" in evidence.
Count ledger rows and rows with a final class. Every row needs a class, and every dead and test-only row needs a refutation result. Return to Step 5 on any gap.
Report in the conversation, in this order:
dead rows: file:line — kind name — searches that came back empty — tool that flagged it, if any — refutation result.test-only rows, same columns plus the test files that reference them.uncertain rows with the dynamic form that blocks a verdict.published rows, one line each.Count live rows; do not list them. Propose no edits, and stop after the report.
references/refutation-prompt.md (opens in a new tab)references/stacks/bash/bats-referenced-by-name.md (opens in a new tab)references/stacks/bash/indirect-references.md (opens in a new tab)references/stacks/go/ginkgo-gomega-referenced-by-name.md (opens in a new tab)references/stacks/go/indirect-references.md (opens in a new tab)references/stacks/go/stdlib-testing-referenced-by-name.md (opens in a new tab)references/stacks/go/testify-referenced-by-name.md (opens in a new tab)references/stacks/php/indirect-references.md (opens in a new tab)references/stacks/php/pest-referenced-by-name.md (opens in a new tab)references/stacks/php/phpunit-referenced-by-name.md (opens in a new tab)references/stacks/python/indirect-references.md (opens in a new tab)references/stacks/python/pytest-referenced-by-name.md (opens in a new tab)references/stacks/python/unittest-referenced-by-name.md (opens in a new tab)references/stacks/typescript/indirect-references.md (opens in a new tab)references/stacks/typescript/jest-referenced-by-name.md (opens in a new tab)references/stacks/typescript/mocha-referenced-by-name.md (opens in a new tab)references/stacks/typescript/node-test-referenced-by-name.md (opens in a new tab)references/stacks/typescript/vitest-referenced-by-name.md (opens in a new tab)references/tools/bash.md (opens in a new tab)references/tools/go.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub it-bens/ai-tools --plugin software-writer4 skills in this plugin
/writing-codeUse when writing or editing implementation code — any change that adds, modifies, or removes logic, signatures, or comments on the lines being written. Also covers reviewing, cleaning up, or improving the comments on code being edited. Do NOT activate for test files and their fixtures (the writing-tests skill owns those)./writing-docsUse when writing or editing a repository documentation surface — a README, an architecture document, a CLAUDE.md or AGENTS.md pointer file, or a surface the project has registered. Do NOT activate for code comments, commit messages, or PR descriptions./writing-testsUse when authoring, editing, or reviewing an automated test — any change to a test file or its fixtures.Other plugins' skills for the same job