CC Guide
入門

カスタムスラッシュコマンドを作成する

.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使用するモデルセッションから継承

あわせて読む

関連コンテンツ