中級

Skill を定義して再利用可能なプロンプトを作る

.claude/skills/ に SKILL.md ファイルを作成し、ユーザーとClaudeの両方から呼び出せるスキルを定義する方法

解決の目安約5分
最終確認

確認済みバージョン

Claude Code 2.1.220
Claude Code

必須: Claude Code

skillsreusabilityconfiguration

症状・対象

手順を command として明示実行するだけでなく、該当タスクで Claude に自動選択させたい人が対象です。最初は副作用のない、ユーザー起動専用 Skill を作って発火条件を検証します。

最短解決

  1. .claude/skills/repo-check/SKILL.md を作る。
  2. description に「いつ使うか」、本文に手順と禁止事項を書く。
  3. /repo-check で明示起動し、別の無関係な質問では起動しないことを確認する。

コピペ例

---
description: "Use when the user asks for a read-only repository health check."
disable-model-invocation: true
user-invocable: true
---

# Repository health check

1. Read the project instructions and package scripts.
2. Identify the documented test, type-check, and lint commands.
3. Report the commands before running anything.
4. Run commands only after the user confirms.

Never edit files, install dependencies, or send data externally.

配置は次です。

.claude/skills/
  repo-check/
    SKILL.md

呼び出します。

> /repo-check

期待結果

  • /skills と command 補完に repo-check が現れる。
  • 明示起動時だけ手順が読み込まれる。
  • command を列挙した時点で止まり、確認前に実行や編集をしない。

検証

まず /repo-check で正常系を確認し、次に新しいセッションで無関係な質問をします。disable-model-invocation: true のため、自動起動しなければ意図どおりです。

> /skills
> /doctor

自動選択へ切り替える場合は disable-model-invocation: false にし、対象となる依頼と対象外の依頼を両方テストします。

落とし穴

  • description に長い手順を書くと、発火条件が曖昧になります。「いつ使うか」だけにします。
  • context: fork は現行 version では既定でバックグラウンド実行されます。前景で必要なら background: false を明示します。
  • fork した Skill はメイン会話の全履歴を前提にできません。必要な入力を本文で指定します。
  • 副作用のある deploy や delete Skill は、ユーザー起動専用と明示確認を維持します。

次の一手

関連コンテンツ