claude-code - 💡(How to fix) Fix PreToolUse/PostToolUse hooks always show 'hook error' on Windows despite exit 0 [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#45065Fetched 2026-04-09 08:14:07
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1

On Windows 11 with Claude Code 2.1.96, all PreToolUse and PostToolUse hooks display "hook error" in the transcript even when they exit with code 0 and produce correct output. SessionStart and UserPromptSubmit hooks display "success" correctly.

Error Message

On Windows 11 with Claude Code 2.1.96, all PreToolUse and PostToolUse hooks display "hook error" in the transcript even when they exit with code 0 and produce correct output. SessionStart and UserPromptSubmit hooks display "success" correctly. 5. Observe: PreToolUse:Bash hook error appears in transcript | node -e "process.exit(0)" | 0 | none | none | error | | bash -c "exit 0" | 0 | none | none | error | | bash -c "cat; exit 0" (stdin passthrough) | 0 | JSON | none | error | | Node script outputting {} | 0 | {} | none | error | | Node script with stderr + exit 0 | 0 | JSON | text | error | All hooks execute correctly (verified via log files and side effects). The "hook error" label is purely a display issue. Every tool use (Bash, Read, Edit, Write) generates 8-14 "hook error" lines in the transcript, making it very noisy and hard to distinguish real errors from cosmetic ones.

Root Cause

On Windows 11 with Claude Code 2.1.96, all PreToolUse and PostToolUse hooks display "hook error" in the transcript even when they exit with code 0 and produce correct output. SessionStart and UserPromptSubmit hooks display "success" correctly.

Code Example

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "node -e \"process.exit(0)\""
          }
        ]
      }
    ]
  }
}
RAW_BUFFERClick to expand / collapse

Summary

On Windows 11 with Claude Code 2.1.96, all PreToolUse and PostToolUse hooks display "hook error" in the transcript even when they exit with code 0 and produce correct output. SessionStart and UserPromptSubmit hooks display "success" correctly.

Reproduction

  1. Windows 11 Pro (10.0.26200), shell: Git Bash
  2. Claude Code 2.1.96
  3. Add a minimal PreToolUse hook to .claude/settings.json:
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "node -e \"process.exit(0)\""
          }
        ]
      }
    ]
  }
}
  1. Run any Bash command in Claude Code
  2. Observe: PreToolUse:Bash hook error appears in transcript

What was tested

Hook variantExit codeStdoutStderrResult
node -e "process.exit(0)"0nonenoneerror
bash -c "exit 0"0nonenoneerror
bash -c "cat; exit 0" (stdin passthrough)0JSONnoneerror
Node script outputting {}0{}noneerror
Node script with stderr + exit 00JSONtexterror

All hooks execute correctly (verified via log files and side effects). The "hook error" label is purely a display issue.

Expected behavior

Hooks exiting with code 0 should display "hook success" (or no message), matching the behavior of SessionStart and UserPromptSubmit hooks.

Impact

Every tool use (Bash, Read, Edit, Write) generates 8-14 "hook error" lines in the transcript, making it very noisy and hard to distinguish real errors from cosmetic ones.

Environment

  • OS: Windows 11 Pro 10.0.26200
  • Shell: Git Bash (MINGW64)
  • Claude Code: 2.1.96
  • Node: v24.x
  • Hooks tested with both node and bash commands

extent analysis

TL;DR

The issue can be mitigated by modifying the hook configuration to handle the output and error streams correctly.

Guidance

  • Verify that the hook commands are executing correctly and producing the expected output by checking the log files and side effects.
  • Check the Claude Code documentation for any specific requirements or guidelines for handling output and error streams in hooks.
  • Consider modifying the hook commands to explicitly handle and redirect output and error streams, for example, by appending > /dev/null 2>&1 to the command.
  • Test the hooks with different commands and output scenarios to ensure the issue is not specific to a particular command or output type.

Example

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "node -e \"process.exit(0)\" > /dev/null 2>&1"
          }
        ]
      }
    ]
  }
}

Notes

The issue seems to be related to how Claude Code handles the output and error streams of the hook commands. The provided examples suggest that the issue is not specific to a particular command or output type, but rather a general issue with how the hooks are executed and displayed in the transcript.

Recommendation

Apply workaround: Modify the hook configuration to handle the output and error streams correctly, as the root cause of the issue is likely related to how Claude Code handles these streams.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Hooks exiting with code 0 should display "hook success" (or no message), matching the behavior of SessionStart and UserPromptSubmit hooks.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING