Skip to content

fix: emit empty hookSpecificOutput in PostToolUse to prevent false hook error#235

Open
murataslan1 wants to merge 1 commit intomksglu:mainfrom
murataslan1:fix/posttooluse-empty-output-and-subagent-ctx-commands
Open

fix: emit empty hookSpecificOutput in PostToolUse to prevent false hook error#235
murataslan1 wants to merge 1 commit intomksglu:mainfrom
murataslan1:fix/posttooluse-empty-output-and-subagent-ctx-commands

Conversation

@murataslan1
Copy link
Copy Markdown

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 the matcher: "" catch-all.

References: anthropics/claude-code#41868, anthropics/claude-code#35587

Fix

Output empty {"hookSpecificOutput":{}} at the end of posttooluse.mjs. This tells Claude Code the hook completed successfully without any modifications.

Test results

Tool Before (exit/stdout) After (exit/stdout) Status
TaskUpdate 0 / (empty) 0 / {"hookSpecificOutput":{}} FIXED
Bash 0 / (empty) 0 / {"hookSpecificOutput":{}} FIXED
Agent 0 / (empty) 0 / {"hookSpecificOutput":{}} FIXED
Read 0 / (empty) 0 / {"hookSpecificOutput":{}} FIXED
{} (invalid) 0 / (empty) 0 / {"hookSpecificOutput":{}} FIXED

PreToolUse regression check: no change (still returns additionalContext as before).

Full test reports: https://gist.github.com/murataslan1/e0290cb0862f57fff4a0e2936b6a77d8

Closes #229

…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
Copilot AI review requested due to automatic review settings April 7, 2026 12:20
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 hookSpecificOutput JSON object from hooks/posttooluse.mjs after processing (or falling back silently on error).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostToolUse hook matcher "" fires on ALL tools (TaskUpdate, TaskCreate, etc.) causing false "hook error" display

2 participants