Skill を定義して再利用可能なプロンプトを作る
.claude/skills/ に SKILL.md ファイルを作成し、ユーザーとClaudeの両方から呼び出せるスキルを定義する方法
Skill を定義して再利用可能なプロンプトを作る
Claude Code の Skills 機能を使うと、再利用可能なプロンプトを定義できます。カスタムスラッシュコマンドと異なり、スキルはユーザーからの明示的な呼び出しだけでなく、Claude が文脈に応じて自動的に参照することも可能です。
スキルのディレクトリ構造
.claude/skills/
hello/
SKILL.md
code-review/
SKILL.md
deploy/
SKILL.md
各スキルはディレクトリ内の SKILL.md ファイルとして定義します。
SKILL.md の基本構造
---
description: "Generate database migration files for schema changes. Use when modifying Prisma schema or adding new tables."
disable-model-invocation: false
user-invocable: true
context: inline
---
# Database Migration Generator
## Instructions
When generating database migrations:
1. Read the current Prisma schema at `prisma/schema.prisma`
2. Identify what changed since last migration
3. Generate appropriate migration SQL
4. Create a descriptive migration name
## Rules
- Always include `up` and `down` migrations
- Use transactions for data migrations
- Add indexes for new foreign keys
- Never drop data without confirmation
Frontmatter の設定項目
| 項目 | 型 | 説明 |
|---|---|---|
description | string | スキルの説明(いつ使うべきかを記述) |
disable-model-invocation | boolean | true の場合、ユーザーのみ呼び出し可能(例: /deploy) |
user-invocable | boolean | false の場合、/メニューに非表示(Claudeのみ呼び出し) |
context | string | fork で独立サブエージェント環境で実行 |
agent | string | context: fork 時のエージェントタイプ |
コンテキストフォークの活用
context: fork を設定すると、スキルが独立したサブエージェント環境で実行されます。メインの会話履歴にアクセスできないため、安全な独立処理に適しています。
---
description: "Security scan of the codebase"
context: fork
agent: Explore
---
Scan the codebase for security vulnerabilities...
プラグインスキル
プラグインも plugin.json の skills パス経由でスキルを定義できます。Superpowers プラグインの14のスキルや、Everything Claude Code の150のスキルがこの仕組みで動作しています。
自動呼び出しの仕組み
Claude はスキルの description を読み、現在のタスクに適用できるかを判断します。そのため、description には「何をするスキルか」ではなく「いつ使うべきか」を記述することが重要です。
---
description: "Use when implementing new API endpoints or modifying existing routes"
---
スキルとコマンドの使い分け
| 特徴 | Skill | Custom Command |
|---|---|---|
| Claudeからの自動参照 | 可能 | 不可 |
| ユーザーからの呼び出し | /skill-name | /command-name |
| フォーク実行 | 対応 | 非対応 |
| 引数 | 非対応 | $ARGUMENTS 対応 |
| 目的 | 再利用可能な振る舞い定義 | 定型プロンプトのショートカット |
あわせて読む
- カスタムエージェントで専門タスクを委任する - エージェント定義の基本
- Claude Code プラグインを開発・公開する - プラグイン構造の全体像
関連コンテンツ
Superpowers 実践ガイド
Superpowers(v5.0.7)の14スキルを活用した標準開発パイプライン。ブレスト、計画、実装、レビューの全フローを解説。
CLAUDE.md でプロジェクトのルールを定義する
CLAUDE.md ファイルを使ってプロジェクト固有の指示を永続化し、全セッションで自動適用する方法
Hook でツール実行を自動化する
PreToolUse, PostToolUse, SessionStart などのフックを使って、ツール実行前後に自動処理を組み込む方法
Claude Code スキルシステム
Claude Codeのスキル定義方法。SKILL.mdの構造、Frontmatter、プラグインスキル、コンテキストフォーク実行を解説。