Skip to content

Drain stdin in generated hook commands to avoid BrokenPipeError#494

Open
LeonCode2025 wants to merge 2 commits into
tirth8205:mainfrom
LeonCode2025:fix/260519_broken_pipe
Open

Drain stdin in generated hook commands to avoid BrokenPipeError#494
LeonCode2025 wants to merge 2 commits into
tirth8205:mainfrom
LeonCode2025:fix/260519_broken_pipe

Conversation

@LeonCode2025
Copy link
Copy Markdown

Summary

Fixes #493.

Generated Codex and Claude hook commands currently do not consume hook event JSON from stdin before running code-review-graph commands. When a hook event contains a large payload, the hook command can exit successfully while the caller is still writing stdin, which causes Broken pipe / EPIPE errors in Codex.

This PR makes the generated hook commands explicitly drain stdin before running the existing git and code-review-graph commands.

Changes

  • Prefix generated Claude hook commands with cat >/dev/null || true;
  • Prefix generated Codex hook commands with cat >/dev/null || true;
  • Apply the stdin drain to both PostToolUse and SessionStart generated commands
  • Add a regression test that writes a large stdin payload to the generated PostToolUse command and verifies it exits successfully without BrokenPipeError

Why

The hook command itself may still return exit code 0, but the parent process can fail while writing hook stdin if the hook exits before consuming the payload. Draining stdin keeps the hook behavior non-blocking while avoiding the caller-side broken pipe error.

Cursor/Gemini hook scripts already consume stdin, so this also makes the Codex/Claude generated hooks consistent with the existing integrations.

Testing

  • Ran pytest tests/test_skills.py
  • Verified the new large-stdin regression test passes
  • Verified the generated hook command exits with code 0 and no BrokenPipeError

…odex-posttooluse-hook

Consume stdin in generated hook commands to avoid BrokenPipeError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex PostToolUse hook should drain stdin to avoid Broken pipe (os error 32) on large tool outputs

1 participant