編集部セレクト
CLAUDE.mdに決まりを長く書いても、途中から守られないと感じていませんか。
Claude Code公式のhooksの説明は、終了コード2で動作そのものを止められるとしています。
PreToolUseのhookならツールの呼び出しを実行前に塞ぎ、止めた理由は標準エラー出力がそのままClaudeに渡ります。
言葉で頼むのをやめて、一番守らせたい決まりをhookに移してください。
出典の原文(引用)
"Exit with code 2 to block the action. On events that can block, Claude Code stops the action: a `PreToolUse` hook blocks the tool call, for example" / "The message that comes with the block is your hook's stderr."— code.claude.com
この話題のきっかけ
https://zenn.dev/tappers/articles/ai-labo-e11-architecture-guardrail-hooks
題材を見つけた場所です。記事の根拠は上の出典です。
