jpskill.com
🛠️ 開発・MCP コミュニティ

knip

JavaScript/TypeScriptプロジェクトで、使われていないファイルや依存関係、エクスポートをKnipで探し出して削除することで、コードの整理や依存関係の最適化、バンドルサイズの削減などを支援するSkill。

📜 元の英語説明(参考)

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.

🇯🇵 日本人クリエイター向け解説

一言でいうと

JavaScript/TypeScriptプロジェクトで、使われていないファイルや依存関係、エクスポートをKnipで探し出して削除することで、コードの整理や依存関係の最適化、バンドルサイズの削減などを支援するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o knip.zip https://jpskill.com/download/15042.zip && unzip -o knip.zip && rm knip.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15042.zip -OutFile "$d\knip.zip"; Expand-Archive "$d\knip.zip" -DestinationPath $d -Force; ri "$d\knip.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して knip.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → knip フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Knip

概要

Knip は、TypeScript/JavaScript プロジェクトで使用されていないファイル、依存関係、およびエクスポートを検出します。プロジェクトの構造(フレームワークのエントリポイント、設定ファイル、スクリプト)を理解し、実際に使用されていないものを報告します。ESLint の no-unused-vars(ファイル内のみをチェック)とは異なり、Knip はプロジェクト全体を対象とします。つまり、未使用のエクスポート、孤立したファイル、リストにない依存関係、およびコードが実際にインポートしていない package.json 内のパッケージを検出します。

使用場面

  • 時間の経過とともに不要なコードが蓄積されたコードベースのクリーンアップ
  • npm 依存関係の監査(未使用、リストにない、または重複)
  • 未使用のエクスポートを削除することによるバンドルサイズの削減
  • 安全に削除できるものを特定するためのリファクタリング前の分析
  • 新しい未使用コードがマージされるのを防ぐための CI ゲート

手順

セットアップ

npx knip  # 設定不要 — すぐに使用可能

# またはインストール
npm install -D knip

Knip が検出するもの

# 完全な分析を実行
npx knip

# 出力:
# 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 — 検出をカスタマイズ
{
  "entry": ["src/index.ts", "src/server.ts"],
  "project": ["src/**/*.{ts,tsx}"],
  "ignore": ["**/*.test.ts", "**/*.spec.ts"],
  "ignoreDependencies": ["@types/node"],
  "ignoreBinaries": ["docker"],
  // フレームワークプラグイン(自動検出)
  "next": { "entry": ["pages/**/*.tsx", "app/**/*.tsx"] },
  "vitest": { "entry": ["**/*.test.ts"] }
}

CI 連携

# .github/workflows/knip.yml — 未使用コードがある場合に CI を失敗させる
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 モード

# 未使用のエクスポートを自動的に削除(アンダースコアのプレフィックスを追加)
npx knip --fix

# 未使用ファイルを削除
npx knip --fix --allow-remove-files

# ドライラン — 変更内容を確認
npx knip --fix --dry-run

例 1: レガシープロジェクトの監査

ユーザープロンプト: "このプロジェクトには 200 以上のファイルがあり、何がまだ使用されているか分かりません。すべての不要なコードを見つけてください。"

エージェントは Knip を実行して、未使用のファイル、エクスポート、および依存関係を特定し、信頼度レベルごとに結果を分類して、クリーンアップ計画を提供します。

例 2: CI パイプラインに追加

ユーザープロンプト: "新しい不要なコードがマージされるのを防ぎます。CI チェックを追加してください。"

エージェントは、プロジェクトのエントリポイントで Knip を設定し、GitHub Actions ワークフローを追加し、正確な検出のためにフレームワークプラグインを設定します。

ガイドライン

  • 設定不要で動作 — Knip はフレームワーク(Next.js、Remix、Vite など)を自動検出します。
  • フレームワークプラグインが重要 — フレームワーク固有のエントリポイントを Knip に伝えます。
  • npx knip から開始 — 設定する前に何が見つかるかを確認します。
  • --fix は慎重 — 未使用のエクスポートに _ のプレフィックスを付け、削除はしません。
  • クリーンアップには --allow-remove-files — 実際に孤立したファイルを削除します。
  • ignore でテストファイルを無視 — テストはアプリのコードで「使用」されていないものを参照します。
  • 誤検出の場合は ignoreDependencies — Knip が追跡できないランタイム専用の依存関係。
  • 大規模なリファクタリングの前に実行 — 再構築する前に、何が不要かを知っておきます。
  • CI による強制でリグレッションを防止 — 新しい不要なコードがあるとビルドが失敗します。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

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
  • --fix is cautious — it prefixes unused exports with _, doesn't delete
  • --allow-remove-files for cleanup — actually removes orphan files
  • Ignore test files in ignore — tests reference things that aren't "used" by app code
  • ignoreDependencies for 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