claude-code-guide
claude codeが使うモデル自体がclaude codeの知識を持っている部分もあるが、claude codeには claude-code-guide という組み込みのサブエージェントが入っていて、Haikuを使ってclaude codeの使い方を調べてくれる機能がある。
Agent Model When Claude uses it Bash Inherits Running terminal commands in a separate context statusline-setup Sonnet When you run /statusline to configure your status line Claude Code Guide Haiku When you ask questions about Claude Code features
https://code.claude.com/docs/en/sub-agents#other
つまり claude code を使っているなかで、これどうしたらいいんだ?というのが出てきたら、claude code上で聞けばよい。
実際に作らせてみる
例えばSpecDrivenのようなことをやりたいとし「あなたがコードを書く前にその大変さや複雑さを一度考えてもらい、一定基準を超えたらADRを書いてもらい、承認を得てから進めるようにしたいんだけど、どうすれば?」とclaude codeに聞けばいい。
次のようなレスポンスがclaude codeから返ってくる。
⏺ いくつかのアプローチを組み合わせるのが効果的です。
方法: CLAUDE.md にルールを追加する
一番シンプルかつ効果的なのは、CLAUDE.md に判断基準とADRのフローを明記することです。Claude Code は CLAUDE.md
の指示に従うので、ここに書けば自動的に適用されます。
...
なるほど。「もしかしたら他の方法もあるかも、どうですかね?」
⏺ 他にもいくつか方法があります。
1. Hooks(プリフック)
.claude/settings.json に PreToolUse フックを設定し、Edit / Write の前にシェルスクリプトを実行させる方法です。
...
2. カスタムスラッシュコマンド
.claude/commands/adr.md を作って、/adr で呼び出せるようにする方法です。
...
3. カスタムエージェント
.claude/agents/architect.md を作り、設計レビュー専用のエージェントを定義する方法です。
...
比較
┌──────────────────────┬────────────────┬────────────────┬──────────────────────────────┐
│ 方法 │ 自動適用 │ 柔軟性 │ 向いているケース │
├──────────────────────┼────────────────┼────────────────┼──────────────────────────────┤
│ CLAUDE.md │ はい │ 高い │ 常にこのフローを適用したい │
├──────────────────────┼────────────────┼────────────────┼──────────────────────────────┤
│ Hooks │ はい │ 低い(機械的) │ ADRファイルの存在チェック等 │
├──────────────────────┼────────────────┼────────────────┼──────────────────────────────┤
│ スラッシュコマンド │ いいえ(手動) │ 中程度 │ 必要な時だけ使いたい │
├──────────────────────┼────────────────┼────────────────┼──────────────────────────────┤
│ カスタムエージェント │ いいえ(手動) │ 高い │ 設計と実装を完全に分離したい │
└──────────────────────┴────────────────┴────────────────┴──────────────────────────────┘
おすすめの組み合わせ
CLAUDE.md(自動判断)+ カスタムエージェント(手動の深い設計)
の併用が実用的です。普段はCLAUDE.mdのルールで自動的にADR判断させつつ、特に重要な設計では /agent architect
で専用エージェントに任せる、という使い分けができます。
どの方向で進めたいですか?
おすすめされているとおり、CLAUDE.mdとカスタムエージェントがハイブリットにつかえて便利そうだ。 「じゃあおすすめのそれで」
⏺ Update(CLAUDE.md)
⎿ Added 56 lines
...
85 +## Complexity Evaluation and ADR
86 +
87 +Before writing code, you MUST evaluate the complexity of the task.
88 +
89 +### Criteria (ADR required if ANY apply)
90 +- Changes span 3 or more files
91 +- Adds a new external dependency
92 +- Modifies existing interfaces, exported types, or data structures
93 +- Multiple valid implementation approaches exist
94 +- Affects performance, security, or external API contracts
95 +- May break existing tests
96 +
97 +### ADR NOT required
98 +- Simple bug fixes (1-2 line changes)
99 +- Typo fixes
100 +- Small additions that follow existing patterns exactly
101 +
102 +### Flow
103 +1. State your complexity assessment explicitly before any code changes
104 +2. If any criterion above applies, create an ADR at `docs/adr/NNNN-title.md` using the template below
105 +3. Wait for user approval before writing any implementation code
106 +4. Never skip this step — unapproved ADRs mean no code changes
107 +
108 +### ADR Template (`docs/adr/NNNN-title.md`)
...
⏺ Write(.claude/agents/architect.md)
⎿ Wrote 22 lines to .claude/agents/architect.md
1 You are an architect agent for the stock-analysis project. Your role is to evaluate proposed changes and produce Architecture Decision R
ecords (ADRs).
2
3 ## Rules
4 - You MUST NOT write implementation code (no Edit/Write to .go files)
5 - You MUST NOT run the application or tests
6 - You CAN read any file in the codebase to understand the current architecture
7 - You CAN create/edit files only under `docs/adr/`
8
9 ## Process
⏺ Bash(mkdir -p /foo/bar/baz/docs/adr)
⎿ Done
いい感じにできあがった。
英語がわからない?じゃあ「日本語で書いて」とでも伝えればよいだろう。
改善していく
おそらく上記のまま使っていると、claude codeからは、これでいいですか?→自由入力、のような形になるだろう。でもclaude codeを使っていると選択肢が表示されることもあるはずだ。あれは使えるのだろうか?
「ADRの承認、自由入力じゃなくて選択肢で選ばせたいのだがclaude codeってそういうのできる?」
⏺ できます。AskUserQuestion というツールがあり、選択肢を提示してユーザーに選ばせることができます。
例えばこんな形で表示されます:
ADRを承認しますか?
○ 承認する — このまま実装に進みます
○ 修正が必要 — フィードバックを入力してADRを修正します
○ 却下する — この方針では進めません
○ Other
CLAUDE.md の ADR フローにこれを明記しておきましょうか?「ADRを書いた後は AskUserQuestion
で選択肢を提示して承認を得ること」というルールを追加する形です。
AskUserQuestionというのがあるんだ。よくわからないけど「それでOK」
⏺ Update(CLAUDE.md)
⎿ Added 7 lines, removed 2 lines
102 ### Flow
103 1. State your complexity assessment explicitly before any code changes
104 2. If any criterion above applies, create an ADR at `docs/adr/NNNN-title.md` using the template below
105 -3. Wait for user approval before writing any implementation code
106 -4. Never skip this step — unapproved ADRs mean no code changes
105 +3. After writing the ADR, use `AskUserQuestion` to present approval choices:
106 + - "承認する" — Proceed to implementation
107 + - "修正が必要" — Revise the ADR based on user feedback
108 + - "却下する" — Abandon this approach entirely
109 +4. Only proceed to implementation after "承認する" is selected
110 +5. If "修正が必要" is selected, revise the ADR and present the choices again
111 +6. Never skip this step — unapproved ADRs mean no code changes
112
113 ### ADR Template (`docs/adr/NNNN-title.md`)
114
へ〜、何かが出来上がった。
実際に実行してみるとこんな感じになる:
☐ ADR承認
ADRを承認しますか?
❯ 1. 承認する
このまま実装に進みます
2. 修正が必要
フィードバックを入力してADRを修正します
3. 却下する
この方針では進めません
4. Type something.
5. Chat about this
おわりに
例えばコードを書いたあとにlint/testを必ずやってほしい、とか、PRを作るときは必ずdraftにしてほしい、とか、コードを書かせたりあれこれやってもらったりしていると、こうしたいんだよな〜がいっぱい出てくる。
でも、それを自分で作る必要もない。それもAIに作らせればよい。自分でせっせとプロンプト頑張って作るよりも、よっぽど効率が良く、やりたいことがストレートに実現できる。