codex - 💡(How to fix) Fix [Feature]: ToolBuild hooks [3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#23490Fetched 2026-05-20 03:48:56
View on GitHub
Comments
3
Participants
3
Timeline
7
Reactions
0
Author
Timeline (top)
labeled ×4commented ×3

Fix Action

Fix / Workaround

Currently, neither the MCP SPEC nor the existing hook system can account for this, and the only viable workaround is implementing an external proxy layer that intercepts and rewrites tool definitions before they reach the model. While technically possible, this is cumbersome, less ergonomic, and introduces unnecessary infrastructure complexity for functionality that naturally belongs in the hook system.

RAW_BUFFERClick to expand / collapse

What variant of Codex are you using?

CLI, App, IDE Extension

What feature would you like to see?

Add granular PreToolBuild and PostToolBuild hooks that allow runtime interception and manipulation of tool definitions before they are sent to the LLM.

Current hooks and the MCP specification do not provide a way to modify the final tool payload at runtime. The proposed hooks would operate on the fully constructed tool collection immediately before model exposure.

The hooks should support:

  • Adding or removing tools dynamically
  • Modifying tool schemas
  • Adjusting properties and required fields
  • Transforming or trimming enums
  • Injecting metadata or constraints
  • Rewriting tool definitions before model delivery

Importantly, this should operate at a granular level, not only entire tools, but entire tool definitions in JSON.

This would enable advanced orchestration workflows that optimize prompt size, token usage, and model focus while preserving necessary capabilities.

Additional information

One practical use case is intelligent MCP tool decomposition and recomposition.

I’m building a plug-in that:

  • Separates MCP tool definitions into:
    • required properties
    • optional properties
    • enums
  • Dynamically selects only the relevant parts based on the user request
  • Re-composes the final tool definition before sending it to the LLM based on the user query.

For example:

  • A tool may contain many optional properties that are irrelevant for most requests
  • Large enum lists can significantly increase prompt size
  • A timezone tool may expose hundreds of timezones even though only one or two are contextually relevant

With granular tool-build hooks, the runtime could:

  • Keep the core tool intact
  • Preserve only relevant optional properties
  • Reduce or rewrite enums dynamically
  • Strip unnecessary schema noise
  • Lower token consumption
  • Improve LLM focus and tool-selection quality

This becomes especially important in multi-session and multi-agent environments where tool definitions may need to be adapted dynamically per request or agent context.

Currently, neither the MCP SPEC nor the existing hook system can account for this, and the only viable workaround is implementing an external proxy layer that intercepts and rewrites tool definitions before they reach the model. While technically possible, this is cumbersome, less ergonomic, and introduces unnecessary infrastructure complexity for functionality that naturally belongs in the hook system.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix [Feature]: ToolBuild hooks [3 comments, 3 participants]