Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Comprehensive command-line interface with extensive options for analysis, fixing, and workflow integration. The CLI provides access to all Knip functionality with detailed configuration options.
Core CLI commands for different analysis modes.
# Basic analysis of current project
knip
# Analyze with specific configuration file
knip --config knip.json
knip -c knip.config.js
# Analyze with TypeScript configuration
knip --tsConfig tsconfig.json
knip -t tsconfig.build.json
# Production analysis only (no test files, devDependencies)
knip --production
# Strict mode (only direct dependencies)
knip --strict
# Analyze single workspace
knip --workspace packages/frontend
knip -W packages/backend
# Run from different directory
knip --directory /path/to/project
# Show help
knip --help
knip -h
# Show version
knip --version
knip -VControl what gets analyzed and how.
# Enable caching for faster repeated runs
knip --cache
# Specify cache location
knip --cache-location node_modules/.cache/knip-custom
# Watch mode for continuous analysis
knip --watch
# Don't use .gitignore files
knip --no-gitignore
# Include type definitions from external dependencies
knip --include-libs
# Include entry exports in unused exports report
knip --include-entry-exports
# Isolate workspaces into separate programs
knip --isolate-workspacesControl which types of issues are reported.
# Include only specific issue types (can be repeated)
knip --include dependencies
knip --include dependencies,exports,files
knip --include dependencies --include exports
# Exclude specific issue types (can be repeated)
knip --exclude types
knip --exclude types,classMembers
knip --exclude types --exclude classMembers
# Shortcut for dependency-related issues
knip --dependencies
# Equivalent to: --include dependencies,unlisted,binaries,unresolved
# Shortcut for export-related issues
knip --exports
# Equivalent to: --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates
# Shortcut for unused files only
knip --files
# Equivalent to: --include filesAvailable Issue Types:
files - Unused filesdependencies - Unused dependenciesdevDependencies - Unused devDependenciesoptionalPeerDependencies - Referenced optional peerDependenciesunlisted - Unlisted dependenciesbinaries - Unlisted binariesunresolved - Unresolved importsexports - Unused exportsnsExports - Exports in used namespacetypes - Unused exported typesnsTypes - Exported types in used namespaceenumMembers - Unused exported enum membersclassMembers - Unused exported class membersduplicates - Duplicate exportsAutomatically fix detected issues.
# Fix all fixable issues
knip --fix
# Fix only specific issue types
knip --fix-type exports
knip --fix-type dependencies,exports
knip --fix-type exports --fix-type types
# Allow Knip to remove files (dangerous!)
knip --allow-remove-files
# Format files after fixing
knip --formatFixable Issue Types:
--allow-remove-files)Control output format and verbosity.
# Select reporter (can be repeated for multiple outputs)
knip --reporter symbols # Default terminal output
knip --reporter compact # Compact terminal output
knip --reporter json # JSON format
knip --reporter markdown # Markdown format
knip --reporter codeowners # GitHub CODEOWNERS format
knip --reporter codeclimate # Code Climate format
knip --reporter disclosure # Issue summary
# Multiple reporters
knip --reporter json --reporter markdown
# Pass options to reporters (JSON format)
knip --reporter json --reporter-options '{"indent":2,"sort":true}'
# Don't show dynamic progress updates
knip --no-progress
knip -n
# Suppress configuration hints
knip --no-config-hints
# Treat configuration hints as errors (exit code 1)
knip --treat-config-hints-as-errorsTransform results before reporting.
# Apply preprocessors (can be repeated)
knip --preprocessor sort
knip --preprocessor filter --preprocessor sort
# Pass options to preprocessors (JSON format)
knip --preprocessor-options '{"filter":{"minSeverity":"error"}}'Filter exports based on JSDoc-style tags.
# Include or exclude tagged exports
knip --tags
# Legacy flag (deprecated, use --tags)
knip --experimental-tagsSupported Tags:
@public - Mark as public API@internal - Mark as internal/private@beta - Mark as beta/experimental@alias - Mark as aliasControl CLI exit behavior.
# Always exit with code 0 (success)
knip --no-exit-code
# Set maximum issues before error exit (default: 0)
knip --max-issues 10Exit Codes:
0 - Success (no issues or --no-exit-code)1 - Issues found exceeding --max-issues threshold2 - Runtime error or configuration problemDebugging and performance analysis options.
# Show debug output
knip --debug
knip -d
# Show trace output for analysis
knip --trace
# Trace specific exports
knip --trace-export MyFunction
knip --trace-export MyClass,MyInterface
# Trace exports in specific file
knip --trace-file src/api.ts
# Performance measurement
knip --performance
# Measure specific function performance
knip --performance-fn analyzeSourceFile
# Memory usage tracking
knip --memory
# Real-time memory usage logging
knip --memory-realtimeCommon CLI usage patterns.
# Development workflow
knip --watch --reporter compact
# CI/CD pipeline
knip --production --reporter json --no-progress --max-issues 0
# Pre-commit hook
knip --include exports,types --fix --format
# Code review
knip --reporter markdown > knip-report.md
# Dependency audit
knip --dependencies --reporter json
# Export cleanup
knip --exports --fix --no-exit-code
# Performance analysis
knip --performance --memory --debug
# Monorepo analysis
knip --workspace packages/frontend --production
knip --isolate-workspaces --reporter jsonEnvironment variables that affect CLI behavior.
# Disable progress in CI environments (automatic)
CI=true knip
# Custom cache location
KNIP_CACHE_LOCATION=/tmp/knip-cache knip --cache
# Node environment affects plugin behavior
NODE_ENV=production knipPackage.json Scripts:
{
"scripts": {
"knip": "knip",
"knip:prod": "knip --production --strict",
"knip:fix": "knip --fix --format",
"knip:ci": "knip --reporter json --no-progress"
}
}GitHub Actions:
- name: Run Knip
run: |
npm run knip:ci > knip-results.json
if [ -s knip-results.json ]; then
echo "Issues found:"
cat knip-results.json
exit 1
fiPre-commit Hook:
#!/bin/sh
# .git/hooks/pre-commit
npx knip --include exports --fix --format --no-exit-code
git add -uWatch Script:
#!/bin/bash
# watch-knip.sh
npx knip --watch --reporter compact --no-progressTypeScript interface for CLI arguments (for tool integration).
interface CLIArguments {
/** Configuration file path */
config?: string;
/** TypeScript configuration path */
tsConfig?: string;
/** Production mode */
production?: boolean;
/** Strict mode */
strict?: boolean;
/** Single workspace analysis */
workspace?: string;
/** Working directory */
directory?: string;
/** Enable caching */
cache?: boolean;
/** Cache location */
'cache-location'?: string;
/** Watch mode */
watch?: boolean;
/** Don't use .gitignore */
'no-gitignore'?: boolean;
/** Issue types to include */
include?: string | string[];
/** Issue types to exclude */
exclude?: string | string[];
/** Dependency shortcut */
dependencies?: boolean;
/** Exports shortcut */
exports?: boolean;
/** Files shortcut */
files?: boolean;
/** Fix issues */
fix?: boolean;
/** Fix specific types */
'fix-type'?: string | string[];
/** Allow file removal */
'allow-remove-files'?: boolean;
/** Format after fixing */
format?: boolean;
/** Include external libs */
'include-libs'?: boolean;
/** Include entry exports */
'include-entry-exports'?: boolean;
/** Isolate workspaces */
'isolate-workspaces'?: boolean;
/** Don't show progress */
'no-progress'?: boolean;
/** Preprocessor */
preprocessor?: string | string[];
/** Preprocessor options */
'preprocessor-options'?: string;
/** Reporter */
reporter?: string | string[];
/** Reporter options */
'reporter-options'?: string;
/** Tag filtering */
tags?: string | string[];
/** Disable config hints */
'no-config-hints'?: boolean;
/** Config hints as errors */
'treat-config-hints-as-errors'?: boolean;
/** Always exit 0 */
'no-exit-code'?: boolean;
/** Maximum issues */
'max-issues'?: number;
/** Debug output */
debug?: boolean;
/** Trace output */
trace?: boolean;
/** Trace export */
'trace-export'?: string | string[];
/** Trace file */
'trace-file'?: string | string[];
/** Performance measurement */
performance?: boolean;
/** Performance function */
'performance-fn'?: string | string[];
/** Memory usage */
memory?: boolean;
/** Real-time memory */
'memory-realtime'?: boolean;
/** Show help */
help?: boolean;
/** Show version */
version?: boolean;
}