Skip to content

fix(plugin): give hooks the event on stdin, cap the input variable - #491

Merged
mrnasil merged 2 commits into
mainfrom
fix/hook-stdin-and-input-size
Nov 25, 2026
Merged

mrnasil merged 2 commits into
mainfrom
fix/hook-stdin-and-input-size

Conversation

@mrnasil

@mrnasil mrnasil commented Nov 25, 2026

Copy link
Copy Markdown
Member

Hooks failed in two ways that had nothing to do with the hook itself.

Large tool input broke the spawn. WHYCODES_TOOL_INPUT carried the whole tool input. A write larger than one environment string (128 KiB on Linux, 32K chars on Windows) made the spawn fail with exit -1. A block_on_failure pre_tool hook then refused every large write, and a pre_tool_transform hook was silently skipped. The variable is now cut at 16K chars.

stdin was null. Hooks written for other tools, including the ones import brings in, read the event as JSON from stdin and failed on an empty one. stdin now carries one JSON object:

  • always: hook_event_name, cwd, session_id;
  • tool hooks: tool_name, tool_use_id and the full tool_input;
  • post-tool: tool_is_error and tool_output;
  • lifecycle variables, without the WHYCODES_ prefix (prompt, …).

The payload is written alongside the wait for the hook to exit. A hook that never reads stdin does not stall, and its broken pipe is only logged at debug level.

docs/config.md and docs/guide.md describe stdin and the 16K cut. The plugin crate gains the tokio io-util and macros features.

Tests:

  • payload contents for pre-tool, post-tool and lifecycle events;
  • a hook that cats stdin gets the JSON;
  • a 300 KB write input no longer blocks a block_on_failure hook.

hooks.rs has 100% line coverage on Linux (WSL), and the tests pass on Windows.

🤖 Generated with Claude Code

Two ways hooks failed for reasons outside the hook:

- WHYCODES_TOOL_INPUT carried the whole tool input. A `write` past one
  environment string (128 KiB on Linux, 32K chars on Windows) made the
  spawn fail, so a block_on_failure pre_tool hook refused every large
  write and a transform hook was silently skipped. The variable is now
  cut at 16K chars.
- stdin was null. Hooks written for other tools read the event as JSON
  from stdin, and failed on an empty one. stdin now carries the event as
  one JSON object with the full tool input, fed alongside the wait so a
  hook that never reads it neither stalls nor errors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mrnasil
mrnasil enabled auto-merge (squash) November 25, 2026 15:04
@mrnasil
mrnasil merged commit 1beca0f into main Nov 25, 2026
7 checks passed
@mrnasil
mrnasil deleted the fix/hook-stdin-and-input-size branch November 25, 2026 21:33
@mrnasil mrnasil mentioned this pull request Nov 26, 2026
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.

1 participant