Summary
PostToolUse hooks are currently observational only and cannot modify tool output before the model processes it. This prevents useful refinement workflows like summarizing large command output or formatting results.
Use Case
I want to build a hook that:
- Runs after a tool executes
- Inspects the output
- Optionally transforms/refines it (e.g., summarize verbose output, extract key information)
- Returns the modified output for the model to see
Current Limitation
PostToolUse hooks cannot modify output - they can only observe and optionally add a systemMessage.
PreToolUse workaround fails for empty output: Using PreToolUse with exit code 2 to intercept and run the command ourselves works for commands with output, but when stderr is empty, the CLI displays "No stderr output" which clutters the conversation.
This creates an impossible situation:
- To check if output needs refinement, we must run the command
- If output is small/empty and we return exit 0, the command runs again (double execution)
- If we return exit 2 with empty stderr, the CLI shows "No stderr output"
Prior Art
OpenCode has tool.execute.after hooks that CAN modify output before the agent sees it, demonstrating this is architecturally feasible.
Proposed Solution
Allow PostToolUse hooks to return modified tool output via a new field like modifiedOutput or toolResult:
{
"hookSpecificOutput": {
"toolResult": "refined output here"
}
}
Or alternatively, fix the "No stderr output" message for PreToolUse exit 2 when stderr is intentionally empty (perhaps by checking for a specific marker or allowing an empty string to mean "no output, not an error").
Related Issues
I'm reopening this request as the use case is valid and the limitation significantly restricts what hooks can accomplish.
Summary
PostToolUse hooks are currently observational only and cannot modify tool output before the model processes it. This prevents useful refinement workflows like summarizing large command output or formatting results.
Use Case
I want to build a hook that:
Current Limitation
PostToolUse hooks cannot modify output - they can only observe and optionally add a
systemMessage.PreToolUse workaround fails for empty output: Using PreToolUse with exit code 2 to intercept and run the command ourselves works for commands with output, but when stderr is empty, the CLI displays "No stderr output" which clutters the conversation.
This creates an impossible situation:
Prior Art
OpenCode has
tool.execute.afterhooks that CAN modify output before the agent sees it, demonstrating this is architecturally feasible.Proposed Solution
Allow PostToolUse hooks to return modified tool output via a new field like
modifiedOutputortoolResult:{ "hookSpecificOutput": { "toolResult": "refined output here" } }Or alternatively, fix the "No stderr output" message for PreToolUse exit 2 when stderr is intentionally empty (perhaps by checking for a specific marker or allowing an empty string to mean "no output, not an error").
Related Issues
I'm reopening this request as the use case is valid and the limitation significantly restricts what hooks can accomplish.