/kenji:plan-dead-codefrom kenji skills
Runs a plan-only dead-code audit using Knip to identify unused files, exports, dependencies, duplication, debug residue, suppressions, orphan assets, and env drift. Produces a reviewed keep/kill list without deleting anything.
Ships in kenji skills. 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.
Degree of freedom: MIXED. Tool config authoring and the baseline
command set [LOW freedom — run exactly]; judging reachable vs
proven-dead, and what must keep working, [HIGH freedom].
Plan-only. This pass deletes nothing — not a file, not an export, not
a dependency, not a row. It produces plan-dead-code.md: a reviewed
keep/kill list plus a ratchet baseline.
The failure mode this skill exists to prevent: an agent runs knip on a
vibe-coded repo, gets 300 findings, and starts deleting. On a first run,
most findings are misconfiguration, not dead code. Knip's own docs are
explicit — running --fix "before your configuration is fully settled is
dangerous", and ignore patterns are "a last resort" because "hiding a
result is not the same as resolving it."
| Skill | Owns |
|---|---|
| plan-dead-code (this) | Nothing reaches this — unreachable files/exports/deps/assets/schema (plan only) |
housekeep-dead-code | Execute this plan — delete by category, install the ratchet |
plan-stub-checker | This reaches nothing — dead buttons, unwired handlers |
plan-antislop | Looks machine-authored — a taste judgment, not reachability |
plan-dependency-provenance | Package existence, integrity, licensing, slopsquatting |
audit-code-quality | Repo-wide smells and consistency drift |
workflow-refactor | Restructuring live code that stays |
enhance-arch-boundaries | Circular deps and layer direction (dependency-cruiser) |
audit-db-schema | Schema design, constraints, naming |
housekeep-backlog | The TODO/skipped-test register |
workflow-housekeep | README, build artifacts, dependency bumps |
Boundary with plan-dependency-provenance: it owns manifest facts (does
this package exist, is it licensed). This owns the graph fact (nothing
imports it). A package that is real, licensed, and unimported is this
skill's finding.
npx knip --trace-export <name> / --trace-file <path> shows
exactly where Knip lookedkill / keep-config / keep-tagged / chain /
needs-owner, per
references/preservation-contract.mdSkipping Interpret is what turns a cleanup into an outage. A tool finding is evidence, not a verdict.
Report chain heads, not chain members. One dead file explains its own exports and the packages only it imported. Those are children of that row, not rows of their own — otherwise a three-item plan reads as twenty-seven and the phasing is wrong.
Observe: first
npx knipon a Vite + React + Supabase app: 312 findings — 47 unused files, 180 unused exports, 61 unused types, 24 deps. Interpret:src/routes/**is loaded viaimport.meta.glob, so no file imports it;src/types/supabase.tsis generated; everyui/*.tsxre-exports through a barrel;supabase/functions/**is Deno, never in the Vite graph. Classify: config-gap, not dead code. Addentryfor the route glob,ignoreExportsUsedInFilefor interfaces/types, a separate workspace forsupabase/functions, and tag the design-system barrel@public. Re-run: 41 findings — 9 unused files, 22 exports, 6 types, 4 deps. Baseline: 41 default / 12--production. That 12 is the highest- confidence set: dead in shipped code. Plan: kill the 9 files (7 are unused shadcn components — re-addable withnpx shadcn add), 4 deps;@publicthe barrel; 2 exportsneeds-owner(look like a half-built public API).
Config quality decides whether every later number means anything. Read, don't guess:
vite.config.*, next.config.*, astro.config.*,
remix.config.*, expo/metro.config.*, nest-cli.jsonpnpm-workspace.yaml, package.json#workspaces, nx.json,
turbo.json. A monorepo configured as one root project reports the whole
repo as dead.supabase/functions/** (Deno), Cloudflare Workers,
*.sql, native shells. These are never in the app's module graph and must
be separate workspaces or they report 100% unused.types/supabase.ts, *.gen.ts, GraphQL codegen,
Prisma client, route treesrg "import\.meta\.glob|require\.context|await import\(|lazy\(" knip.json, knip.jsonc, package.json#knip,
.jscpd.json, tsconfig noUnusedLocals/noUnusedParametersRecord: package manager, framework, workspace layout, non-Node arms, generated paths, dynamic-import mechanisms, whether tests pass today.
Sequencing note. In the plan loop,
plan-test-coverage(step 3) locks behavior in tests. Running this audit is safe any time; executing it before behavior is locked is the risky order. Say so in the plan.
Install as a devDependency (never a global): npm i -D knip. Requires the
project's own TypeScript.
1a. First run, read hints only.
npx knip
Configuration hints print at the top. Resolve those before reading a single finding. Hints are Knip telling you your config is wrong.
1b. Fix hints in knip.json — not with ignore.
Symptom → correct fix → not-this table (entry patterns, ignoreExportsUsedInFile, paths, ignoreDependencies, --production, the one legitimate ignore): references/knip-config.md §Hint symptom → correct fix.
Knip already respects .gitignore — do not re-list node_modules,
dist, build. Do not duplicate entry points that auto-detected plugins
already add.
1c. Repeat 1a–1b until hints are clean. This loop is the skill. Config
recipes for Vite+React+Supabase, Next.js App Router, and monorepos are in
references/knip-config.md.
Gate before Phase 2. Hints clean, and unresolved imports plus unlisted dependencies both explained. If either is still in the dozens, the config is not done — the resolver is failing, not the code. Triaging findings from a misconfigured run is how false positives become deletions.
Run both modes; Knip's CI guide suggests considering a default run alongside a production run.
npx knip --production # shipped code only: no tests, config, stories, devDeps
npx knip # everything
Read findings in Knip's documented order, because it cascades — "getting the list of unused files right trickles down into the other issue types":
paths gap, not dead codeScope with --files, --exports, --dependencies to read one class at a
time, and --max-show-issues <n> to keep a first pass readable.
--production excludes test files, config files, stories and
devDependencies; --strict additionally isolates workspaces to direct
dependencies. --reporter json is what the baseline numbers come from —
never a hand count.
Delegate a baseline or residue pass to a subagent only when it is sizeable, independent of the others, and its raw output (Knip JSON, grep dumps) has no place in the plan; brief it with the exact commands and the columns to return. It deletes nothing, like this pass. A handful of greps stays in the main context. Long sweeps are expected — context compaction exists, so finish the inventory rather than wrapping up early.
Build the keep-working list. For every finding, ask what would break. Named suspects, each needing a positive reason to keep:
@public (Knip then stops reporting it)@internal@aliasTags beat config here: they live next to the code and Knip reports a tag hint when a tag becomes unnecessary, so the exemption cannot rot.
Knip owns the module graph. These are the classes a vibe-coded repo
accumulates that it will never report. Count each; fix nothing. Exact
commands, false positives, and the fix column are in
references/residue-greps.md.
Run the bundle-leak check even if you skip the rest of this phase:
npm run build && rg -l "service_role|SUPABASE_SERVICE_ROLE" dist. A hit is a live credential in shipped output — stop the pass and go toplan-secrets-audit.
tsc --noEmit under noUnusedLocals + noUnusedParameters, or the linter's unused rule, and record whether the flags are even onnpx jscpd src --min-tokens 50 --reporters json; record duplication % and top clone pairs; a refactor finding, not a deletion finding → workflow-refactorconsole.* / debugger, .only / .skip / .todo / x-prefixed tests (flag .only high), commented-out blocks, utils/helpers dumping grounds@ts-ignore / @ts-expect-error / eslint-disable / biome-ignore and any, counted with rg -o … | wc -l; a stale @ts-expect-error is itself dead codepublic/, assets/, static/ cross-referenced against source, CSS, and HTML; a folder referenced only by template string is needs-owner, not dead.env.example; names only, never print valuessupabase db lint, supabase inspect db unused-indexes, supabase inspect db seq-scans, cross-referenced with .from( / .rpc( / functions.invoke( usage; low scans on a young or read-light database are not evidence; no DROP is authored in this pass
Full commands, caveats, and routing for 3a–3g: references/residue-greps.md §The seven surfaces.plan-dead-code.md [LOW freedom on format]4a. Baseline table — the ratchet's starting line. Numbers only ever go down. Metric | command | today rows (Knip both modes, unused locals, duplication %, debug residue, suppressions, orphan assets, env drift, schema): references/output-templates.md §Baseline table (4a).
4b. Keep/kill list — one row per chain head:
path:line | class | evidence | verdict | sev | effort | children | what must keep working
Verdicts: kill · keep-tagged (@public/@internal/@alias) ·
keep-config (config gap, fix the config) · chain (child of another row) ·
needs-owner (a human must decide). Never guess kill to shrink the list,
and never leave a keep row without naming its remedy — a keep with no remedy
is an ignore in disguise, and the next session will delete it.
A filled example table, with the severity and effort rubric, is in
references/output-templates.md.
4c. Phased burndown — ordered so each phase's verification is meaningful, cheapest-to-review first, and the pre-approved file list going first so later phases do not churn files that are about to be deleted.
4d. Ratchet proposal — the knip script, the CI job with
--max-issues set to today's count, and which aggregator gate it joins.
4e. Cause-not-count callouts. If 40 exports come from one barrel
index.ts, the finding is the barrel, not 40 exports. Name the root
cause so execution fixes one thing instead of forty.
ignore used where entry,
paths, --production, or a tag was the real fix--production and default, reported separatelykill names its evidence;
dynamic/generated/Deno paths were actively checkednot run with a reasonworkflow-refactor; unwired UI →
plan-stub-checker; slop taste → plan-antislop; package existence →
plan-dependency-provenance; circular deps → enhance-arch-boundaries;
destructive SQL → plan-data-integrityknip.json authored; configuration hints clean--production and default baselines capturednot run with a reasonplan-dead-code.md written: baseline, keep/kill list, phases, ratchethousekeep-dead-codeFull template: references/output-templates.md.
knip.json changed and which hint each resolvedPlan only. End the turn with a standalone recap in chat: the two or three highest-impact chain heads and the first phase to approve; the plan file is the deliverable, write it first. Deletion begins in housekeep-dead-code, after approval. The
non-negotiables for this pass are in
references/preservation-contract.md.
What SKILL.md sets; muted values are Claude Code's defaults
highThree short reads, in order
dead-code, knip, code-audit, unused-exports, unused-dependencies
npx claudepluginhub kensaurus/skills --plugin kenji162 skills in this plugin
/audit-accessibilityWCAG 2.2 AA audit via playwright-cli: axe-core, keyboard, contrast, target size, focus, ARIA. Use when "audit accessibility", "check a11y", "WCAG audit", "check keyboard nav", or "test screen reader".
/audit-agent-speedMeasure and fix a slow coding-agent setup: status line, hooks, instruction bloat, effort, worktree pile-up, antivirus and indexer scans. Use when "Claude is slow" or "CPU is pinned". App speed → audit-performance.
/audit-analyticsRead-only audit of product-analytics events (PostHog, Amplitude, Mixpanel, GA4): taxonomy, funnels, consent-gated firing, dead or duplicate events. Use when "audit our analytics", "are we tracking the right events", or "funnel instrumentation".
/audit-auth-flowsRead-only audit of app-layer auth: route×gate matrix, session lifecycle, OAuth, provider traps (getSession vs getUser, middleware-only gates, CVE-2025-29927). Use when "audit our auth" or "check middleware protection". RLS → plan-rls-audit.
/audit-backend-architectureRead-only backend-architecture audit and pattern advisor, gated by stack. Use when "audit backend architecture", "which pattern should I use", "am I over-engineering", or "sync vs event-driven". Enforced boundaries → enhance-arch-boundaries.
/audit-bundle-sizeAnalyse and shrink a web app's JavaScript bundle. Use when "reduce bundle size", "code splitting", "slow initial load", or "why is the bundle so big". Runtime → audit-performance.
Other plugins' skills for the same job