hooks: don't block on stdin EOF when reading hook input (#1398)

main

Commit

Karthik Rameshkumar2mo ago

entire hooks gemini session-start (and every other agent hook) hung indefinitely on Windows/Git Bash. The shared ReadAndParseHookInput used io.ReadAll, which blocks until stdin reaches EOF. Agents deliver the hook payload by piping JSON to the hook process, but some keep the write end of that pipe open for the hook's lifetime instead of closing it after the write — on Windows/Git Bash the full payload arrives yet EOF never does, so io.ReadAll waited forever and the session never started (WSL closes stdin, which is why it worked there).

Switch to a streaming json.Decoder, which returns as soon as one complete JSON value has been read, independent of when — or whether — stdin is closed. Also short-circuit when stdin is an interactive terminal (manual runs, or an agent that leaves the console attached instead of a pipe): there is no payload coming, so return promptly as "empty hook input" instead of blocking.

Empty-input and malformed-JSON error semantics are preserved. Fixes the hang for all agents that route through this helper (cursor, claude-code, codex, factory-droid, gemini, opencode, copilot).

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com Entire-Checkpoint: 01KXDSZGRJRHEE2N68N467Y9G6

Checkpoints

Fix Windows Hooks and Cursor Installation Issues

Claude Code
View session
Checkpoint 1