[FEATURE] Add PreToolResponse hook to intercept tool outputs before model processing

Resolved 💬 5 comments Opened Oct 14, 2025 by telcomate Closed Jan 12, 2026

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Problem Statement

## Summary
Request for a new hook type that runs after tool execution but before the model processes the tool response, allowing users to intercept, modify, or replace tool outputs.

## Current Behavior
The existing hook system provides:

  • UserPromptSubmit: Runs before Claude processes user input
  • PreToolUse: Runs before tool execution (can modify tool inputs)
  • PostToolUse: Runs after tool execution and after model receives response
  • Stop: Runs when Claude finishes responding

## The Gap
There is no hook that fires between tool execution completion and model response processing. This means:

  1. Tool executes → 2. Model receives response → 3. PostToolUse hook fires

By the time PostToolUse runs, the model has already received and started processing the tool response.

Proposed Solution

Add a PreToolResponse (or PostToolExecution) hook type that:

  • Fires after tool execution completes
  • Receives the tool response via stdin
  • Can modify/replace the response before it reaches the model
  • Supports exit codes:
  • exit 0: Pass modified stdout to model
  • exit 1: Error, show to user
  • exit 2: Silent modification

Alternative Solutions

_No response_

Priority

High - Significant impact on productivity

Feature Category

Configuration and settings

Use Case Example

When using MCP tools that return large payloads (e.g., image generation tools returning base64-encoded images), I want to:

  1. Save the payload to disk
  2. Prevent the model from processing the large payload
  3. Return only metadata (file path, size, etc.) to the model

This would:

  • Reduce token usage and costs
  • Speed up response times
  • Allow custom processing of tool outputs before model analysis

### Example: Image Generation
``json
{
"hooks": {
"PreToolResponse": [
{
"matcher": "mcp__demo-mcp__generate_images",
"hooks": [
{
"type": "command",
"command": "save-image-and-return-metadata.sh"
}
]
}
]
}
}
``
The hook script would:

  • Receive the tool response (image data)
  • Save to disk
  • Return modified response: {"saved": true, "path": "/images/foo.png", "size": "2MB"}
  • Model only sees the metadata, not the full payload

Additional Context

_No response_

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗