Claude認定 対策ノート

講座 › 分野7 セキュリティと安全性

7.3 Claudeのフック

配点 1.0%Claude Hooks

フックは「必ず起きる」処理。破壊的な操作を、モデルの判断に関係なく実行前に止める。

未読

フックとは

図解:フックとは

フックは、Claude Codeの動きの決まったタイミングで実行される、利用者が定義した処理です。モデルが実行を選ぶかどうかに頼らず、決まった処理が必ず起きる、決定論的な制御を与えます。編集後の整形、実行前のコマンドの阻止、入力待ちの通知などに使います。

出典:Hooks guide
which gives you deterministic control: certain actions always happen rather than relying on the LLM to choose to run them
https://code.claude.com/docs/en/hooks-guide.md(取得 2026-11-17)
出典:Hooks guide
format files after edits, block commands before they execute, send notifications when Claude needs input
https://code.claude.com/docs/en/hooks-guide.md(取得 2026-11-17)

破壊的な操作を止める

図解:破壊的な操作を止める

ツールが実行される直前の PreToolUse のフックで、コマンドの中身を調べ、rm -rf のような破壊的な操作なら permissionDecision に deny を返して止めます。CLAUDE.mdに禁止を書いても文脈として扱われるだけなので、判断に関係なく止めたい操作はフックで止めます。

出典:Hooks reference
returns a `permissionDecision` of `"deny"` if it contains `rm -rf`
https://code.claude.com/docs/en/hooks.md(取得 2026-11-17)
出典:Memory (CLAUDE.md)
To block an action regardless of what Claude decides, use a PreToolUse hook
https://code.claude.com/docs/en/memory.md(取得 2026-11-17)

複数のフックと、判断が要る場合

図解:複数のフックと、判断が要る場合

同じイベントに当たるフックは並列に動き、権限の判断では最も厳しい結果が採られます。1つでも deny があれば、ツールの呼び出しは止まります。決まったルールでなく判断が要る場合は、Claudeのモデルに判定させるプロンプト型のフックもあります。Agent SDKでも、同じようにフックで危険な操作を止められます。

出典:Agent SDK hooks
For permission decisions, the most restrictive result applies. One hook's `deny` blocks the tool call.
https://code.claude.com/docs/en/agent-sdk/hooks.md(取得 2026-11-17)
出典:Agent SDK hooks
Block dangerous operations before they execute, like destructive shell commands or unauthorized file access
https://code.claude.com/docs/en/agent-sdk/hooks.md(取得 2026-11-17)
試験のポイント