fix: emit empty hookSpecificOutput in PostToolUse to prevent false hook error#235
Conversation
…ok error
PostToolUse hook exits 0 but outputs nothing to stdout. Claude Code
interprets empty stdout as a hook failure and shows "hook error" on
every tool call (TaskUpdate, TaskCreate, etc.), even though the hook
ran successfully.
Output empty {"hookSpecificOutput":{}} so Claude Code recognizes the
hook completed without error. This is a workaround for CC #41868.
Closes mksglu#229
There was a problem hiding this comment.
Pull request overview
This PR updates the PostToolUse hook output so Claude Code receives a valid JSON payload even when the hook has no modifications to apply, preventing false “hook error” messages when stdout would otherwise be empty.
Changes:
- Always emit an empty
hookSpecificOutputJSON object fromhooks/posttooluse.mjsafter processing (or falling back silently on error).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thank you for the detailed investigation and testing @murataslan1 — your analysis of the empty stdout → "hook error" pattern was spot-on and helped inform the final fix. However, we took a different approach that addresses the root cause rather than the symptom: What shipped on
Why this approach vs empty hookSpecificOutput:
Your comment on #229 about #241's substring matching was directly used in the fix. Credit noted in the commit. Closing as superseded — #229 is already resolved. |
Problem
PostToolUse hook exits 0 but outputs nothing to stdout. Claude Code interprets empty stdout as a hook failure and displays "hook error" on every tool call — including
TaskUpdate,TaskCreate, and other internal tools that fire due to thematcher: ""catch-all.References: anthropics/claude-code#41868, anthropics/claude-code#35587
Fix
Output empty
{"hookSpecificOutput":{}}at the end ofposttooluse.mjs. This tells Claude Code the hook completed successfully without any modifications.Test results
{"hookSpecificOutput":{}}{"hookSpecificOutput":{}}{"hookSpecificOutput":{}}{"hookSpecificOutput":{}}{"hookSpecificOutput":{}}PreToolUse regression check: no change (still returns additionalContext as before).
Full test reports: https://gist.github.com/murataslan1/e0290cb0862f57fff4a0e2936b6a77d8
Closes #229