knip
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "knip":https://skillpi.com/zh/skills/deepskill-752990b7e06b55175b763f8d93db7cb929db59cb1fee286b78c244f0ac096040。安装前核对上游来源和版本:https://skillhub.cn/skills/user_3c6cb52e/knip-unused-code-dependency-finder。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
skillhub.cn
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
运行 Knip 来查找并删除 JavaScript 和 TypeScript 项目中未使用的文件、依赖项和导出,以减少打包大小、维护负担和依赖攻击面。
介绍来源: third_party · user_3c6cb52e · 1.0.0 参考来源
SkillPi 解读
- 能完成的任务
- 来源文档未说明。
- 适合谁
- 翻译待完成,请参阅来源文档。
- 输入和输出
- 来源文档未说明。
- 软件、账号及付费要求
- 翻译待完成,请参阅来源文档。
- 限制与区别
- 来源文档未说明。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: knip
description: >-
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.
license: Apache-2.0
compatibility: "Node.js 18+. TypeScript/JavaScript projects."
metadata:
author: terminal-skills
version: "1.0.0"
category: devops
tags: ["unused-code", "dependencies", "knip", "cleanup", "dead-code"]Knip
Overview
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.
When to Use
- Cleaning up a codebase that's accumulated dead code over time
- Auditing npm dependencies (unused, unlisted, or duplicate)
- Reducing bundle size by removing unused exports
- Pre-refactoring analysis to identify what can be safely deleted
- CI gate to prevent new unused code from being merged
Instructions
Setup
npx knip # Zero config — works out of the box
# Or install
npm install -D knip
What Knip Detects
# 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)
Configuration
// 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"] }
}
CI Integration
# .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
Fix Mode
# 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
Examples
Example 1: Audit a legacy project
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.
Example 2: Add to CI pipeline
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.
Guidelines
- Zero config works — Knip auto-detects frameworks (Next.js, Remix, Vite, etc.)
- Framework plugins are key — they tell Knip about framework-specific entry points
- Start with
npx knip— see what it finds before configuring --fixis cautious — it prefixes unused exports with_, doesn't delete--allow-remove-filesfor cleanup — actually removes orphan files- Ignore test files in
ignore— tests reference things that aren't "used" by app code ignoreDependenciesfor false positives — runtime-only deps that Knip can't trace- Run before major refactors — know what's dead before restructuring
- CI enforcement prevents regression — new dead code fails the build
当前收录版本
1.0.0
安全与评测信息
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 Knip 工具的使用指南,用于查找和删除 JavaScript/TypeScript 项目中未使用的文件、依赖项和导出,具有明确的开发运维场景和广泛受众的实用价值。
亮点
- 触发词精准完整,覆盖多种变体,如 'find unused code', 'clean up dependencies', 'remove dead code' 等,边界清晰。
亮点
- 结构清晰,包含 Overview、When to Use、Instructions、Examples、Guidelines 等章节,步骤划分明确,有端到端示例,frontmatter 完整。
待提升项
-
未覆盖主要异常处理 原报告严重程度:轻微
Skill 提供了 Knip 的安装、运行、配置、CI 集成和修复模式的详细命令和示例,但未明确提及如何处理 Knip 执行过程中可能出现的错误(如配置文件错误、权限问题等),也未说明在哪些情况下 Knip 可能产生误报或漏报。
改进建议:建议补充 Knip 执行过程中常见错误的处理方法,以及误报/漏报的识别和应对策略,以提高执行可靠性。
亮点
- 工具来源明确(npx knip),参数正确,覆盖了主要使用场景。
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
安装或获取外部依赖
使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。
主文档提及 · 第 37, 40, 47, 98, 105 行
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
翻译待完成,请参阅来源文档。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。