Skip to content


Run Knip as you normally would, and then run it again with the --fix flag to let Knip automatically apply fixes. Currently includes:

  • Remove export keyword for unused exports and exported types
  • Remove unused dependencies and devDependencies from package.json
  • Remove unused files
  • Works across workspaces in a monorepo

Add the --fix flag to remove unused exports and dependencies:

Terminal window
knip --fix

Add --allow-remove-files to allow Knip to remove unused files:

Terminal window
knip --fix --allow-remove-files

Use --fix-type to fix only specific issue types (files, exports, types and/or dependencies). Example:

Terminal window
knip --fix-type exports,types

Use VCS/Git to review and undo changes if necessary.


After Knip has fixed issues, there are two things to consider:

  1. Use tools like ESLint or Biome to find and remove unused variables inside files. This may result in more deleted code, and Knip may then find more unused code. Rinse and repeat!
  2. Verify changes in package.json and update dependencies using your package manager:
Terminal window
npm install

Example results

The export keyword for unused exports is removed:

export const unused = 1;
export default class MyClass {}
const unused = 1
class MyClass {}

The default keyword was also removed here.

Knip cleans up the whole or part of re-exports:

export { Cat, Dog } from './pets';
export { Lion, Elephant } from './jungle';
export { Elephant } from './jungle'

Sometimes lines can be removed completely:

module.exports.UNUSED = 1;
module.exports['ACCESS'] = 1;

Unused dependencies are removed from package.json:

"name": "my-package",
"dependencies": {
"rimraf": "*",
"unused-dependency": "*"
"rimraf": "*"
"devDependencies": {
"unreferenced-package": "5.3.3"
"devDependencies": {}

What’s not included

Operations that auto-fix does not yet perform include:

  • Add unlisted (dev) dependencies to package.json
  • Remove unused class and enum members
  • Remove empty export declarations for less common cases, e.g.:
export const { , } = { a, b };
export const [, ] = [c, d];

ISC License © 2024 Lars Kappert