skip to content

In Claude Code, how is a tool call decided when several PreToolUse hooks return different decisions and a permissions deny rule also matches?

level: seniorimportance: nice to knowfreq 6%

answer

  1. all matching hooks run at once
  2. most restrictive decision wins
  3. rules still evaluated after allow
  4. tighten, never loosen

basics

~20 s

All matching PreToolUse hooks run in parallel, and their decisions combine as deny over defer over ask over allow. A hook's allow never overrides a deny or ask rule, while a hook's deny or exit 2 blocks even when an allow rule matches.

solid answer

~40 s

Claude Code runs every matching hook **in parallel**; an identical handler defined in more than one settings file runs once. Among `PreToolUse` decisions the most restrictive wins: **`deny` > `defer` > `ask` > `allow`**, and an exit-2 hook counts as a deny. Then the permission rules have their say: **deny and ask rules are evaluated regardless of what a hook returns**, so a hook's `allow` can't unblock a call a deny rule matches, including a deny from managed settings. In the other direction, a hook's `deny` or exit 2 blocks the call even when an allow rule matches, and even in `bypassPermissions` mode. Hooks can tighten restrictions but not loosen them past the rules. Non-decision outputs combine differently: every hook's `additionalContext` is delivered, while for `updatedInput` the last hook to finish wins.

go deeper

for a junior

Recall that several hooks can match one call and that a deny from any of them wins over an allow from the others.

for a middle

Explain the full order deny over defer over ask over allow, that hooks run in parallel, and that duplicates across settings files run once.

for a senior

Show how hook decisions meet permission rules: an allow can't beat a deny or ask rule, a hook deny holds even in bypassPermissions, and parallel updatedInput is a race.

for a principal

Decide which controls belong in deny rules, which in hooks, and which in managed settings, given that hooks only tighten and that a team's project hook can't loosen an organisation's deny.

## Two layers meet on every tool call When Claude asks to use a tool, two independent controls look at the call. **PreToolUse hooks** are programs that inspect the call and may return a decision. **Permission rules** (`permissions.allow`, `permissions.ask`, `permissions.deny` in settings) are declarative patterns. The question is how several hook answers combine with each other, and then how the combined answer meets the rules. How the rules are matched among themselves is a separate subject; here the rules are treated as a given deny, ask or allow match. ## Step 1: hooks run together - **All matching hooks run in parallel.** There is no ordering between them and no short-circuit: one hook denying doesn't stop the others from running. - **Duplicates collapse.** If the same handler is defined in more than one settings file, it runs once. A plugin's or a skill's copy of the same handler stays separate. - **Exit 2 counts as `deny`.** A hook that blocks by exiting 2 routes the same way as a JSON `deny`, with stderr as the reason Claude sees. ## Step 2: the most restrictive hook decision wins When hooks disagree, Claude Code applies a fixed precedence: | Rank | Decision | Meaning | |---|---|---| | 1 | `deny` | Block the call | | 2 | `defer` | Pause for a calling process (only in `-p` runs) | | 3 | `ask` | Force a permission prompt | | 4 | `allow` | Skip the prompt | So one `ask` beside three `allow`s still produces a prompt, and a single `deny` beats everything. A hook that exits 0 with no output has no decision and doesn't take part. Outputs that are not decisions combine differently: - **`additionalContext`**: when several hooks return it, Claude receives all of the values. - **`updatedInput`**: the last hook to finish wins. Because hooks run in parallel, that order is non-deterministic, so avoid having two hooks rewrite the same tool's input. ## Step 3: the combined decision meets the rules The key asymmetry is that hooks can **tighten** but not **loosen** past the permission rules: | Hook result | Matching rule | Outcome | |---|---|---| | `allow` | deny rule | **Blocked**: deny rules are evaluated regardless of the hook | | `allow` | ask rule | **Prompted**: the ask rule still prompts | | `allow` | no rule matches | Runs without a prompt | | `deny` or exit 2 | allow rule | **Blocked**: an exit-2 hook stops the call before the rules are evaluated | | no decision | any | The normal permission flow decides alone | The docs make two points explicit. Deny-first precedence is preserved **including deny rules set in managed settings**, so no project hook can override an organisation's deny. And `PreToolUse` hooks fire **before any permission-mode check, in every mode**, so a hook's `deny` blocks even in `bypassPermissions` mode or with `--dangerously-skip-permissions`. An `allow` also can't skip the prompt for a few special cases: MCP tools whose server marks them as requiring user interaction, the protected actions that no mode auto-approves, and `AskUserQuestion` or `ExitPlanMode` unless the hook also returns `updatedInput` holding the answer. ## A worked example Suppose one hook returns `allow` for `make` targets, a second hook returns `ask` for commands that mention a production host, and a deny rule matches `Bash(terraform destroy *)`. 1. `make lint`: the first hook allows, the second is silent and no deny rule matches, so it runs without a prompt. 2. `make deploy HOST=prod.example.com`: one `allow` and one `ask` combine to `ask`, so the user is prompted. 3. `terraform destroy -auto-approve`: even if a hook returned `allow`, the deny rule blocks it. ## Design consequences 1. Put **hard prohibitions in deny rules**, which no hook `allow` can undo, and use hooks for logic that rules can't express. 2. Use a hook `deny` or exit 2 when a block must hold in every permission mode, including `bypassPermissions`. 3. Let **one hook own each rewrite**, because `updatedInput` from parallel hooks is a race. 4. Treat a hook's `allow` as a way to skip the prompt for calls the rules allow anyway, not as a way to grant more access.

  • Why does one exit-2 hook beat an allow rule but an allow hook can't beat a deny rule?
    The design keeps deny-first precedence intact. A blocking hook stops the call before the rules are evaluated, so the block holds even where an allow rule matches. A hook's `allow` only skips the prompt; deny and ask rules are still evaluated afterwards, so hooks can make the policy stricter but never looser.
  • Two PreToolUse hooks both rewrite a Bash command with `updatedInput`. Which rewrite runs?
    Whichever hook finishes last. Hooks run in parallel, so the order is non-deterministic and the result can change from run to run. Have exactly one hook own the rewrite of a given tool's input.

  • Hooks run one after another in the order they appear in settings
  • A hook returning allow overrides a matching deny rule
  • When hooks disagree, the last hook to finish decides
  • Bypass permissions mode skips PreToolUse hooks as well as prompts
  • Only the first hook's additionalContext reaches Claude