claude-code - 💡(How to fix) Fix [Bug] PreToolUse and PostToolUse hooks not invoked on Windows (win32-x64) [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#53254Fetched 2026-04-26 05:20:26
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1

Fix Action

Fix / Workaround

Bug Description Issue: PreToolUse and PostToolUse hooks are not invoked on Windows.

Environment:

  • Claude Code 2.1.119 (native, win32-x64)
  • Windows, Git Bash for shell
  • Project at C:\dev\flowcraft\

Reproduction:

  • .claude/settings.json with valid hooks config (current schema: matcher + hooks: [{type, command}] array)
  • Absolute forward-slash path: bash C:/dev/flowcraft/.claude/hooks/before_bash.sh
  • Hook script verified working when invoked directly: bash before_bash.sh "git push origin main --force" -> "❌ BLOCKED" + exit 2

Diagnostic that confirms hooks are not invoked:

  • Added to hook script: echo "$(date) HOOK_INVOKED" >> hook-debug.log
  • Ran multiple Bash tool calls from within Claude Code session
  • hook-debug.log was never created (cat returns "No such file or directory")
  • Same config worked on Linux/Mac per docs

Tried (no fix):

  • Schema corrections (matcher+hooks array vs flat command field)
  • Path corrections (absolute Windows path with forward slashes)
  • .gitattributes for LF line endings on .sh files
  • Multiple session restarts including --debug flag
  • /doctor command (output shows minimal info, no hooks section)

Workaround in use: hooks disabled in settings.json ({}); rely on user's manual approval prompts as primary safety net.

Code Example

[]
RAW_BUFFERClick to expand / collapse

Bug Description Issue: PreToolUse and PostToolUse hooks are not invoked on Windows.

Environment:

  • Claude Code 2.1.119 (native, win32-x64)
  • Windows, Git Bash for shell
  • Project at C:\dev\flowcraft\

Reproduction:

  • .claude/settings.json with valid hooks config (current schema: matcher + hooks: [{type, command}] array)
  • Absolute forward-slash path: bash C:/dev/flowcraft/.claude/hooks/before_bash.sh
  • Hook script verified working when invoked directly: bash before_bash.sh "git push origin main --force" -> "❌ BLOCKED" + exit 2

Diagnostic that confirms hooks are not invoked:

  • Added to hook script: echo "$(date) HOOK_INVOKED" >> hook-debug.log
  • Ran multiple Bash tool calls from within Claude Code session
  • hook-debug.log was never created (cat returns "No such file or directory")
  • Same config worked on Linux/Mac per docs

Tried (no fix):

  • Schema corrections (matcher+hooks array vs flat command field)
  • Path corrections (absolute Windows path with forward slashes)
  • .gitattributes for LF line endings on .sh files
  • Multiple session restarts including --debug flag
  • /doctor command (output shows minimal info, no hooks section)

Workaround in use: hooks disabled in settings.json ({}); rely on user's manual approval prompts as primary safety net.

Environment Info

  • Platform: win32
  • Terminal: mintty
  • Version: 2.1.119
  • Feedback ID: 754e81c5-ccfa-4346-b71a-0352db354b77

Errors

[]

extent analysis

TL;DR

The PreToolUse and PostToolUse hooks are not invoked on Windows, and a potential fix involves investigating the compatibility of the hook scripts with the Windows environment.

Guidance

  • Verify that the hook scripts are executable in the Windows environment by running them directly from the Command Prompt or PowerShell, rather than relying on Git Bash.
  • Check the file system permissions and ownership of the hook scripts to ensure they can be executed by the Claude Code process.
  • Consider modifying the hook scripts to use Windows-compatible commands and syntax, as the current scripts may be specific to Linux/Mac environments.
  • Investigate the use of a Windows-compatible shell, such as PowerShell, to run the hook scripts instead of Bash.

Example

No code snippet is provided as the issue does not contain sufficient information about the hook scripts or the expected behavior.

Notes

The issue may be related to the compatibility of the hook scripts with the Windows environment, and further investigation is needed to determine the root cause. The fact that the same config works on Linux/Mac suggests that the issue is specific to the Windows platform.

Recommendation

Apply a workaround by modifying the hook scripts to be compatible with the Windows environment, as the current configuration is not working as expected. This may involve using Windows-compatible commands and syntax, or using a different shell to run the hook scripts.

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…

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [Bug] PreToolUse and PostToolUse hooks not invoked on Windows (win32-x64) [1 comments, 2 participants]