Find and remove unused files, dependencies, and exports in JavaScript/TypeScript projects with Knip. Use when someone asks to "find unused code", "clean up dependencies", "remove dead code", "find unused exports", "Knip", "reduce bundle size by removing unused files", or "audit npm dependencies". Covers unused files, dependencies, exports, types, and CI integration.
Knip finds unused files, dependencies, and exports in your TypeScript/JavaScript project. It understands your project structure — framework entry points, config files, scripts — and reports what's truly unused. Unlike ESLint's no-unused-vars (which only checks within files), Knip works across the entire project: unused exports, orphan files, unlisted dependencies, and packages in package.json that no code actually imports.
npx knip # Zero config — works out of the box
# Or install
npm install -D knip
# Run a full analysis
npx knip
# Output:
# Unused files (2)
# src/utils/legacy-helper.ts
# src/components/OldBanner.tsx
#
# Unused dependencies (3)
# lodash
# moment
# chalk
#
# Unused exports (5)
# src/lib/api.ts: formatDate, parseResponse
# src/types/index.ts: LegacyUser, OldConfig
# src/utils/math.ts: calculateTax
#
# Unlisted dependencies (1)
# dotenv (used in src/config.ts but not in package.json)
// knip.json — Customize detection
{
"entry": ["src/index.ts", "src/server.ts"],
"project": ["src/**/*.{ts,tsx}"],
"ignore": ["**/*.test.ts", "**/*.spec.ts"],
"ignoreDependencies": ["@types/node"],
"ignoreBinaries": ["docker"],
// Framework plugins (auto-detected)
"next": { "entry": ["pages/**/*.tsx", "app/**/*.tsx"] },
"vitest": { "entry": ["**/*.test.ts"] }
}
# .github/workflows/knip.yml — Fail CI on unused code
name: Unused Code Check
on: [pull_request]
jobs:
knip:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm ci
- run: npx knip
# Auto-remove unused exports (adds underscore prefix)
npx knip --fix
# Remove unused files
npx knip --fix --allow-remove-files
# Dry run — see what would change
npx knip --fix --dry-run
User prompt: "This project has 200+ files and we're not sure what's still used. Find all dead code."
The agent will run Knip to identify unused files, exports, and dependencies, then categorize results by confidence level and provide a cleanup plan.
User prompt: "Prevent new dead code from being merged. Add a CI check."
The agent will configure Knip with the project's entry points, add a GitHub Actions workflow, and set up framework plugins for accurate detection.
npx knip — see what it finds before configuring--fix is cautious — it prefixes unused exports with _, doesn't delete--allow-remove-files for cleanup — actually removes orphan filesignore — tests reference things that aren't "used" by app codeignoreDependencies for false positives — runtime-only deps that Knip can't tracenpx skills add TerminalSkills/knip下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer