codex-plugin-cc icon indicating copy to clipboard operation
codex-plugin-cc copied to clipboard

Stop hook hangs on Windows when review gate is disabled (stdin blocking)

Open emamimohsen opened this issue 7 months ago • 2 comments

On Windows with Git Bash as the configured shell, the Stop hook opens a new terminal window and hangs indefinitely (up to the 900s timeout) after every Claude response, even when the review gate is disabled.

stop-review-gate-hook.mjs calls fs.readFileSync(0, "utf8") (blocking stdin read) at the top of main(), before checking whether config.stopReviewGate is enabled. On Windows with Git Bash, the hook runner does not properly pipe/close stdin for the spawned Node.js process, so the read blocks forever.

The gate check at line 154 (if (!config.stopReviewGate) { return; }) never runs because execution is stuck at line 143 (readHookInput()).

Environment:

  • OS: Windows 11 Enterprise
  • Shell: Git Bash (C:/Users/.../Git/usr/bin/bash.exe)
  • Claude Code with Codex plugin v1.0.3
  • Review gate: disabled (stopReviewGate: false)

emamimohsen avatar Apr 09 '26 08:04 emamimohsen

+1 Confirming this on Windows 11 + Git Bash + plugin 1.0.3 (verified the v1.0.4 manifest is byte-identical, so still affected).

Empirical evidence

Direct manual run with echo '{}' | to provide stdin returns cleanly:

$ time (echo '{}' | node "stop-review-gate-hook.mjs")
real  0m0.644s
exit  0

Under the actual Claude Code harness (no piped stdin), the same hook hangs until the manifest's 900ms timeout, after which the harness emits:

Stop hook error: Failed with non-blocking status code: No stderr output

Signature is consistent with fs.readFileSync(0) blocking on a stdin handle the harness leaves open without writing — exactly as the original report describes.

Confirmed config

  • state.json: config.stopReviewGate: false
  • Plugin: codex 1.0.3, also tested against the v1.0.4 manifest — identical 5 / 5 / 900 timeouts in hooks/hooks.json.

Suggested fix directions

  1. Primary (matches root cause): move readHookInput() to after the config.stopReviewGate check at line 154. When the gate is off, the script can short-circuit without reading stdin at all. This eliminates the hang in the common (default) case.

  2. Defensive alternative: non-blocking stdin read with a short fallback — e.g. Promise.race between an event-based stdin reader and setTimeout(50, () => ({})). Useful if any future code path needs the input even when the gate is off.

  3. Orthogonal but related: the manifest timeouts in plugins/codex/hooks/hooks.json look like they assume seconds:

    "SessionStart": ... "timeout": 5    // 5 ms — unreachable for a Node cold start
    "SessionEnd":   ... "timeout": 5    // 5 ms — same
    "Stop":         ... "timeout": 900  // 900 ms — barely above the empirical 644ms
    

    Per the CC schema, command/http hook timeouts are in milliseconds. SessionStart/End at 5ms cannot succeed under any realistic conditions. Suggest bumping to 5000 / 5000 / 10000 regardless of the stdin fix — those are independent bugs.

Happy to test a candidate patch on Windows 11 + Git Bash if it helps land the fix.

lucasmiachon-blip avatar Apr 25 '26 23:04 lucasmiachon-blip

Duplicate of #530.

dkundel-openai avatar Aug 11 '26 00:08 dkundel-openai