[BUG] Windows: PreToolUse hooks fail with WSAENOBUFS (0x80072747) socket buffer error

Resolved 💬 2 comments Opened Feb 9, 2026 by avrvenkatesa Closed Mar 9, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

# PreToolUse Hooks Failing on Windows with Socket Buffer Error

## Environment

  • Claude Code Version: 2.1.37
  • Platform: Windows (win32)
  • OS: Windows (Git Bash / MSYS)
  • Bash Version: GNU bash, version 5.2.37(1)-release (x86_64-pc-msys)

## Summary
PreToolUse hooks configured to trigger on Edit/Write operations fail with a Windows socket buffer error (WSAENOBUFS - 0x80072747)
before the hook script can execute. The hooks are correctly matched and triggered, but the bash process creation fails at the OS
level.

## Expected Behavior
When using Edit or Write tools, the configured PreToolUse hook should:

  1. Be matched against the "Edit|Write" matcher
  2. Execute the bash script at .claude/hooks/debug-hook.sh
  3. Receive tool data via stdin
  4. Return a response (optionally JSON)
  5. Allow the Edit/Write operation to proceed

## Actual Behavior
The hook is matched correctly, but execution fails with:
``
An operation on a socket could not be performed because the system
lacked sufficient buffer space or because a queue was full.
Error code: Bash/Service/0x80072747
``

The hook script never executes - the error occurs when Claude Code attempts to create the bash process and pipe data to it.

## Configuration

Global Settings (~/.claude/settings.json):
``json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "bash .claude/hooks/debug-hook.sh"
}
]
}
]
}
}
``

Project Settings (.claude/settings.json):
``json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "bash .claude/hooks/debug-hook.sh"
}
]
}
]
}
}
``

## Steps to Reproduce

  1. Create a simple hook script at .claude/hooks/debug-hook.sh:

``bash
#!/bin/bash
echo '{"allow": true}'
``

  1. Configure PreToolUse hook in .claude/settings.json as shown above
  1. Restart Claude Code completely (exit then claude)
  1. Use the Edit or Write tool on any file
  1. Check debug logs at ~/.claude/debug/latest

## Debug Log Evidence

From ~/.claude/debug/latest:

``
2026-02-09T05:35:54.089Z [DEBUG] executePreToolHooks called for tool: Edit
2026-02-09T05:35:54.089Z [DEBUG] Getting matching hook commands for PreToolUse with query: Edit
2026-02-09T05:35:54.089Z [DEBUG] Found 2 hook matchers in settings
2026-02-09T05:35:54.089Z [DEBUG] Matched 1 unique hooks for query "Edit" (2 before deduplication)
2026-02-09T05:35:54.192Z [DEBUG] Hook output does not start with {, treating as plain text
2026-02-09T05:35:54.192Z [DEBUG] Hook PreToolUse:Edit (PreToolUse) error:
An operation on a socket could not be performed because the system
lacked sufficient buffer space or because a queue was full.
Error code: Bash/Service/0x80072747
``

The logs show:

  • ✅ Hook is matched correctly (1 unique hook matched)
  • ✅ Hook execution is attempted
  • ❌ Fails with WSAENOBUFS error before script runs

## Attempted Workarounds

All of the following approaches failed with the same error:

  1. Added timeout to stdin reading:

``bash
timeout 2s cat > "output.txt" 2>/dev/null || true
``

  1. Closed stdin immediately:

``bash
exec 0<&-
``

  1. Minimal JSON-only response (no stdin reading):

``bash
#!/bin/bash
echo '{"allow": true}'
``

  1. Manual execution test: The hook script works perfectly when run manually:

``bash
$ bash .claude/hooks/debug-hook.sh <<< '{"test": "data"}'
{"allow": true}
``

## Analysis

The error code 0x80072747 is the Windows Sockets error WSAENOBUFS, which means:
> "An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full."

This suggests the issue is with how Claude Code creates the inter-process communication pipes on Windows, not with the hook script
itself. The error occurs at the OS level when attempting to:

  • Create the bash subprocess
  • Establish stdin/stdout/stderr pipes
  • Send the tool data through the pipe

## Additional Notes

  • Other tools (Bash, Read, Grep) show hooks being checked but not matched (as expected)
  • PostToolUse hooks for Read show "Matched 1 unique hooks" successfully in logs
  • The issue is specific to PreToolUse hooks with bash commands on Windows
  • This may be a Windows-specific issue (pipes/sockets work differently on Windows vs Unix)

## Expected Fix

Claude Code should either:

  1. Fix the Windows pipe/socket buffer allocation for bash subprocess creation
  2. Provide better error handling and fallback behavior
  3. Add Windows-specific hook execution using PowerShell or cmd.exe
  4. Document known limitations on Windows and suggest workarounds

## Workaround Request

Is there an alternative way to configure hooks on Windows (e.g., PowerShell scripts, .bat files, or different execution methods)?

---

Full debug session details available upon request.

What Should Happen?

## Expected Fix

Claude Code should either:

  1. Fix the Windows pipe/socket buffer allocation for bash subprocess creation
  2. Provide better error handling and fallback behavior
  3. Add Windows-specific hook execution using PowerShell or cmd.exe
  4. Document known limitations on Windows and suggest workarounds

Error Messages/Logs

The error code **0x80072747** is the Windows Sockets error **WSAENOBUFS**, which means:
 > "An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full."

Steps to Reproduce

## Steps to Reproduce

  1. Create a simple hook script at .claude/hooks/debug-hook.sh:

``bash
#!/bin/bash
echo '{"allow": true}'
``

  1. Configure PreToolUse hook in .claude/settings.json as shown above
  1. Restart Claude Code completely (exit then claude)
  1. Use the Edit or Write tool on any file
  1. Check debug logs at ~/.claude/debug/latest

## Debug Log Evidence

From ~/.claude/debug/latest:

``
2026-02-09T05:35:54.089Z [DEBUG] executePreToolHooks called for tool: Edit
2026-02-09T05:35:54.089Z [DEBUG] Getting matching hook commands for PreToolUse with query: Edit
2026-02-09T05:35:54.089Z [DEBUG] Found 2 hook matchers in settings
2026-02-09T05:35:54.089Z [DEBUG] Matched 1 unique hooks for query "Edit" (2 before deduplication)
2026-02-09T05:35:54.192Z [DEBUG] Hook output does not start with {, treating as plain text
2026-02-09T05:35:54.192Z [DEBUG] Hook PreToolUse:Edit (PreToolUse) error:
An operation on a socket could not be performed because the system
lacked sufficient buffer space or because a queue was full.
Error code: Bash/Service/0x80072747
``

The logs show:

  • ✅ Hook is matched correctly (1 unique hook matched)
  • ✅ Hook execution is attempted
  • ❌ Fails with WSAENOBUFS error before script runs

## Attempted Workarounds

All of the following approaches failed with the same error:

  1. Added timeout to stdin reading:

``bash
timeout 2s cat > "output.txt" 2>/dev/null || true
``

  1. Closed stdin immediately:

``bash
exec 0<&-
``

  1. Minimal JSON-only response (no stdin reading):

``bash
#!/bin/bash
echo '{"allow": true}'
``

  1. Manual execution test: The hook script works perfectly when run manually:

``bash
$ bash .claude/hooks/debug-hook.sh <<< '{"test": "data"}'
{"allow": true}
``

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.1.37

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

_No response_

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗