{
  "id": 20898571,
  "title": "\"A Crashed PreToolUse Hook Leaves No Trace in the Model's Context; Telling It to Block Leaves Too Much\"",
  "url": "https://urgent.news/2026/11/20/a-crashed-pretooluse-hook-leaves-no-trace-in-the-models-context",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-20T12:51:15.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/enjoy_kumawat/a-crashed-pretooluse-hook-leaves-no-trace-in-the-models-context-telling-it-to-block-leaves-too-3l8a"
  },
  "original_language": "en",
  "account": "Two readers commented on last week's article about Claude Code's PreToolUse hook exit codes, asking about what happens to stderr output from a crashing hook and about an onFailure: block setting that hadn't been tested. The first reader's question was answered in the article, which established that a non-2 exit code still lets the guarded tool call through, and that the failure appears as a hook_non_blocking_error attachment. However, the article did not examine what is actually in the model's context versus what is only visible in the raw session log.\n\nTo answer these questions, the author built an experiment using a throwaway .claude/settings.json file, a crash-prone hook script, and real headless Claude -p calls against the actual CLI. The crash_hook.py script logs its invocation time, writes a traceback to a file, and then raises a RuntimeError. The hooks configuration includes a PreToolUse hook for the Bash command, with a matcher and a command to run the crash_hook.py script.\n\nWhen the command echo hello456 is asked to run, the full event stream is captured with the --output-format stream-json --verbose option. The raw stream contains a hook_response system event with the entire crash information. However, the tool-result message that the model receives does not contain any stderr output, exit code, or mention of the hook running. The model's final answer correctly reports that the command printed hello456 without mentioning any hook output or errors.\n\nWhen the onFailure: block setting is added to the hook configuration, the result changes. The crash occurs, and the tool call does not go through. The tool-result message now indicates that the tool call was blocked due to the onFailure: block setting, and the model's final answer accurately describes the situation, including the crash details and the blocked command. This demonstrates that the onFailure: block setting fails closed, while the default behavior fails open, allowing the guarded command to run even if the hook crashes.",
  "summary": "Two readers left comments on yesterday's piece about Claude Code's PreToolUse hook exit codes that I couldn't answer honestly at the time. One asked what happens to stderr output from a crashing hook — does it leak into the model's context, or just disappear. The other asked about an onFailure: \"block\" setting I hadn't tested. Yesterday's article only established that a non-2 exit code lets the…",
  "key_points": [
    "Crashed PreToolUse hook leaves no trace in model's context",
    "onFailure: block setting prevents command execution",
    "Model reports command success despite hook crash"
  ],
  "editors_take": "The default behavior of failing open during hook crashes creates a security gap where models execute guarded commands without visibility into the errors that occurred during the pre-tool verification process.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}