[BUG] PostToolUse hook exit-2/stderr warning not delivered to model in VSCode extension
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported with this scope
- [x] This is a single bug report
- [x] I am using the latest version of Claude Code (v2.1.234)
What's Wrong?
Follow-up to #55889 (closed for inactivity, not resolved — locked, so filing new per its own closing instructions). That issue documented additionalContext/systemMessage/plain-stdout-on-exit-0 all being dropped for Bash-matched PostToolUse hooks. It did not test exit 2 + stderr, which several community docs/threads recommend as the reliable fallback (since exit-0 stdout is documented as not surfaced to the model, only exit-2 stderr is). In our testing, exit 2 + stderr is also not delivered to the model in the VSCode extension.
We confirmed with a two-stage diagnostic, isolating "does the harness invoke the hook" from "does the hook's message reach the model":
- Added an unconditional debug line at the top of our PostToolUse hook script that appends a timestamp to
/tmp/check-commit-debug.log, before any conditional logic. - Ran multiple real
git commitcommands from within a live Claude Code session (VSCode extension, not terminal CLI). - Confirmed via
cat /tmp/check-commit-debug.logthat the hook is invoked on every commit — the harness-to-script wiring works correctly. - The same script, further down, detects a specific commit condition (a new file added under a given path) and on match does:
``bash``
echo "<warning text>" >&2
exit 2
- On a commit that met the match condition, the debug log confirmed the script ran and reached that branch. But the Claude model in the session never referenced, mentioned, or acted on the warning text — no awareness of it at all, across multiple repeated attempts, including after a full VSCode window restart.
This means for Bash-matched PostToolUse hooks in the VSCode extension, none of the documented-or-recommended delivery channels work: additionalContext (per #55889), systemMessage (per #55889), plain stdout on exit 0 (per #55889), and now exit 2 + stderr (this issue).
What Should Happen?
Per the hooks reference, PostToolUse hook output should appear next to the tool result so the model can see and act on it. Exit 2 + stderr specifically is documented elsewhere as the channel to use for a non-blocking-but-visible warning. Neither happens.
Reproduction
- In a repo, add
.claude/settings.json:
``json``
{
"hooks": {
"PostToolUse": [
{
"matcher": "Bash",
"hooks": [
{ "type": "command", "command": "./check-commit.sh", "if": "Bash(git commit*)", "timeout": 10 }
]
}
]
}
}
check-commit.sh:
``bash``
#!/usr/bin/env bash
set -euo pipefail
echo "invoked at $(date -Iseconds)" >> /tmp/check-commit-debug.log
echo "XYZZY_TEST_MARKER: if you see this, say MARKER_OK" >&2
exit 2
- In a live Claude Code session running inside the VSCode extension (not terminal CLI), have Claude run
git commit --allow-empty -m "test". - Observe:
/tmp/check-commit-debug.loggets a new line (hook fires), but the model's next message shows no awareness ofXYZZY_TEST_MARKER— it never saysMARKER_OK. - Tried across multiple separate commits and after a full VSCode window/extension restart — same result every time.
Environment
- Claude Code Version: 2.1.234
- VSCode: 1.133.0
- Extension: anthropic.claude-code@2.1.234
- OS: Linux (Fedora), connected via Remote-SSH
- Related: #55889 (PreToolUse/PostToolUse additionalContext/systemMessage/stdout dropped, closed for inactivity — this issue extends that finding to exit-2/stderr and confirms in VSCode extension specifically)
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗