Skip to content
Automation
Skill

/knip-cleanup

Add knip to a TypeScript project and use it to remove dead exports, collapse pass-through barrels, and narrow every export to what another file actually imports. Trigger on "add knip", "set up knip", "find dead code", "remove unused exports", "clean up barrel files", "get rid of

From plugin
jobpilot
6931 skills2 agents2 MCP
Install
$ npx -y skills add suxrobGM/jobpilot --skill knip-cleanup --agent claude-code

How it fires

How this skill gets triggered: by you, by Claude, or both.

  • Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
  • You can call itInvoke it directly when you want it.
  • Slash command/knip-cleanup

Context preview

The summary Claude sees to decide when to auto-load this skill.

Add knip to a TypeScript project and use it to remove dead exports, collapse pass-through barrels, and narrow every export to what another file actually imports. Trigger on "add knip", "set up knip", "find dead code", "remove unused exports", "clean up barrel files", "get rid of

SKILL.md

knip-cleanup.SKILL.md
name: knip-cleanup
description: Add knip to a TypeScript project and use it to remove dead exports, collapse pass-through barrels, and narrow every export to what another file actually imports. Trigger on "add knip", "set up knip", "find dead code", "remove unused exports", "clean up barrel files", "get rid of export *", "why is this exported".
metadata:
  version: "1.0"

Knip Integration and Barrel Cleanup

Four phases, each one committed and verified on its own. Later phases depend on earlier ones: every deletion exposes another layer of dead code, so knip is re-run between them rather than once at the start.

Do not start at phase 3. A knip baseline full of false positives will delete something real.

Phase 0: measure before believing the complaint

If the user also reports line-ending churn on every format, check before changing anything:

git ls-files --eol | awk '{print $1, $2}' | sort | uniq -c | sort -rn | head
<formatter> --check .    # biome check . / prettier --check .

`i/lf w/lf` across the board with a clean formatter run means the tracked tree is already normalized and the churn is in **newly created** files. The fix is prevention, not renormalizing: `.editorconfig` with `end_of_line = lf`, the editor's own EOL setting (`"files.eol": "\n"` for VS Code), and `git config core.autocrlf false` locally. Renormalizing a tree that is already LF produces a huge no-op diff and fixes nothing.

Phase 1: a baseline that is actually true

Install knip at the **repo root**, one config, one script. In a monorepo never give each package its own config: a per-workspace run cannot see that another workspace imports the symbol, so every shared export reads as dead.

{
  "$schema": "https://unpkg.com/knip@<major>/schema.json",
  "tags": ["-knipignore"],
  "workspaces": {
    "packages/lib": {
      "entry": ["src/index.ts", "src/**/*.test.ts"],
      "project": ["src/**/*.ts"],
      "includeEntryExports": true,
      "ignoreExportsUsedInFile": true
    }
  }
}

Then iterate until the report contains **only real findings**. Expect these, in this order:

  • **Every compiled entrypoint must be listed.** Grep the Dockerfiles, CI, and build scripts for

`--outfile`, `--entry`, `bun build`, `esbuild`. A second binary built from `src/worker.ts` is invisible to knip and its whole dependency tree reports as unused.

  • **Config files that read env at load time** (`prisma.config.ts` and friends) crash knip's plugin

loader. Disable that plugin (`"prisma": false`) rather than faking the variable.

  • **`includeEntryExports: true` wherever `package.json` `exports` uses wildcards.** A map like

`"./utils/*": "./src/utils/*.ts"` makes *every file* an entry, and knip then reports nothing at all for that package. Verify by adding a deliberately unused export and confirming knip sees it — silence is the failure mode here, so it will not announce itself.

  • **Framework-indirect dependencies** (`@prisma/client`, `pg`, a JWT lib reached through a plugin)

go in `ignoreDependencies`. Check each one is genuinely reached before ignoring it.

  • **Type-level assertions are not dead code.** A `type XInSync = [Assert<A, B>, Assert<B, A>]`

drift guard has no runtime caller by design. Tag it `@knipignore` (with `"tags": ["-knipignore"]` in the config) and say in a comment what it guards. Deleting it silently removes a check.

Commit the config and the script separately from any deletion.

Phase 2: dead exports, before touching barrels

Pure subtraction, no import churn, so it lands cleanly and reviews easily.

Cross-check every finding against a repo-wide grep before deleting. `files=1 refs=1` (the declaration is the only occurrence) is safe. More than that needs a look, and the reasons split into four:

| What grep shows | What it means | What to do | | --- | --- | --- | | Only the declaration | Truly dead | Delete | | A same-named declaration in another workspace | Duplicate, this copy is dead | Delete this one | | Hits only in a barrel's re-export line | The forwarding line is dead, not the symbol | Handle in phase 3 | | Hits in a comment | Not a reference | Delete |

Then delete, and **re-run knip after deleting**: removing a function usually orphans the data tables and helper types it used, which were invisible while it existed.

Two traps when automating the deletion:

  • Deleting a declaration by brace balance breaks on chained expressions

(`export const x = new Builder().use(a).derive(b)`) — the balance returns to zero mid-chain. Verify with a lint run and hand-edit the mangled file rather than tuning the heuristic.

  • Deletions strand imports and module-level state. Run the formatter's unsafe autofix

(`biome check --write --unsafe`, `eslint --fix`) on the touched files, then read what it could not fix.

Phase 3: barrels, by whether they earn their keep

State the rule before writing any code, because it decides the size of the diff. A barrel stays only when **it aggregates more than one file and has more than one importer outside its own directory**. Everything else is indirection: `export *`, single-file forwarders, and barrels with one caller.

Classify first and show the counts — the split is usually lopsided and tells you where the real work is. In one monorepo it was 168 barrels: 74 `export *`, 75 named, 18 with real code; after the rule, all 45 survivors were frontend component aggregators and the backend kept none.

Two barrels must never be deleted:

  • Anything `package.json` `exports` points at. Deleting `src/utils/index.ts` when the map says

`"./utils": "./src/utils/index.ts"` breaks every consumer, and **typecheck inside that package still passes** — the break only shows up in the packages that import it. `export *` is defensible in exactly this position, since the subpath is the unit of API.

  • A barrel that a *surviving* barrel re-exports from. Repoint the parent's `export ... from` lines

at the concrete files first, then drop the c

Read more
Ships withjobpilot

An AI agent that applies to jobs for you, on the Claude or Codex subscription you already have.

Get the whole plugin

Other skills on jobpilot.