Claude Codeのカスタムコマンドをチームで共有する
こんにちは😊 kesojiです。
最近、Claude Code を使っています。
Claude Codeにはスラッシュコマンドという仕組みがあり、これは自分たちでもカスタムコマンドを作成できます。これをチームで共有する方法を考えてみました。
作った仕組み
Claude Codeには Slash Commands という、~/.claude/commands
にmarkdownファイルを置くことで独自のコマンドを作成できる機能があります。
この機能を使って、よく使うコマンドをGitリポジトリで管理し、シンボリックリンクで~/.claude/commands
に配置する仕組みを作りました。
なお、カスタムコマンドは awesome-claude-code に色々と例があります
構成
claude-commands/ はgitのリポジトリです。
claude-commands/
├── README.md
├── CLAUDE.md
├── setup-links.sh
├── create-pr.md
├── doctor.sh
├── my-doctor.md
└── update-check.sh
管理用のスクリプト
-
setup-links.sh
: シンボリックリンクを作成するスクリプト -
doctor.sh
: 環境チェック用のスクリプト-
update-check.sh
: doctor.shの中から使う
-
実際のコマンド
-
my-doctor.md
: 環境チェック用のClaudeのスラッシュコマンド -
create-pr.md
: PRを作成するためのClaudeのスラッシュコマンド(サンプル)
セットアップ
チームのメンバーには
- リポジトリのクローン
-
./setup-links.sh
の実行
をしてもらいます。 これで、プロジェクト内の全ての.md
ファイルが~/.claude/commands
にシンボリックリンクとして作成され、コマンドが使えるようになります。
実際のコマンド例
例えば、create-pr.md
はこのような内容になっています。 英語にしているのはトークンの節約のため。
- If on base branch, create a working branch
- Review previous instructions and commit any uncommitted related code
- Include change summary and previous instructions in commit message **in Japanese**
- Create Pull Request against base branch (use gh command, or MCP if unavailable)
- PR content should match commit message unless otherwise specified
これにより、/create-pr
と入力するだけで、一連のPR作成フローをClaudeが実行してくれます。
スラッシュコマンドの中身の作り方は、 公式のビルトインコマンドを参考にできます。 Claude Code Deep Dive 〜t-wada, mizchiとAgentic Codingの「今」を眺める 〜 で中身を見る方法が紹介されていたので、是非確認してください。
更新の仕組み
リポジトリに入って、 git pull
して、 ./setup-links.sh
を実行すればコマンドたちがアップデートされます。
これを自動化するために my-doctor.md
というコマンドも用意しました。
Check git updates and relink commands
This command helps maintain your Claude Commands installation by:
1. Checking for git updates in the claude-commands repository
2. Automatically pulling latest changes if available
3. Re-running setup-links.sh to create symbolic links for any new commands
Run this periodically to keep your commands up to date.
"$(dirname "$(readlink ~/.claude/commands/my-doctor.md)")/doctor.sh"
実行すると、以下のようになります(めっちゃAIが作った感ありますね、はい...)
⎿ 🏥 Claude Commands Doctor - システムの健全性を確認中...
🔄 最新の変更を取得中...
✅ すでに最新バージョンです。
🔗 setup-links.shを再実行中...
Skipped: CLAUDE.md (not a command file)
Skipped: create-pr.md (link already exists)
Skipped: my-doctor.md (link already exists)
Skipped: README.md (not a command file)
Created link: ~/.claude/commands/test.md -> /Users/kesoji/src/github.com/socialdb/claude-commands/test.md
Setup complete!
🏥 システム確認完了!
これを実行することで、アップデートが完了します。
たぶんhooksなど使えばもっとうまくできるんじゃないかとも思っています。
まとめ
Claude Codeのslash commandsをチームで共有する方法と、アップデートの仕組みをちょこっと自動化する仕組みを作りました。
Have a nice Agentic Coding!
Discussion