| name | knip |
| description | Run knip to find and remove unused files, dependencies, and exports. Use for cleaning up dead code and unused dependencies. |
Knip Code Cleanup
Run knip to find and remove unused files, dependencies, and exports from this codebase.
Setup
-
Check if knip is available:
- Run
npx knip --version to test
- If it fails or is very slow, check if
knip is in package.json devDependencies
- If not installed locally, install with
npm install -D knip (or pnpm/yarn/bun equivalent based on lockfile present)
-
Knip does NOT remove unused imports/variables inside files — that's a linter's job. Knip finds unused files, dependencies, and exports across the project.
Workflow
Always follow this configuration-first workflow. Even for simple "run knip" or "clean up codebase" prompts, configure knip properly before acting on reported issues.
Step 1: Understand the project
- Check what frameworks and tools the project uses (look at package.json)
- Check if a knip config exists (
knip.json, knip.jsonc, or knip key in package.json)
- If a config exists, review it for improvements (see Configuration Best Practices below)
Step 2: Run knip and read configuration hints first
npx knip
Focus on configuration hints before anything else. These appear at the top of the output and suggest config adjustments to reduce false positives.
Step 3: Address hints by adjusting knip.json
Fix configuration hints before addressing reported issues. Common adjustments:
- Enable/disable plugins for detected frameworks
- Add entry patterns for non-standard entry points