入門
カスタムスラッシュコマンドを作成する
.claude/commands/ に Markdown ファイルを置いて、よく使うプロンプトをコマンド化する方法
commandsproductivityautomation
カスタムスラッシュコマンドを作成する
Claude Code では、よく使うプロンプトを Markdown ファイルとして定義し、スラッシュコマンドとして呼び出せます。繰り返し入力する指示をコマンド化することで、生産性が大幅に向上します。
コマンドの配置場所
| スコープ | ディレクトリ | 共有範囲 |
|---|---|---|
| プロジェクト | .claude/commands/ | チーム全体(Git管理) |
| ユーザー | ~/.claude/commands/ | 全プロジェクト共通 |
基本的なコマンド作成
例えば .claude/commands/fix-lint.md を作成します。
---
description: "Fix all linting errors in the project"
allowed-tools: ["Bash", "Edit", "Write"]
---
Fix all linting errors in the current project. Run the linter first, identify all issues, and fix them one by one. After fixing, run the linter again to verify all errors are resolved.
セッション内で以下のように呼び出します。
> /fix-lint
引数の使用
コマンド内で引数を参照できます。
---
description: "Review a specific pull request"
argument-hint: "<PR number>"
---
Review pull request $ARGUMENTS. Analyze the code changes, identify potential issues, and provide feedback on code quality, security, and performance.
個別の引数には $1, $2, $3 でアクセスできます。
> /review-pr 456 high-priority
この場合、$ARGUMENTS は "456 high-priority"、$1 は "456"、$2 は "high-priority" になります。
ファイル参照とBash実行
コマンド内でファイルの内容を参照したり、事前にBashコマンドを実行したりできます。
---
description: "Debug test failures"
---
First run the failing tests to see current state:
!`npm test 2>&1 | tail -50`
Then analyze the test output above and @src/test-utils.ts to identify root causes and suggest fixes.
!command`` -- コマンド実行前に Bash コマンドを実行し、出力をコンテキストに含める@path/to/file-- ファイルの内容をコンテキストに含める
サブディレクトリによる名前空間
サブディレクトリでコマンドを整理できます。
.claude/commands/
db/
migrate.md # /db/migrate
seed.md # /db/seed
deploy/
staging.md # /deploy/staging
production.md # /deploy/production
Frontmatter の設定項目
| 項目 | 説明 | デフォルト |
|---|---|---|
description | コマンドの説明 | プロンプトの最初の行 |
argument-hint | 引数のヒント(補完時に表示) | なし |
allowed-tools | 使用可能なツール | セッションから継承 |
model | 使用するモデル | セッションから継承 |
あわせて読む
- /help で機能を体系的に探索する - スラッシュコマンド一覧と探索方法
- MCP ツールをスラッシュコマンドとして呼び出す - MCP サーバーのツールをコマンド化
関連コンテンツ
コマンド
カスタムコマンド
ユーザー定義スラッシュコマンドの作成方法。プロジェクト・ユーザー・MCPの3種類と、テンプレート機能を解説。
Tips
GitHub Actions で Claude Code を CI/CD に組み込む
anthropics/claude-code-action を使って、PRレビュー、自動修正、テスト生成をCIパイプラインに組み込む方法
Tips
/help で機能を体系的に探索する
Claude Code の組み込みヘルプ、スラッシュコマンド一覧、設定確認を活用して機能全体を把握する方法
Tips
Hook でツール実行を自動化する
PreToolUse, PostToolUse, SessionStart などのフックを使って、ツール実行前後に自動処理を組み込む方法