シンプルなコマンドの例
例1: /commit コマンド
Section titled “例1: /commit コマンド”ファイル: plugins/commit-commands/commands/commit.md
Section titled “ファイル: plugins/commit-commands/commands/commit.md”---allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*)description: Create a git commit---
## Context
- Current git status: !`git status`- Current git diff (staged and unstaged changes): !`git diff HEAD`- Current branch: !`git branch --show-current`- Recent commits: !`git log --oneline -10`
## Your task
Based on the above changes, create a single git commit.
You have the capability to call multiple tools in a single response. Stage and create the commit using a single message. Do not use any other tools or do anything else. Do not send any other text or messages besides these tool calls.YAMLフロントマター
Section titled “YAMLフロントマター”allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*)description: Create a git commitallowed-tools:
Bash(git add:*):git addコマンドのみ許可Bash(git status:*):git statusコマンドのみ許可Bash(git commit:*):git commitコマンドのみ許可- 制限:
git pushやnpm installなどは実行できない
description:
- コマンドの簡潔な説明
/commitと入力したときに表示される
動的コマンド実行
Section titled “動的コマンド実行”- Current git status: !`git status`動作:
- コマンド実行時に
git statusが実行される - 実行結果がマークダウンに埋め込まれる
- 完成したプロンプトがClaude APIに送信される
実行結果の例:
- Current git status: modified: src/main.ts modified: README.mdプロンプト本文
Section titled “プロンプト本文”## Your task
Based on the above changes, create a single git commit.これがClaude AIへの指示になります。
# ターミナルでclaude
# プロンプトで/commit実行フロー:
1. ユーザーが /commit と入力 ↓2. CLI が commit.md を読み込み ↓3. !`git status` などを実行 ↓4. 結果を埋め込んでプロンプト生成 ↓5. Claude API に送信 ↓6. Claude が git add, git commit を実行 ↓7. コミット完了例2: より複雑な /commit-push-pr コマンド
Section titled “例2: より複雑な /commit-push-pr コマンド”ファイル: plugins/commit-commands/commands/commit-push-pr.md
Section titled “ファイル: plugins/commit-commands/commands/commit-push-pr.md”---allowed-tools: Bash(git checkout --branch:*), Bash(git add:*), Bash(git status:*), Bash(git push:*), Bash(git commit:*), Bash(gh pr create:*)description: Commit, push, and open a PR---
## Context
- Current git status: !`git status`- Current git diff (staged and unstaged changes): !`git diff HEAD`- Current branch: !`git branch --show-current`
## Your task
Based on the above changes:
1. Create a new branch if on main2. Create a single commit with an appropriate message3. Push the branch to origin4. Create a pull request using `gh pr create`5. You have the capability to call multiple tools in a single response. You MUST do all of the above in a single message. Do not use any other tools or do anything else. Do not send any other text or messages besides these tool calls.より多くのツール許可
Section titled “より多くのツール許可”allowed-tools: Bash(git checkout --branch:*), Bash(git add:*), Bash(git status:*), Bash(git push:*), Bash(git commit:*), Bash(gh pr create:*)git checkout --branch: ブランチ作成git push: リモートへプッシュgh pr create: GitHub PR作成
複数ステップのタスク
Section titled “複数ステップのタスク”1. Create a new branch if on main2. Create a single commit with an appropriate message3. Push the branch to origin4. Create a pull request using `gh pr create`すべてのステップを順序通りに実行するよう指示。
# コードを変更後claude
# プロンプトで/commit-push-pr実行フロー:
1. git branch --show-current で現在のブランチ確認 ↓2. mainブランチなら新しいブランチを作成 git checkout -b feature/new-feature ↓3. 変更をステージング git add . ↓4. コミット作成 git commit -m "Add new feature" ↓5. リモートにプッシュ git push -u origin feature/new-feature ↓6. PRを作成 gh pr create --title "..." --body "..." ↓7. PR URL が返される例3: カスタムコマンドを作る
Section titled “例3: カスタムコマンドを作る”目標: /status コマンド
Section titled “目標: /status コマンド”プロジェクトの状態を表示するコマンド。
- ディレクトリ作成:
mkdir -p .claude/commands- コマンド定義作成:
cat > .claude/commands/status.md << 'EOF'---description: Show project statusallowed-tools: Bash(git status:*), Bash(git branch:*), Bash(npm:*), Bash(ls:*)---
# Project Status Report
## Git Information
### Current Status!`git status --short`
### Current Branch!`git branch --show-current`
### Recent Commits!`git log --oneline -5`
## Project Information
### Package Dependencies!`npm list --depth=0 2>/dev/null || echo "No npm project"`
### Project Files!`ls -lh`
## Your Task
Based on the above information, provide a concise summary of:1. Current git state (clean/dirty, current branch)2. Recent development activity3. Project structure overviewEOF- 試す:
claude# プロンプトで/status# Project Status Report
## Git Information
### Current StatusM src/main.tsM README.md
### Current Branchfeature/new-api
### Recent Commitsabc1234 Add new API endpointdef5678 Update documentation...
## Summary
Your project is currently on the `feature/new-api` branch with 2 modified files.Recent activity shows API endpoint development and documentation updates.The project contains 15 npm packages...コマンド設計のベストプラクティス
Section titled “コマンド設計のベストプラクティス”1. 単一責任原則
Section titled “1. 単一責任原則”❌ 悪い例: 1つのコマンドで複数の無関係なタスク
---description: Do everything---
Commit code, run tests, deploy to production, and send email notifications.✅ 良い例: 1つのコマンドは1つの明確なタスク
---description: Create a git commit---
Based on the current changes, create a single git commit.2. ツールの最小権限
Section titled “2. ツールの最小権限”❌ 悪い例: 必要以上のツールを許可
allowed-tools: Bash(*), Edit(*), Write(*)✅ 良い例: 必要最小限のツールのみ
allowed-tools: Bash(git add:*), Bash(git commit:*)3. 動的コンテキストの活用
Section titled “3. 動的コンテキストの活用”❌ 悪い例: 静的な情報のみ
Please create a git commit.✅ 良い例: 最新情報を動的に取得
Current changes: !`git diff HEAD`Based on the above, create a git commit.4. 明確な指示
Section titled “4. 明確な指示”❌ 悪い例: 曖昧な指示
Do something with git.✅ 良い例: 具体的な指示
1. Stage all changes2. Create a commit with a descriptive message3. Do not push to remoteトラブルシューティング
Section titled “トラブルシューティング”問題1: コマンドが見つからない
Section titled “問題1: コマンドが見つからない”症状: /mycommand と入力しても認識されない
原因: ファイルの配置場所が間違っている
解決:
# プロジェクトレベルのコマンド.claude/commands/mycommand.md
# プラグインのコマンドplugins/my-plugin/commands/mycommand.md問題2: allowed-toolsでエラー
Section titled “問題2: allowed-toolsでエラー”症状: “Tool not allowed” エラー
原因: 必要なツールが許可されていない
解決:
# パターンを確認allowed-tools: Bash(git:*) # すべてのgitコマンドallowed-tools: Bash(git add:*) # git add のみallowed-tools: Bash(git add:*), Bash(git commit:*) # 複数問題3: 動的コマンドが実行されない
Section titled “問題3: 動的コマンドが実行されない”症状: !`command` がそのまま表示される
原因: バッククォートの形式が間違っている
解決:
❌ !`command` (通常のバッククォート - これは認識されない場合がある)✅ !`command` (正しいバッククォート)次のステップ
Section titled “次のステップ”- フックシステムの例 - イベント駆動の処理を学ぶ
- マルチエージェントの例 - 複雑なワークフローを理解する