setup-knip
БесплатноБез исполняемых скриптовНе проверенInstall and configure Knip for dead code detection. Use before running dead-code-hunter or dependency-auditor to ensure Knip is available. Handles…
от maslennikov-ig★ 271 звезда на GitHubОб этом скилле
Setup Knip
Install and configure Knip - the tool for finding unused files, dependencies, and exports in JavaScript/TypeScript projects.
When to Use
- Before running dead-code-hunter agent
- Before running dependency-auditor agent
- When project doesn't have Knip configured
- When upgrading Knip configuration
- In pre-flight validation of health workflows
Instructions
Step 1: Check if Knip is Installed
Check package.json for knip in devDependencies.
Tools Used: Read
# Read package.json and check for knip
Check Logic:
- If
devDependencies.knipexists → Knip is installed - If not found → Need to install
Step 2: Install Knip if Missing
If Knip is not installed, add it as devDependency.
Tools Used: Bash
# Detect package manager
if [ -f "pnpm-lock.yaml" ]; then
pnpm add -D knip
elif [ -f "yarn.lock" ]; then
yarn add -D knip
elif [ -f "bun.lockb" ]; then
bun add -D knip
else
npm install -D knip
fi
Expected Output:
+ [email protected]
Step 3: Check for Knip Configuration
Look for existing Knip configuration files.
Tools Used: Glob
Configuration Files (in priority order):
knip.jsonknip.jsoncknip.tsknip.config.tsknip.config.jspackage.json(knip field)
Step 4: Create Default Configuration if Missing
If no configuration found, create knip.json with sensible defaults.
Tools Used: Write
Default Configuration for Standard Project:
{
"$schema": "https://unpkg.com/knip@5/schema.json",
"entry": ["src/index.{ts,tsx,js,jsx}", "src/main.{ts,tsx,js,jsx}"],
"project": ["src/**/*.{ts,tsx,js,jsx}"],
"ignore": [
"**/*.d.ts",
"**/*.test.{ts,tsx}",
"**/*.spec.{ts,tsx}",
"**/test/**",
"**/tests/**",
"**/__tests__/**",
"**/node_modules/**"
],
"ignoreDependencies": [
"@types/*"
]
}
Default Configuration for Next.js Project (detected by next in dependencies):
{
"$schema": "https://unpkg.com/knip@5/schema.json",
"entry": [
"src/app/**/*.{ts,tsx}",
"src/pages/**/*.{ts,tsx}",
"app/**/*.{ts,tsx}",
"pages/**/*.{ts,tsx}"
],
"project": ["src/**/*.{ts,tsx}", "app/**/*.{ts,tsx}", "pages/**/*.{ts,tsx}"],
"ignore": [
"**/*.d.ts",
"**/*.test.{ts,tsx}",
"**/*.spec.{ts,tsx}",
"**/node_modules/**"
],
"next": {
"entry": [
"next.config.{js,ts,mjs}",
"middleware.{js,ts}"
]
}
}
Default Configuration for Monorepo (detected by workspaces in package.json):
{
"$schema": "https://unpkg.com/knip@5/schema.json",
"workspaces": {
"packages/*": {
"entry": ["src/index.{ts,tsx,js,jsx}"],
"project": ["src/**/*.{ts,tsx,js,jsx}"]
},
"apps/*": {
"entry": ["src/index.{ts,tsx,js,jsx}", "src/main.{ts,tsx,js,jsx}"],
"project": ["src/**/*.{ts,tsx,js,jsx}"]
}
},
"ignore": [
"**/*.d.ts",
"**/*.test.{ts,tsx}",
"**/*.spec.{ts,tsx}",
"**/node_modules/**"
]
}
Step 5: Add npm Scripts if Missing
Check if package.json has knip scripts, add if missing.
Tools Used: Read, Bash
Scripts to Add:
{
"scripts": {
"knip": "knip",
"knip:fix": "knip --fix",
"knip:deps": "knip --dependencies",
"knip:exports": "knip --exports",
"knip:files": "knip --files"
}
}
Add via npm pkg:
npm pkg set scripts.knip="knip"
npm pkg set scripts.knip:fix="knip --fix"
npm pkg set scripts.knip:deps="knip --dependencies"
npm pkg set scripts.knip:exports="knip --exports"
npm pkg set scripts.knip:files="knip --files"
Step 6: Validate Installation
Run Knip to verify installation works.
Tools Used: Bash
npx knip --help
Expected: Help output displayed without errors
Step 7: Return Result
Return structured result indicating setup status.
Expected Output:
{
"installed": true,
"version": "5.x.x",
"config_file": "knip.json",
"config_created": true,
"scripts_added": ["knip", "knip:fix", "knip:deps", "knip:exports", "knip:files"],
"project_type": "nextjs|monorepo|standard",
"ready": true
}
Error Handling
- Installation fails: Return error with package manager output
- Configuration invalid: Return error with validation details
- Permission denied: Return error suggesting sudo or permission fix
- Network error: Return error suggesting offline installation
Examples
Example 1: Fresh Project (No Knip)
Initial State:
- package.json exists
- No knip in devDependencies
- No knip.json
Actions:
- Install knip via detected package manager
- Detect project type (standard)
- Create knip.json with defaults
- Add npm scripts
- Validate installation
Output:
{
"insta
Установить setup-knip в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
BashReadWriteGlobFAQ
Что делает скилл setup-knip?
Install and configure Knip for dead code detection. Use before running dead-code-hunter or dependency-auditor to ensure Knip is available. Handles installation, configuration creation, and validation.
Как установить скилл setup-knip?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл setup-knip запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic