Monorepos & Workspaces
Workspaces are handled out-of-the-box by Knip.
Workspaces are sometimes also referred to as package-based monorepos, or as
packages in a monorepo. Knip uses the term workspace exclusively to indicate a
directory that has a package.json.
Configuration
Section titled “Configuration”Here’s example configuration with custom entry and project patterns:
{ "workspaces": { ".": { "entry": "scripts/*.js", "project": "scripts/**/*.js" }, "packages/*": { "entry": "{index,cli}.ts", "project": "**/*.ts" }, "packages/cli": { "entry": "bin/cli.js" } }}Each workspace has the same default configuration.
The root workspace is named "." under workspaces (like in the example
above).
Workspaces
Section titled “Workspaces”Knip reads workspaces from four possible locations:
- The
workspacesarray inpackage.json(npm, Bun, Yarn, Lerna) - The
packagesarray inpnpm-workspace.yaml(pnpm) - The
workspaces.packagesarray inpackage.json(legacy) - The
workspacesobject in Knip configuration
The workspaces in Knip configuration (4) not already defined in the root
package.json or pnpm-workspace.yaml (1, 2, 3) are added to the analysis.
For projects with only a root package.json, please see integrated
monorepos.
Additional workspaces
Section titled “Additional workspaces”If a workspace is not configured as such in package.json#workspaces (or
pnpm-workspace.yaml) it can be added to the Knip configuration manually. Add
its path to the workspaces configuration object the same way as
"packages/cli": {} in the example above.
Source mapping
Section titled “Source mapping”See Source Mapping.
Package aliases
Section titled “Package aliases”A workspace package referenced through a workspace: alias in package.json,
such as "test-utils": "workspace:@org/test-utils@*", resolves to the aliased
workspace in the workspace that declares the alias and in the workspaces nested
in it. This includes imports of its exports subpaths through the alias.
Additional options
Section titled “Additional options”The following options are available inside workspace configurations:
- ignore
- ignoreBinaries
- ignoreDependencies
- ignoreIssues
- ignoreMembers
- ignoreUnresolved
- includeEntryExports
- includeSubpathExports
Plugins can be configured separately per workspace.
Use --debug for verbose output and see the workspaces Knip includes, their
configurations, enabled plugins, glob options and resolved files.
Filter workspaces
Section titled “Filter workspaces”Use the --workspace (or -W) argument to select one or more workspaces:
knip --workspace packages/my-libThe filter supports multiple formats:
knip --workspace @myorg/my-lib # Package nameknip --workspace '@myorg/*' # Package name globknip --workspace packages/my-lib # Directory pathknip --workspace './apps/*' # Directory globCombine selectors to include or exclude workspaces:
knip --workspace @myorg/* --workspace '!@myorg/legacy'knip --workspace './apps/*' --workspace '@shared/utils'This will include the target workspace(s), but also ancestor, dependency and dependent workspaces. For three reasons:
- Ancestor workspaces may list dependencies in
package.jsonthe linted workspace uses. - Dependency workspaces may provide configuration and source information used by the linted workspace.
- Dependent workspaces may reference exports from the linted workspace.
To lint the workspace in isolation, there are two options:
- Combine the
workspaceargument with strict production mode. - Run Knip from inside the workspace directory.
ISC License © 2026Lars Kappert