DEV Community

Alex Spinov
Alex Spinov

Posted on

Knip Has a Free Unused Code Finder — Here's How to Use It

Your project has dead code. Unused exports, unreferenced files, unnecessary dependencies — they slow your build, confuse your team, and bloat your bundle. Knip finds and reports all of them.

What Is Knip?

Knip finds unused files, dependencies, and exports in JavaScript and TypeScript projects. Think of it as a linter for your project's dependency graph.

Quick Start

npx knip
Enter fullscreen mode Exit fullscreen mode

No config needed — Knip auto-detects your project structure.

What Knip Finds

  • Unused files — code nobody imports
  • Unused dependencies — packages in package.json nobody uses
  • Unused exports — functions/classes exported but never imported
  • Duplicate dependencies — same package at different versions

Real Impact

A startup ran Knip on their 2-year-old Next.js app:

  • 47 unused files removed
  • 12 unused dependencies removed — 30% faster npm install
  • 89 unused exports cleaned — smaller bundle
  • Build time dropped from 45s to 32s

Configuration

{
  "entry": ["src/index.ts", "src/pages/**/*.tsx"],
  "project": ["src/**/*.{ts,tsx}"],
  "ignore": ["**/*.test.ts"]
}
Enter fullscreen mode Exit fullscreen mode

Plugin System

Knip understands Next.js, Remix, Jest, Vitest, ESLint, Storybook, GitHub Actions, and 40+ more frameworks automatically.

CI Integration

- name: Check for unused code
  run: npx knip
Enter fullscreen mode Exit fullscreen mode

Exits with code 1 if unused items found — perfect for CI gates.

Auto-Fix

npx knip --fix
npx knip --fix --dry-run  # Preview changes
Enter fullscreen mode Exit fullscreen mode

Get Started


Cleaning up your codebase? My Apify scrapers keep data pipelines lean too. Custom solutions: spinov001@gmail.com

Top comments (0)