fix(hooks): parse JSON output on exit code 2 to preserve hook additionalContext#2815
fix(hooks): parse JSON output on exit code 2 to preserve hook additionalContext#2815DennisYu07 wants to merge 2 commits intomainfrom
Conversation
…nalContext Exit code 2 (blocking error) previously skipped JSON parsing entirely, converting stderr to plain text and losing structured output fields like hookSpecificOutput.additionalContext. This fixes issue #2809 where PostToolUse hook additionalContext was not surfaced to the model when the hook returned exit code 2.
📋 Review SummaryThis PR fixes a bug where 🔍 General Feedback
🎯 Specific Feedback🟡 High
🟢 Medium
🔵 Low
✅ Highlights
|
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
TLDR
Fixes hookSpecificOutput.additionalContext from
PostToolUse/PostToolUseFailurehooks was not surfaced to the model when the hook exited withcode 2(blocking error).The exit
code 2path skipped JSON parsing entirely, converting stderr to plain text and losing all structured output fields. Now exitcode 2also attempts JSON parsing first, falling back to plain text only when stderr is not valid JSON.Screenshots / Video Demo
When stderr the

hookSpecificOutput.additionalContextwill be injected totranscript:Dive Deeper
Origin implementation only affected hooks that exited with
code 2(blocking decision). The root cause was inhookRunner.tswhere the exit code 2 branch calledconvertPlainTextToHookOutputdirectly without attempting JSON parsing first. This meant any structured output — hookSpecificOutput.additionalContext, hookSpecificOutput.decision, or other typed fields — was silently discarded and the entire stderr was used as the plain text reason.Exit codes 0and1already attempted JSON parsing, so this was purely an omission in the blocking error path.Reviewer Test Plan
code 2and outputs JSON to stderr:glob,read_file) in qwen-code.~/.qwen/projects/.../chats/<session>.jsonl) — the tool response should end with [Hook] This context should appear in tool response.Testing Matrix
Linked issues / bugs
#2809