Coding agent hooks fail open: what six agents do when a hook fails

In Claude Code, Gemini CLI, Cursor, Copilot CLI and Cline, a pre-tool hook that times out lets the call run. What each agent does when its hook fails, tested, and how to make a gate fail closed.

· 6 min read

Every major coding agent now runs a hook before a tool call, and people use those hooks as a gate: block rm -rf, ask before a deploy, send the command to someone for approval. But in most of them a hook that fails is not a no. In Claude Code, Gemini CLI, Cursor, Copilot CLI and Cline, a hook that times out lets the call run as if there were no hook, and most of them do the same when the hook crashes or prints something they cannot read. Cursor and Claude Code have a switch that makes a failure block, off by default; we found none in the other four.

We build approval hooks for all six, so we ran each one’s hook runner with hooks that sleep, crash and print junk, against a scripted model. Where we could not run an agent that way, the table quotes its own documentation and says so.

What each agent does when its hook fails

How Claude Code, Codex, Gemini CLI, Cursor, Copilot CLI and Cline treat a pre-tool hook that times out, crashes or prints something unreadable, November 2026
OptionDefault timeWhen the hook failsTo refuseAn ask
Claude CodeDefault time600 s (timeout)When the hook failsThe call goes ahead: a timeout, an exit code other than 0 or 2, a hook that does not start and JSON that does not parse are all non-blocking errors. Set onFailure: "block" (v2.1.295 or later) to block instead.To refuseExit 2 with the reason on stderr, or permissionDecision "deny". Exit 2 blocks even if the JSON says allow.An askShows Claude Code's own permission prompt.
CodexDefault time600 s (timeout)When the hook failsNot stated for local hooks. The docs say a PreToolUse error, timeout or malformed response in managed cloud hooks can let the tool run. New or changed hooks do not run at all until trusted under /hooks.To refusepermissionDecision "deny", or exit 2 with the reason on stderr.An askNot supported yet: Codex marks the hook run as failed and the call goes ahead, so "ask" works like a yes.
Gemini CLI 0.70Default time60 s (timeout, in ms)When the hook failsThe tool runs when the hook times out or exits 1.To refuseExit 2, or decision "deny".An askHangs a headless run, which has nobody to ask.
Cursor CLI 2026.11.19Default time60 s (timeout)When the hook failsThe call runs when the hook crashes, times out or exits with a code other than 0 or 2, unless the hook sets failClosed: true. Output that is not JSON blocks.To refuseExit 2, or permission "deny".An askForces Cursor's prompt in the CLI, which --force skips.
Copilot CLI 1.0.114Default time30 s (timeoutSec)When the hook failsThe call runs when the hook passes its timeout or prints something that is not JSON. Any non-zero exit blocks.To refuseAny non-zero exit, or permissionDecision "deny".An askA no in -p runs and autopilot.
Cline CLI 3.0.75Default time120 s, fixedWhen the hook failsThe call runs when the hook passes 120 seconds, prints something that is not JSON or exits with any error. Exit codes are ignored.To refusecancel: true, which stops the whole task, not only the call.An askNo ask: the hook can only let the call go ahead or cancel.

The Claude Code and Codex rows quote their hook documentation (sources below). The other four are from our own runs, on the versions named.

Three ways a gate opens by itself

  • It runs out of time. A hook that waits for a person, a network call or a slow policy engine is cut off at the timeout, and the agent carries on. The defaults range from 30 seconds in Copilot CLI to 10 minutes in Claude Code and Codex, and Cline’s 120 seconds cannot be changed.
  • It never starts. A missing binary, an npx download with no network, or a typo in the command is a crash, and in most agents a crash is a yes. Nothing in the hook’s own code can catch this.
  • It answers in a shape the agent does not read. A stray log line on stdout, a field named the way another agent names it, or an “ask” that the agent does not support. In Codex an “ask” is marked as a failed hook and the call goes ahead; in Cline a refusal must be cancel: true, not deny.

Making a hook fail closed anyway

  • Turn on the switch where there is one. In Cursor, set failClosed: true on the hook. In Claude Code, set onFailure: "block" (v2.1.295 or later).
  • Answer before the timeout, always. Give the hook its own deadline a good margin inside the agent’s timeout, and when it is reached, print the refusal. A hook that waits for a person should take back the open request at that point, so nobody approves a call the agent was already told not to make.
  • Turn every error inside the hook into a refusal. No key, no network, an unreadable call: catch them all and print the agent’s own “no”. In Copilot CLI any non-zero exit also blocks, and in Claude Code exit 2 does; in Cline, Gemini CLI and Cursor without failClosed, only the printed answer counts.
  • Install the hook’s program. A hook that starts through npx or a package download fails open the first time the network does. On a machine that runs agents unattended, install it.
  • Do not send “allow” unless you mean it. In Copilot CLI a hook’s allow skips its own --deny-tool rules. A gate that only adds refusals cannot widen what the agent was configured to do.

Test the failure, not only the happy path

Point the hook at a script that waits past its timeout (set a short one for the test), ask the agent to run touch marker.txt, and see whether the file appears. Then try one that exits 1 and one that prints hello. If any of the three lets the command run, so will a hook that stalls in production.

#!/bin/bash
# A hook that fails on purpose: it reads the call, waits past the
# timeout, and only then refuses. If marker.txt appears, a stalled hook
# is a yes in this agent. 150 seconds is past the defaults of Copilot
# CLI, Gemini CLI, Cursor and Cline; for Claude Code and Codex (600 by
# default), set the hook's timeout to 20 while you test.
cat > /dev/null
sleep 150
echo '{"decision": "deny"}'
exit 2

Agents change their hook runners often. The versions in the table are the ones we tested in November 2026; run the three checks again after an upgrade.

Where approvals come in

A hook that asks a person is the case where all of this bites, because a person can take longer than any default timeout. VariantGate’s hooks for each agent wait inside its timeout, withdraw the request when time runs out, and print that agent’s own refusal on every failure, so an unanswered request is a no. The guides list what each hook writes and how it was tested: Claude Code, Codex, Gemini CLI, Cursor, Copilot CLI, Cline.

Sources

  1. Claude Code: Hooks reference (timeouts, exit codes, onFailure), read 21 November 2026
  2. OpenAI Codex: Hooks (timeout, decisions, trust), read 21 November 2026