CLAUDE.mdもSkillもAgentも自分で書くな

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に作らせればよい。自分でせっせとプロンプト頑張って作るよりも、よっぽど効率が良く、やりたいことがストレートに実現できる。

サイト案内

運営してるひと: @sters9

最近は Go, Ruby, Rails, Kubernetes, GCP, Datadog あたりをしていますがもっといろいろやりたい!

プロフィール

開発環境の紹介

プライバシーポリシー

tools.gomiba.co

building-microservices.gomiba.co

サイト内検索

アーカイブ

2026/02 (4) 2026/01 (6)

2025/12 (5) 2025/11 (1) 2025/10 (2) 2025/09 (4) 2025/08 (1) 2025/07 (6) 2025/06 (1) 2025/05 (1) 2025/04 (3) 2025/03 (1) 2025/02 (3) 2025/01 (4)

2024/12 (2) 2024/09 (3) 2024/07 (1) 2024/06 (3) 2024/05 (1) 2024/04 (7) 2024/03 (4) 2024/01 (3)

2023/12 (1) 2023/11 (3) 2023/10 (1) 2023/09 (1) 2023/08 (2) 2023/05 (4) 2023/04 (4) 2023/03 (4) 2023/02 (2) 2023/01 (1)

2022/12 (2) 2022/11 (4) 2022/10 (3) 2022/09 (2) 2022/08 (4) 2022/07 (5) 2022/06 (4) 2022/05 (9) 2022/04 (8) 2022/03 (10) 2022/02 (21) 2022/01 (8)

2021/12 (11) 2021/11 (1) 2021/10 (4) 2021/09 (2) 2021/08 (1) 2021/07 (2) 2021/06 (5) 2021/05 (10) 2021/04 (1) 2021/03 (8) 2021/02 (12) 2021/01 (8)

2020/05 (2) 2020/04 (2) 2020/02 (2) 2020/01 (1)

2019/12 (3) 2019/11 (2) 2019/10 (5) 2019/09 (3) 2019/07 (6) 2019/06 (4) 2019/04 (3) 2019/01 (2)

2018/12 (6) 2018/10 (4) 2018/09 (6) 2018/08 (7) 2018/07 (16) 2018/06 (7) 2018/05 (7) 2018/04 (5) 2018/03 (3) 2018/02 (10) 2018/01 (6)

2017/12 (8) 2017/11 (6) 2017/10 (10) 2017/09 (12) 2017/08 (12) 2017/07 (3) 2017/06 (1) 2017/01 (4)

2016/12 (5) 2016/10 (3) 2016/09 (1) 2016/07 (2) 2016/06 (1) 2016/04 (1) 2016/02 (1) 2016/01 (2)

2015/12 (1) 2015/10 (1) 2015/09 (3) 2015/06 (1) 2015/01 (1)

2014/08 (2) 2014/07 (3) 2014/05 (1) 2014/01 (7)

2013/12 (2) 2013/11 (4) 2013/10 (1) 2013/09 (1) 2013/08 (3) 2013/07 (4) 2013/06 (5) 2013/05 (2) 2013/04 (7) 2013/03 (1)