2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Claude CodeのStop hookでAIの作業チェックをAIにやらせる

2
Last updated at Posted at 2026-06-09

はじめに

Claude CodeにはAgent-based hookがあります。
Agent-based hooks | Automate actions with hooks - Claude Code Docs

Agent-based hookでは、サブエージェントがツール(Read, Grepなど)を使って検証ができます。
そのため、command hookでは検証しづらいようなことをエージェントに検証させることができるため、メインエージェントによる対応漏れや検証漏れを確認できます。

使い方

Agent-based hookの定義は"type": "agent"とするだけでできます。

以下は、公式ドキュメントから引っ張ってきたユニットテストが通ることを検証してから停止を許可するStop hookの例です。
サブエージェントがチェックし、NGだった場合は修正をさせることができます。

settings.json
{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          {
            "type": "agent",
            "prompt": "Verify that all unit tests pass. Run the test suite and check the results. $ARGUMENTS",
            "timeout": 120
          }
        ]
      }
    ]
  }
}

Agent-based hookの制約としては、サブエージェントは最大で50回のターンまでという点です。
基本は収まるような気はしますが、一応ターン数の上限があるのは覚えておくと良さそうです。

さいごに

Agent-based hookを使うと、「AIの作業チェックをAIにやらせる」ことができて便利です。
なお、Stop hookで作業を継続させると無限ループが気になると思いますが、それについても記事を書いているので読んでいただけると嬉しいです。

参考

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?