fix: emit empty hookSpecificOutput in PostToolUse to prevent false hook error#235
Open
murataslan1 wants to merge 1 commit intomksglu:mainfrom
Open
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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