slash-commands について
Claude Codeでユーザーが呼び出すスラッシュコマンドを作成・利用するためのリファレンススキルです。コマンドファイル、引数、Bash実行、ファイル参照と、スキルとの違いを説明します。
主な機能
- 01組み込みコマンド一覧
- 02プロジェクト用・個人用コマンドの設定
- 03YAMLフロントマターと引数
- 04プロンプト内でのBash実行
- 05ファイル参照と名前空間
- 06MCPサーバーが提供するコマンド
活用シーン
- 01再利用可能なプロンプトの作成
- 02コマンドへの引数とファイル参照の追加
- 03プロンプト読み込み前のBash実行
- 04スラッシュコマンドとスキルの使い分け
MCP 対応
MCPサーバーがプロンプトをスラッシュコマンドとして公開できることを説明し、呼び出し例を示します。
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ parcadei/ continuous-claude-v3 --skill slash-commandsインストール後、Claude Code で/slash-commandsを入力して読み込まれたか確認します。
詳細
スラッシュコマンドのリファレンス
/command-name 構文を使って、ユーザーが呼び出すプロンプトを作成して使用します。
使用する場面
- 「スラッシュコマンドを作成するにはどうすればよいですか?」
- 「どのようなスラッシュコマンドを使用できますか?」
- 「コマンドに bash を追加する」
- 「コマンドでファイル参照を使用する」
- 「スラッシュコマンドとスキルの違い」
組み込みコマンド
| コマンド | 目的 |
|---|---|
/clear | 会話履歴を消去する |
/compact | 焦点を絞って会話を圧縮する |
/config | 設定インターフェースを開く |
/cost | トークン使用量を表示する |
/agents | サブエージェントを管理する |
/mcp | MCP サーバーを管理する |
/memory | CLAUDE.md ファイルを編集する |
/model | AI モデルを選択する |
/review | コードレビューを依頼する |
/resume | セッションを再開する |
/help | 使用方法に関するヘルプを表示する |
コマンドの作成
プロジェクトコマンド
mkdir -p .claude/commands
cat > .claude/commands/optimize.md << 'EOF'
---
description: Analyze code for performance issues
---
Review this code for:
- Performance bottlenecks
- Memory leaks
- Caching opportunities
EOF
個人用コマンド
mkdir -p ~/.claude/commands
cat > ~/.claude/commands/review.md << 'EOF'
---
description: Security-focused code review
---
Check for vulnerabilities:
- Input validation
- SQL injection
- XSS risks
EOF
コマンドファイルの形式
---
description: Brief description for /help
allowed-tools: [Bash, Read, Write] # Optional
argument-hint: "[file] [type]" # Optional
---
Your markdown instructions here.
Use $1, $2 for arguments or $ARGUMENTS for all.
Bash の実行
! 接頭辞を使うと、プロンプトを読み込む前に bash を実行できます。
---
allowed-tools: Bash(git:*), Bash(grep:*)
description: Git commit helper
---
Current status: !`git status`
Staged changes: !`git diff --staged`
Recent commits: !`git log --oneline -5`
Based on these changes, suggest a commit message.
ルール:
- フロントマターに
allowed-tools: Bash(...)を宣言する必要があります - バッククォートを使用します:
!`command` - 出力は Claude のコンテキストに含まれます
ファイル参照
@ 接頭辞を使ってファイルを含めます。
Review against @.claude/STYLE_GUIDE.md
Compare:
- @src/old.js
- @src/new.js
Refactor files matching @src/**/*.util.ts
引数
---
argument-hint: "[pr-number] [priority]"
---
Review PR #$1 with priority: $2
# Or use all arguments:
Fix issue #$ARGUMENTS
使用方法:
/review-pr 456 high
# $1 = "456", $2 = "high"
名前空間
サブディレクトリを使って整理します。
.claude/commands/
├── frontend/
│ └── component.md → /component (project:frontend)
└── backend/
└── endpoint.md → /endpoint (project:backend)
MCP スラッシュコマンド
MCP サーバーはプロンプトをコマンドとして公開します。
/mcp__github__list_prs
/mcp__github__pr_review 456
/mcp__jira__create_issue "Bug" high
スラッシュコマンドとスキルの違い
| 項目 | スラッシュコマンド | スキル |
|---|---|---|
| 呼び出し | 明示的:/command | 自動検出 |
| ファイル | 単一の .md ファイル | SKILL.md を含むディレクトリ |
| 用途 | 手軽なプロンプト | 複雑なワークフロー |
スラッシュコマンドの用途: 頻繁に入力するプロンプト、シンプルなテンプレート
スキルの用途: 複雑なワークフロー、複数のファイル、自動検出
例:Git コミットコマンドの全体像
---
description: Generate semantic commit message
allowed-tools: Bash(git:*), Read
argument-hint: "[type]"
---
# Semantic Commit Generator
Staged files: !`git diff --name-only --cached`
Diff preview:
!`git diff --cached | head -100`
Generate a conventional commit message.
Type: $1 (feat/fix/docs/style/refactor/perf/test/chore)
Format: `<type>(<scope>): <subject>`
使用方法: /commit feat
コメント
Markdown 対応