On Linux, Bun's libuv calls fstat() on inherited pipe file descriptors
and crashes with EINVAL when the pipe originates from Claude Code's hook
system. This causes all PostToolUse hooks to fail silently, preventing
observations from being recorded.
The fix reads stdin entirely in the Node.js parent process (bun-runner.js)
before spawning Bun, then writes the buffered data to a fresh pipe created
by Node's child_process.spawn(). Bun receives a standard pipe that it can
fstat() without errors.
Changes:
- Add collectStdin() to buffer piped input in Node.js with 5s safety timeout
- Change stdio from 'inherit' to ['pipe'|'ignore', 'inherit', 'inherit']
- Write buffered stdin to child.stdin then close for proper EOF signaling
- Handle edge cases: TTY stdin, no stdin, read errors
Fixes#646
Co-authored-by: yczc3999 <zxfgds@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
On Windows, when the username contains spaces (e.g., "Tafari Higgs"),
bun-runner.js fails with: Syntax Error at C:\Users\Tafari:1:2
This happens because `shell: IS_WINDOWS` (true on Windows) causes
spawn() to route through cmd.exe, which misinterprets the path at
the first space in the username directory.
Removing `shell: true` on Windows fixes the issue since spawn()
can invoke the Bun binary directly without needing a shell wrapper.
Added `windowsHide: true` to prevent a visible console window from
appearing, matching the previous hidden behavior under cmd.exe.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
On fresh installations, smart-install.js installs Bun to ~/.bun/bin/bun
but Bun isn't in PATH until terminal restart. Subsequent hooks fail
because they try to run `bun ...` directly.
This fix introduces bun-runner.js - a Node.js script that finds Bun
in common install locations (not just PATH) and runs commands with it.
All hooks now use `node bun-runner.js ...` instead of `bun ...`.
The bun-runner checks:
- PATH (via which/where)
- ~/.bun/bin/bun (default install location)
- /usr/local/bin/bun
- /opt/homebrew/bin/bun (macOS Homebrew)
- /home/linuxbrew/.linuxbrew/bin/bun (Linuxbrew)
- Windows: %LOCALAPPDATA%\bun or fallback paths
Fixes#818
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>