PostToolUse hook stdin: tool_response.stderr is always empty

Resolved 💬 2 comments Opened Apr 7, 2026 by Riordanxd Closed May 19, 2026

Description

When a Bash command outputs content to stderr (e.g., Python traceback), the tool_response.stderr field in the PostToolUse hook stdin is always empty, even though the stderr content is
displayed correctly in the terminal output.

This prevents plugins from detecting errors in command output via the PostToolUse hook.

Steps to Reproduce

  1. Configure a PostToolUse hook in settings.json:

{
"hooks": {
"PostToolUse": [
{
"matcher": "*",
"hooks": [{ "type": "command", "command": "cat > /tmp/hook_stdin.log" }]
}
]
}
}

  1. Execute a Python command that outputs to stderr:

python3 -c "raise RuntimeError('TEST_ERROR')"

  1. Check the hook stdin content:

cat /tmp/hook_stdin.log | jq '.tool_response.stderr'

Expected Behavior

.tool_response.stderr should contain the stderr output:
"Traceback (most recent call last):\n File \"<string>\", line 1, in <module>\nRuntimeError: TEST_ERROR\n"

Actual Behavior

.tool_response.stderr is always an empty string:
""

The stderr content IS displayed in the terminal output, but it's not passed to the hook stdin.

Investigation

I verified that the hook IS being triggered correctly:

  • The hook script receives the stdin
  • tool_name is correctly "Bash"
  • tool_input.command contains the correct command
  • tool_response.stdout contains stdout content
  • tool_response.stderr is ALWAYS empty, even when stderr has content

I also verified that when manually passing stderr content to the hook, it works correctly:
echo '{"tool_name":"Bash","tool_input":{"command":"python3 -c raise"},"tool_response":{"stdout":"","stderr":"Traceback...RuntimeError"}}' | my_hook_script
# Hook correctly detects the error

This confirms the hook logic is correct; the issue is that Claude Code doesn't include stderr in the stdin passed to the hook.

Impact

This affects plugins that need to detect errors in command output. For example:

  • Memory plugins that recall past bugfixes when encountering similar errors
  • Error tracking/monitoring plugins
  • Any plugin that needs to analyze stderr content

Environment

  • Claude Code CLI version: Latest (as of 2026-04-07)
  • OS: Linux
  • Shell: bash

Suggested Fix

Include the actual stderr content in the tool_response.stderr field when constructing the stdin for PostToolUse hooks.

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗