Loading...
Loading...
Knip finds unused files, dependencies, exports, and types in JavaScript/TypeScript projects. Plugin system for frameworks (React, Next.js, Vite), test runners (Vitest, Jest), and build tools. Use when cleaning up codebases, optimizing bundle size, or enforcing strict dependency hygiene in CI.
npx skill4agent add laurigates/claude-plugins knip-dead-code| Use this skill when... | Use another approach when... |
|---|---|
| Finding unused dependencies | Removing unused CSS (use PurgeCSS) |
| Detecting unused exports in libraries | Finding runtime dead code paths |
| Cleaning up codebases after refactors | Optimizing bundle size (use bundler tree-shaking) |
| Enforcing dependency hygiene in CI | Detecting duplicate dependencies (use npm-dedupe) |
# Project-local (recommended)
bun add --dev knip
# Verify installation
bunx knip --version# Run Knip (scans entire project)
bunx knip
# Show only unused dependencies
bunx knip --dependencies
# Show only unused exports
bunx knip --exports
# Show only unused files
bunx knip --files
# Production mode (only check production dependencies)
bunx knip --production
# Exclude specific issue types
bunx knip --exclude-exports-used-in-file
# Output JSON (for CI)
bunx knip --reporter json
# Debug mode (show configuration)
bunx knip --debugmainexportsbin{
"$schema": "https://unpkg.com/knip@latest/schema.json",
"entry": ["src/index.ts", "src/cli.ts"],
"project": ["src/**/*.ts"],
"ignore": ["**/*.test.ts", "scripts/**"],
"ignoreDependencies": ["@types/*"],
"ignoreBinaries": ["npm-check-updates"]
}// knip.ts
import type { KnipConfig } from 'knip';
const config: KnipConfig = {
entry: ['src/index.ts', 'src/cli.ts'],
project: ['src/**/*.ts', 'scripts/**/*.ts'],
ignore: ['**/*.test.ts', '**/*.spec.ts', 'tmp/**'],
ignoreDependencies: [
'@types/*', // Type definitions
'typescript', // Always needed
],
ignoreExportsUsedInFile: true,
ignoreWorkspaces: ['packages/legacy/**'],
};
export default config;# Fastest check - only dependencies
bunx knip --dependencies
# Exit with error if any unused dependencies
bunx knip --dependencies --max-issues 0# Check for unused exports
bunx knip --exports
# Allow exports used in same file
bunx knip --exports --exclude-exports-used-in-file# Check production code only
bunx knip --production
# Check everything (including dev dependencies)
bunx knipNo unused files
No unused dependencies
2 unused exports
src/utils.ts:
- calculateTax (line 42)
- formatDate (line 58)
src/types.ts:
- UserRole (line 12)| Type | Description | Action |
|---|---|---|
| Unused file | File not imported anywhere | Delete or add to entry points |
| Unused dependency | Package in package.json not used | Remove from dependencies |
| Unused export | Exported but never imported | Remove export or make private |
| Unused type | Type/interface exported but unused | Remove or make internal |
| Unused enum member | Enum member never referenced | Remove member |
| Duplicate export | Same export from multiple files | Consolidate exports |
| Context | Command |
|---|---|
| Quick scan | |
| Dependencies only | |
| Exports only | |
| CI strict mode | |
| Production check | |
| JSON output | |
| Debug config | |
| Changed files | |
| Flag | Description |
|---|---|
| Check only unused dependencies |
| Check only unused exports |
| Check only unused files |
| Production dependencies only |
| Fail if more than N issues |
| JSON output for CI |
| Compact output |
| Show configuration details |
| Check only changed files |
| Changed files since main |
| Check specific workspace |
| Ignore same-file exports |