Skip to content

シンプルなコマンドの例

ファイル: 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.
allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*)
description: Create a git commit

allowed-tools:

  • Bash(git add:*): git add コマンドのみ許可
  • Bash(git status:*): git status コマンドのみ許可
  • Bash(git commit:*): git commit コマンドのみ許可
  • 制限: git pushnpm install などは実行できない

description:

  • コマンドの簡潔な説明
  • /commit と入力したときに表示される
- Current git status: !`git status`

動作:

  1. コマンド実行時に git status が実行される
  2. 実行結果がマークダウンに埋め込まれる
  3. 完成したプロンプトがClaude APIに送信される

実行結果の例:

- Current git status:
modified: src/main.ts
modified: README.md
## Your task
Based on the above changes, create a single git commit.

これがClaude AIへの指示になります。

Terminal window
# ターミナルで
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 main
2. Create a single commit with an appropriate message
3. Push the branch to origin
4. 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.
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作成
1. Create a new branch if on main
2. Create a single commit with an appropriate message
3. Push the branch to origin
4. Create a pull request using `gh pr create`

すべてのステップを順序通りに実行するよう指示。

Terminal window
# コードを変更後
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 が返される

プロジェクトの状態を表示するコマンド。

  1. ディレクトリ作成:
Terminal window
mkdir -p .claude/commands
  1. コマンド定義作成:
Terminal window
cat > .claude/commands/status.md << 'EOF'
---
description: Show project status
allowed-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 activity
3. Project structure overview
EOF
  1. 試す:
Terminal window
claude
# プロンプトで
/status
# Project Status Report
## Git Information
### Current Status
M src/main.ts
M README.md
### Current Branch
feature/new-api
### Recent Commits
abc1234 Add new API endpoint
def5678 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つのコマンドで複数の無関係なタスク

---
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.

悪い例: 必要以上のツールを許可

allowed-tools: Bash(*), Edit(*), Write(*)

良い例: 必要最小限のツールのみ

allowed-tools: Bash(git add:*), Bash(git commit:*)

悪い例: 静的な情報のみ

Please create a git commit.

良い例: 最新情報を動的に取得

Current changes: !`git diff HEAD`
Based on the above, create a git commit.

悪い例: 曖昧な指示

Do something with git.

良い例: 具体的な指示

1. Stage all changes
2. Create a commit with a descriptive message
3. Do not push to remote

問題1: コマンドが見つからない

Section titled “問題1: コマンドが見つからない”

症状: /mycommand と入力しても認識されない

原因: ファイルの配置場所が間違っている

解決:

Terminal window
# プロジェクトレベルのコマンド
.claude/commands/mycommand.md
# プラグインのコマンド
plugins/my-plugin/commands/mycommand.md

症状: “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` (正しいバッククォート)