openai / openai/codex

Feature request: let PostToolUse hooks replace tool output (updatedToolOutput)

Open
#38,135 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

CLI context enhancement hooks
Dominant language
Rust
Stars
125k
Forks
19.5k
PR merge metrics
PR metrics pending

Description

Motivation

We build toonify-mcp, a context-compression tool: it converts large JSON/YAML tool output to a compact tabular format and collapses repetitive logs (60%+ token reduction on realistic payloads), while passing through anything it can't reproduce losslessly.

On Claude Code this works as a PostToolUse hook that returns hookSpecificOutput.updatedToolOutput, which replaces what the model sees — that replacement is what actually shrinks context.

Current Codex behavior

PostToolUseOutcome supports block / additionalContext / feedback, but no output replacement. The output parser already recognizes a Claude-style updatedMCPToolOutput field — and explicitly rejects it as unsupported (codex-rs/hooks/src/events/post_tool_use.rs, unsupported_updated_mcp_tool_output_fails_open), so the concept appears to be on your radar already.

additionalContext can't serve this use case: appending a compressed copy on top of the original output makes context larger, the exact opposite of the goal.

Request

Support an updatedToolOutput (and/or the already-parsed updatedMCPToolOutput) in PostToolUse hook output that replaces the tool result before it enters model context — schema-checked against the tool's output type, with fail-open on mismatch, like the current unsupported-field handling.

This would let context-optimization tools (compression, redaction, truncation policies) work across both ecosystems with the same hook contract.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in codex-rs/hooks/src/events/post_tool_use.rs, including unsupported_updated_mcp_tool_output_fails_open, to understand the existing parser and fail-open behavior. Trace how PostToolUseOutcome reaches model context; done means a supported updatedToolOutput or updatedMCPToolOutput can replace the result when schema-compatible, while mismatches fail open.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.