Answer: For rules with zero exceptions, use a deterministic hook type such as a `command`, `http`, or `mcp_tool` hook, and add `onFailure: "block"` if the action should also be stopped when the hook itself crashes or times out. A `prompt` or `agent` hook isn't deterministic, so it isn't suitable for real enforcement. Status: Confirmed Entry: tool/claude-code/agents-and-automation/enforce-rules-with-hooks Revision: 5 Digest: sha256:aa16f6463f6b81db (changes whenever the content changes) Timeline: Created: 2026-11-13T02:27:53Z Last changed: 2026-11-20T12:18:14Z (deterministic hook types: — → command) Last verified: 2026-11-20T12:18:14Z Next check: 2026-11-21T12:18:14Z Check interval: Daily Expected change: No fixed schedule Data: Field | Value | Source | As of deterministic hook types | command | [1] | 2026-11-20 failure setting | onFailure: "block" | [1] | 2026-11-20 non-deterministic hook types | prompt | [1] | 2026-11-20 rule scope | zero | [1] | 2026-11-20 Sources: [1] Anthropic. "Best practices for Claude Code". https://code.claude.com/docs/en/best-practices.md Role: primary. Accessed: 2026-11-20T12:18:14Z Quote: "For real enforcement, use a `command`, `http`, or `mcp_tool` hook" (Supports: deterministic hook types) Quote: "add [`onFailure: "block"`](https://code.claude.com/docs/en/hooks#block-the-action-when-a-hook-fails) if the action should also be stopped when the hook itself crashes or times out" (Supports: failure setting) Quote: "A `prompt` or `agent` hook asks *another model* to decide, so it isn't deterministic either." (Supports: non-deterministic hook types) Quote: "a hook is for a rule with *zero* exceptions" (Supports: rule scope) Published: 2026-11-20T10:31:18Z Snapshot SHA-256: 4cec5f4d01d2756b3de3d51fa8fc8e72e84020a51e008b866639104845fd704d (captured 2026-11-20T12:18:14Z) Verification: Method: Automated extraction from [1] with deepseek-flash (JSON output, thinking disabled). Every value was checked by code to appear verbatim in a quoted passage of [1]. Cross-check: not-available at 2026-11-20T12:18:14Z. No independent second source is configured for this entry Last successful check: 2026-11-20T12:18:14Z Last attempt: 2026-11-20T12:18:14Z Notes and limitations: Extracted automatically from a single official source (section "Enforce steps with hooks"). Related: https://latestn.com/tool/claude-code/agents-and-automation/filter-hook-events How do I filter which events a Claude Code mod hook handles? https://latestn.com/tool/claude-code/agents-and-automation/fork-session How do I fork a Claude Code SDK session to explore alternative approaches? https://latestn.com/tool/claude-code/agents-and-automation/free-text-input-responses How do I support free-text input for Claude Code clarifying question responses? https://latestn.com/tool/claude-code/agents-and-automation/enable-agent-teams How do I enable agent teams in Claude Code? https://latestn.com/tool/claude-code/agents-and-automation/enable-file-checkpointing How do I enable file checkpointing in the Claude Code Agent SDK? https://latestn.com/tool/claude-code/agents-and-automation/enable-streaming-output How do I enable streaming output in the Claude Code Agent SDK? https://latestn.com/tool/ All entries in AI tools Change log: Time | Event | Change | Source 2026-11-20T12:18:14Z | changed | deterministic hook types: — → command | [1] 2026-11-20T12:18:14Z | changed | blocking exit code: 2 → — | [1] 2026-11-20T12:18:14Z | changed | example hook event: PostToolUse → — | [1] 2026-11-20T12:18:14Z | changed | hook type for enforcement: command → — | [1] 2026-11-18T12:13:58Z | changed | hook type for enforcement: — → command | [1] 2026-11-18T12:13:58Z | changed | recommended hook types: command → — | [1] 2026-11-15T12:17:53Z | changed | blocking exit code: — → 2 | [1] 2026-11-15T12:17:53Z | changed | example exit code: 2 → — | [1] 2026-11-13T03:03:20Z | changed | example exit code: — → 2 | [1] 2026-11-13T03:03:20Z | changed | non-deterministic hook types: — → prompt | [1] 2026-11-13T03:03:20Z | changed | recommended hook types: — → command | [1] 2026-11-13T03:03:20Z | changed | blocking exit code: 2 → — | [1] 2026-11-13T03:03:20Z | changed | example matcher: Edit|Write → — | [1] 2026-11-13T03:03:20Z | changed | hook type for enforcement: command → — | [1] 2026-11-13T02:27:53Z | added | Entry created | — Changes for this entry as a feed: https://latestn.com/tool/claude-code/agents-and-automation/enforce-rules-with-hooks/latest Challenge this entry: Open challenges: None How: If a value here is wrong or out of date, send what is wrong and a link to evidence. Challenges are queued and checked against the evidence; they do not change the entry by themselves. If the entry changes as a result, the change log says so. Form: https://latestn.com/dispute/tool/claude-code/agents-and-automation/enforce-rules-with-hooks POST: https://latestn.com/dispute/tool/claude-code/agents-and-automation/enforce-rules-with-hooks with claim, evidence_url, and optionally field and contact (form-encoded or JSON) GET: https://latestn.com/dispute/tool/claude-code/agents-and-automation/enforce-rules-with-hooks?claim={what is wrong}&evidence_url={link} How to cite: LatestN. (2026). How do I enforce rules that can't have exceptions in Claude Code using hooks? Revision 5, last verified 2026-11-20T12:18:14Z. https://latestn.com/tool/claude-code/agents-and-automation/enforce-rules-with-hooks (accessed 2026-11-21T10:02:47Z). @misc{LatestN_tool_claude_code_agents_and_automation_enforce_rules_with_hooks_r5, title = {How do I enforce rules that can't have exceptions in Claude Code using hooks?}, author = {{LatestN}}, year = {2026}, howpublished = {\url{https://latestn.com/tool/claude-code/agents-and-automation/enforce-rules-with-hooks}}, note = {Revision 5; digest sha256:aa16f6463f6b81db; last verified 2026-11-20T12:18:14Z; accessed 2026-11-21T10:02:47Z} } Reuse: License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/) Attribution: Copying and adapting are allowed, including commercially, if you credit LatestN and link to the entry you used. Each entry ends with a ready-made citation. URL: https://latestn.com/tool/claude-code/agents-and-automation/enforce-rules-with-hooks