fix(stop-review-gate-hook): always emit valid JSON on stdout
Summary
scripts/stop-review-gate-hook.mjs returns silently in three no-decision paths in main():
if (!config.stopReviewGate)— the default, hit on every Stop event when the user has not opted into the review gateif (setupNote)— Codex not yet set up- The trailing path where the review came back
ALLOW
In all three, logNote() writes to stderr but stdout is never touched. Newer hook executors (observed in current Claude Code / Codex CLI builds) strict-parse hook stdout as JSON. Empty stdout is no longer treated as "no decision" — it surfaces as a visible error after every Claude turn:
Stop hook (failed)
error: hook returned invalid stop hook JSON output
Older Claude Code tolerated empty stdout, which is why this only became visible recently.
Fix
Emit {} (a no-decision JSON object) before each silent return. Three-line change, no behavior change other than satisfying the strict parser. The block path is untouched — it already emits a {decision: "block", reason} object.
Test plan
- [x]
echo '{"hook_event_name":"Stop","session_id":"test","stop_hook_active":false}' | node scripts/stop-review-gate-hook.mjs→ stdout is{}, exit 0 - [x]
JSON.parse(stdout)succeeds - [x] stderr
logNotemessages preserved (no regression in user-facing diagnostics) - [x]
decision: "block"path unchanged
Related issues / context
I searched open issues and PRs for stop-review-gate, empty stdout, hook returned invalid, JSON output — none describe this specific defect. The closest are:
- #191 (Stop hook hangs on Windows when review gate disabled) — different root cause (stdin blocking, not stdout shape)
- #248 (Stop review gate blocks Claude on infrastructure errors) — touches
parseStopReviewOutput, but only the gate-enabled paths
Both are orthogonal to this fix.
🤖 Generated with Claude Code
Addressed the P1 review note from @chatgpt-codex-connector in commit a1020ad — updated the three stdout.trim() === "" assertions in tests/runtime.test.mjs (lines 1897, 1925, 1950) to expect "{}" so they match the new no-decision contract.
Verified locally: all 5 stop-hook tests now pass.
[!NOTE] To use Codex here, create an environment for this repo.