# Anthropic Claude Code — hooks / enforcement, failure and observability boundaries

ARTICLE_ID: GX-0005
CONTENT_FAMILY: GX
PUBLIC_KIND: ARTICLE_PRODUCT
REVISION_ID: GX-0005-R20261027-01
CURRENT_STATUS: CURRENT
OBSERVATION: UNOBSERVED
FRESHNESS: CURRENT
PAGE_TYPE: reference
CANONICAL_URL: /providers/gx-0005-anthropic-claude-code-hooks-enforcement-failure-and-observabilit
CLAIM_IDS: none
EVIDENCE_IDS: none
UNKNOWN_IDS: GX-0005-UNKNOWN-01
OPS_IDS: none

## Summary
Claude Code hooksは、sessionやtool lifecycleの特定eventでcommand、HTTP endpoint、MCP tool、prompt、agent等を起動する拡張・制御機構である。PreToolUseはtool実行前に発火し、明示的なdenyでtool callを止められる。ただし、設定ファイルにhookが存在すること自体は、そのhookが実際に発火し、意図したdecisionが適用されたことの証明ではない。

## Current judgment
Claude Code hooksは、sessionやtool lifecycleの特定eventでcommand、HTTP endpoint、MCP tool、prompt、agent等を起動する拡張・制御機構である。PreToolUseはtool実行前に発火し、明示的なdenyでtool callを止められる。ただし、設定ファイルにhookが存在すること自体は、そのhookが実際に発火し、意図したdecisionが適用されたことの証明ではない。

## Scope
2026-10-27時点のClaude Code Hooks referenceでは、PreToolUseとPostToolUseはagentic loop内の各tool callで発火する（EndConversationは例外）。matcherはtool name等を対象にし、PreToolUseはpermissionDecision=denyでtool callをblockできる。hook sourceはuser/project/local/managed/plugin等に分かれ、subagent tool callsでも同じconfigured hooksが動く一方、managed policyのallowManagedHooksOnly等によりeffective hook setが制限され得る。したがって、設定sourceと実際のeffective hook setを分離して扱う。

## Confirmed

## UNKNOWN
- GX-0005-UNKNOWN-01: - #85430、#46193、#94362、#85904で報告された挙動のcurrent latest releaseでの完全な修正状態。
- terminal / IDE / desktop / cloud / headless / subagent間の全platform・全mode conformance。
- auto mode等のpermission pipeline変更時にhook decision precedenceが将来どのように変化するか。
- hook invocation/decisionの標準的なdurable audit schemaと保持保証。

## Evidence
- none listed on this page

## Failure / limits
command hookはexit code 2などevent-specific blocking pathを持つ一方、通常のその他exit codeはnon-blocking errorとなり得る。HTTP hookについて現行referenceはnon-2xx、connection failure、timeoutをnon-blocking errorとして扱い、明示的な2xx JSON decisionでblock/denyする契約を示す。安全制御としてhookを使う場合、spawn失敗、path/executable不備、matcher不一致、HTTP endpoint outageを自動的なfail-closedと仮定しない。
## Failure / limits
Author-maintained issue #85430は2026-08-10、同じproject settingsからpermissions.denyは効くのにPreToolUse hookが特定working directoryで発火しないという再現報告を残している。原因は確定しておらず、全環境へ一般化しない。issue #46193はClaude Code 2.1.100 / Windowsで、unreachableなPermissionRequest HTTP hookがdocumented non-blocking contractに反してtool callをdenyしたという報告である。issue #94362はClaude Code 2.1.270 / macOSで、実行bitを失ったPreToolUse commandがnon-blocking failureとなりguardがfail-openしたという報告である。issue #85904は2.1.219 / Windowsで、再測定時にはPreToolUse自体は発火したがdefaultMode=auto下でpermissionDecision=askが無視されたというversion-scoped報告を含む。

これらはprovider contractではなくruntime counterevidenceであり、issue closureや単一reportからcurrent latestの修正状態を断定しない。
## 要点と前提
Claude Code hooksは、sessionやtool lifecycleの特定eventでcommand、HTTP endpoint、MCP tool、prompt、agent等を起動する拡張・制御機構である。PreToolUseはtool実行前に発火し、明示的なdenyでtool callを止められる。ただし、設定ファイルにhookが存在すること自体は、そのhookが実際に発火し、意図したdecisionが適用されたことの証明ではない。

## Current contract
2026-10-27時点のClaude Code Hooks referenceでは、PreToolUseとPostToolUseはagentic loop内の各tool callで発火する（EndConversationは例外）。matcherはtool name等を対象にし、PreToolUseはpermissionDecision=denyでtool callをblockできる。hook sourceはuser/project/local/managed/plugin等に分かれ、subagent tool callsでも同じconfigured hooksが動く一方、managed policyのallowManagedHooksOnly等によりeffective hook setが制限され得る。したがって、設定sourceと実際のeffective hook setを分離して扱う。

## Failure semantics
command hookはexit code 2などevent-specific blocking pathを持つ一方、通常のその他exit codeはnon-blocking errorとなり得る。HTTP hookについて現行referenceはnon-2xx、connection failure、timeoutをnon-blocking errorとして扱い、明示的な2xx JSON decisionでblock/denyする契約を示す。安全制御としてhookを使う場合、spawn失敗、path/executable不備、matcher不一致、HTTP endpoint outageを自動的なfail-closedと仮定しない。

## Counterevidence / runtime conformance
Author-maintained issue #85430は2026-08-10、同じproject settingsからpermissions.denyは効くのにPreToolUse hookが特定working directoryで発火しないという再現報告を残している。原因は確定しておらず、全環境へ一般化しない。issue #46193はClaude Code 2.1.100 / Windowsで、unreachableなPermissionRequest HTTP hookがdocumented non-blocking contractに反してtool callをdenyしたという報告である。issue #94362はClaude Code 2.1.270 / macOSで、実行bitを失ったPreToolUse commandがnon-blocking failureとなりguardがfail-openしたという報告である。issue #85904は2.1.219 / Windowsで、再測定時にはPreToolUse自体は発火したがdefaultMode=auto下でpermissionDecision=askが無視されたというversion-scoped報告を含む。

これらはprovider contractではなくruntime counterevidenceであり、issue closureや単一reportからcurrent latestの修正状態を断定しない。

## Operational meaning
高影響操作のguardrailにhooksを使う場合は、設定存在確認だけでなく、対象version/platform/modeでpositive probeとnegative probeを行う。少なくとも、(1) matcher対象toolでhook invocationが観測できること、(2) deny pathが実際にtool executionを止めること、(3) hook failure時のfail-open/fail-closed挙動、(4) auto/headless/subagent等の実行mode差、(5) managed policyによるeffective hook set、をreadbackする。hook側にもinvocation/decision/errorの監査ログを持たせ、設定済みと実行済みを分離する。

外部APIやdatabase等のside effectでは、hook deny成功を唯一のauthorization boundaryにせず、対象system側のcredential scope、transaction、approval、idempotency等と組み合わせる。hookが発火したことは外部side effectのexactly-onceや取消し可能性を保証しない。

## Unconfirmed
- #85430、#46193、#94362、#85904で報告された挙動のcurrent latest releaseでの完全な修正状態。
- terminal / IDE / desktop / cloud / headless / subagent間の全platform・全mode conformance。
- auto mode等のpermission pipeline変更時にhook decision precedenceが将来どのように変化するか。
- hook invocation/decisionの標準的なdurable audit schemaと保持保証。

## 原著の公式参照先（未検証）
以下は原研究に記録された公式資料へのリンクです。現在の内容、資料の更新日、個別主張の妥当性を新たに検証したものではありません。
- https://code.claude.com/docs/en/hooks

NEXT: /agent/start.json
STOP: This is a knowledge projection, not an execution order.