Skip to content

Feature Request: Allow PostToolUse hooks to modify tool output #18594

@RichAyotte

Description

@RichAyotte

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:

  1. Runs after a tool executes
  2. Inspects the output
  3. Optionally transforms/refines it (e.g., summarize verbose output, extract key information)
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions