Production Mode
The default mode for Knip is comprehensive and targets all project code, including configuration files, test files, Storybook stories, and so on. Test files usually import production files. This prevents production files or their exports from being reported as unused, while sometimes both of them can be deleted. Knip features a “production mode” to focus only on the code that you ship.
Configuration
Section titled “Configuration”To tell Knip what is production code, add an exclamation mark behind each
pattern! that represents production code:
{ "entry": ["src/index.ts!", "build/script.js"], "project": ["src/**/*.ts!", "build/*.js"]}The default mode uses these patterns too, no need to list them again without
!.
Depending on file structure and enabled plugins, you might not need to modify your configuration at all.
Run Knip with the --production flag:
knip --productionHere’s what’s included in production mode:
- Only
entryandprojectpatterns suffixed with! - Only production
entryfile patterns exported by plugins (such as Next.js and Remix) - Only the
startscript (ofpackage.json#scripts) - Ignore exports with the
@internaltag
Files referenced only from development scripts or plugin configuration, such as
a test setup file or a custom test reporter, are excluded from the analysis. A
file that is also a production entry stays included. These references do not
count as dependency usage, so a package in dependencies that only test or
tooling configuration uses is reported as unused.
Unused subpaths in package.json are not reported, since files excluded from
the analysis, such as tests, may import them.
To see the difference between default and production mode in great detail, use
the --debug flag and inspect what entry and project files are used, and the
plugins that are enabled. For instance, in production mode this shows that files
such as tests and Storybook files (stories) are excluded from the analysis.
In case files like mocks and test helpers are reported as unused files, use negated patterns to exclude those files in production mode:
{ "entry": ["src/index.ts!"], "project": ["src/**/*.ts!", "!src/test-helpers/**!"]}Also see configuring project files to align entry and project with
production mode.
Strict Mode
Section titled “Strict Mode”In production mode, only dependencies (not devDependencies) are considered
when finding unused or unlisted dependencies.
Additionally, the --strict flag can be added to:
- Verify isolation: workspaces should use strictly their own
dependencies - Include required
peerDependencieswhen finding unused or unlisted dependencies - Distinguish development-only type imports from types exposed to package consumers
knip --production --strictUsing --strict implies --production, so the latter can be omitted.
Add --exclude types if you don’t want to include types in the report:
knip --production --exclude typesISC License © 2026Lars Kappert