mcpField

Knip Until Clean

FeaturedOn demand
DependenciesUp to 5 rounds

About Knip Until Clean

Started by hand, this loop runs npx knip to find unused code and dependencies. The agent separates real findings from false positives, removes what is truly unused, and runs knip again in the next round. It stops when knip exits 0 or after 5 rounds.

Key features

  1. 01Manual trigger, started on demand
  2. 02Single check command: npx knip
  3. 03Capped at 5 rounds
  4. 04Success defined by knip's exit code 0

Use cases

  1. 01Clearing unused exports and dependencies before a release
  2. 02Tidying a codebase after a large refactor
  3. 03Bringing a project to a clean knip baseline
Goal
knip reports no unused code or dependencies.
Exit when
Stop when knip exits 0, or when the 5-round limit is reached.
Between iterations run
npx knip

Launch prompt

Paste into Cursor. The agent repeats the steps below until the exit condition is met.

prompt.md
Start the "Knip Until Clean" loop.
Goal: knip reports no unused code or dependencies.
Max iterations: 5.
Step 1: Run knip — Run npx knip and read its report of unused code and dependencies. An exit code of 0 means the project is clean and the loop ends. `npx knip`
Step 2: Triage the findings — Check each reported item to decide whether it is genuinely unused or a false positive. Only genuine findings are acted on.
Step 3: Apply the cleanup — Remove the unused code and dependencies that were confirmed. Then start the next round, until the round limit is reached.
Between iterations run: `npx knip`
Exit when: Stop when knip exits 0, or when the 5-round limit is reached.

Steps

Each round runs in order; if the exit condition isn’t met, another round starts, up to 5.

01
Run knip

Run npx knip and read its report of unused code and dependencies. An exit code of 0 means the project is clean and the loop ends.

$npx knip
02
Triage the findings

Check each reported item to decide whether it is genuinely unused or a false positive. Only genuine findings are acted on.

03
Apply the cleanup

Remove the unused code and dependencies that were confirmed. Then start the next round, until the round limit is reached.

Not met → next roundExits when met

Supported agents

Coding agents that can run this loop directly.

Cursor

Comments

Markdown supported