カスタムコマンド
from Claude Code in Action
プロジェクトでよく使うプロンプトをClade Codeのコマンドとして登録することができる
.claude/commands配下マークダウンファイルを作成する。ファイル名をそのままコマンドとして使用できる
カスタムコマンドを使用する際には、$ARGUMENTSを使って引数を受け入れることができる
1. 例えば以下のカスタムコマンドを作成したとする。一行目に$ARGUMENTSを入れている
code:write_tests_md
Write comprehensive tests for: $ARGUMENTS
Testing conventions:
* Use Vitests with React Testing Library
* Place test files in a __tests__ directory in the same folder as the source file
* Name test files as filename.test.ts(x)
* Use @/ prefix for imports
Coverage:
* Test happy paths
* Test edge cases
* Test error states
2. 実際に実行するとき、カスタムコマンドの後がそのまま引数になる
code:bash
/write_tests the use-auth.ts file in the hooks directory
メリット
反復している作業を自動化できる
毎回同じ手順で依頼できる
Claudeに必要なコンテキストを事前に定義できる
引数を渡すことで、重ななカスタムコマンドができる