Skip to content

fix(hooks): pre-tool guard fails open when the hook can't start, crashes, or times out — adopt onFailure: "block" (Claude Code 2.1.295) #1439

Open

Description

@admarble

Problem

templates/hooks/pre-tool.sh is Sequant's security guard. It blocks only by exiting 2 (for example at lines 795 and 849). It has no set -e or trap, and its header (line 5) treats exit 1 as non-blocking. If the script cannot start, crashes, or times out, Claude Code lets the tool call through: the guard fails open.

Claude Code v2.1.295 added onFailure: "block" for command and HTTP hooks: "a hook that can't start, times out, or exits with an unexpected code blocks the action instead of letting it through". Neither plugin/hooks/hooks.json nor templates/settings.json sets it.

Found in the v2.1.290–296 upstream triage (2026-10-13). The /upstream classifier did not flag this line.

Open questions (decide in /spec)

  1. Does an exit code of 1 count as "unexpected"? If it does, every bug in pre-tool.sh blocks every tool call. That is fail-closed, but it may be too harsh for a 1700-line shell script. We may need a trap that maps internal errors to a deliberate code first.
  2. How do Claude Code versions older than 2.1.295 handle the unknown onFailure key: ignore it, warn, or reject the hooks file? Sequant has no Claude Code version floor (README recommends ≥ 2.1.288).
  3. Does the guard's timeout need adjusting once a timeout blocks instead of allowing?

Acceptance Criteria

  • AC-1: The behaviour of onFailure: "block" is measured on Claude Code ≥ 2.1.295 for three cases: hook script missing, hook exits 1, hook exceeds its timeout. Each case records whether the tool call was blocked. Evidence: the probe commands and their output, pasted in the PR body.
  • AC-2: How Claude Code 2.1.288–2.1.294 handles a hooks file containing onFailure is measured (ignored / warned / rejected). Evidence: the probe output, pasted in the PR body.
  • AC-3: Based on AC-1 and AC-2, the shipped PreToolUse guard entries in plugin/hooks/hooks.json and templates/settings.json fail closed when the guard cannot run, or the PR records why that is unsafe and what stands in for it. Evidence: a test that asserts the chosen configuration on both files, mutation-verified by removing it.
  • AC-4: Deliberate internal errors in pre-tool.sh do not block every tool call: an unbound variable or failed command inside the script gives the outcome chosen in /spec. Evidence: a test that runs the hook with an injected fault and asserts that outcome.

Constraints

  • It touches plugin/, so the merge waits for the plugin freeze to lift. Opening the PR is fine.

Activity

  1. added
    bug
    on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions