Introduction
Knip scans JavaScript and TypeScript projects to find files, dependencies, and exports that are no longer used. By identifying dead code and phantom dependencies, it helps developers reduce bundle size, speed up builds, and keep the dependency tree clean without manual auditing.
What Knip Does
- Detects unused source files that are not imported or referenced anywhere in the project
- Finds npm packages listed in package.json that no code actually imports
- Identifies exported functions, types, and variables that have no consumers
- Reports duplicate dependencies present in multiple workspace packages
- Understands framework-specific entry points for Next.js, Remix, Astro, Vite, Jest, and more
Architecture Overview
Knip statically analyzes the project by resolving entry points from package.json scripts, framework configs, and tool configs. It builds an import graph using TypeScript's module resolution, walks every reachable file, and compares the graph against the file system and dependency declarations. Unused nodes in the graph are reported as unused files, exports, or dependencies. Plugin modules teach Knip how each framework and tool defines its own entry points.
Self-Hosting & Configuration
- Install with npm, yarn, or pnpm:
npm install -D knip - Run with
npx knipfrom the project root for zero-config analysis - Add a
knip.jsonorknipfield inpackage.jsonfor custom entry and project patterns - Configure workspace patterns for monorepo setups with per-package overrides
- Integrate into CI by adding
npx knipas a lint step that fails on unused code
Key Features
- Over 100 built-in plugins for frameworks and tools including Next.js, Jest, ESLint, Storybook, and Vitest
- Monorepo support with per-workspace configuration and cross-package reference tracking
- Multiple reporters: compact, JSON, SARIF for CI integration, and GitHub Actions annotations
- Auto-fix mode that removes unused exports and dependencies with
--fix - Fast execution using TypeScript's project references and incremental resolution
Comparison with Similar Tools
- depcheck — checks unused dependencies only; Knip also finds unused files, exports, and types
- ts-prune — finds unused TypeScript exports; Knip covers the full spectrum including deps and files
- unimported — detects unimported files; Knip adds dependency and export analysis on top
- ESLint no-unused-vars — catches unused local variables; Knip works at the module and package level
- webpack-bundle-analyzer — visualizes bundle contents; Knip operates at the source level before bundling
FAQ
Q: Does Knip work with monorepos? A: Yes. It supports npm, yarn, and pnpm workspaces with per-package configuration.
Q: Will it understand my framework's conventions? A: Knip includes plugins for Next.js, Remix, Astro, Angular, Svelte, Jest, Vitest, and many more that register framework-specific entry points automatically.
Q: Can I auto-fix issues?
A: Yes. Run npx knip --fix to automatically remove unused exports and unlisted dependencies.
Q: How fast is it? A: Knip uses TypeScript module resolution and skips unnecessary file reads, analyzing most projects in seconds.