Skip to content

[Feature request] Extend PreToolUse hooks beyond Bash + implement updatedInput rewrite #18491

@claudioemmanuel

Description

@claudioemmanuel

Summary

The PreToolUse hook in ~/.codex/hooks.json currently fires for Bash/shell tool calls only. Two related requests that together unlock full-parity middleware integrations:

  1. Expand PreToolUse to all tool calls — specifically read_file, grep, and apply_patch, which are the other high-volume tools and the ones with the highest potential to overflow context when left unconstrained
  2. Implement updatedInput in the hook response — the schema is documented and parsed but the rewritten tool input is not applied. Implementing this would let hooks enforce programmatic budgets (e.g. cap limit on a file read, cap head_limit on a grep) rather than relying on model compliance

Motivation

I'm the author of squeez, an external compression middleware that integrates with Claude Code, Copilot CLI, OpenCode, Gemini CLI, and Codex CLI via their respective hook systems.

For Codex specifically, I can compress Bash output via the existing PreToolUse + PostToolUse hooks — that part works today. But read_file / grep / apply_patch results routinely push sessions past the context budget, and without a hook surface on those tools the only fallback is a prose hint in AGENTS.md, which the model may or may not honour.

If the hook surface expanded, middleware could uniformly enforce output-size budgets across every tool call, the same way Claude Code's PreToolUse + tool-input rewrite does today.

Current state

  • PreToolUse hook schema already handles matcher-based registration and supports decision: allow/deny responses
  • updatedInput field is documented in the response shape but not currently applied by the Codex runtime
  • Tracked downstream in the squeez host-adapter matrix: https://github.com/claudioemmanuel/squeez — CodexCliAdapter ships with BUDGET_SOFT (prose hints in AGENTS.md) pending this feature

Suggested acceptance criteria

  • PreToolUse fires for read_file, grep, and apply_patch in addition to Bash/shell
  • A hook emitting {"decision":"allow","updatedInput":{...}} has the rewritten input passed to the tool
  • Documentation at https://developers.openai.com/codex/hooks updated to reflect both

Happy to help test once a dev branch is available.

Additional context

Related discussion: #2150

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthooksIssues related to event hookstool-callsIssues related to tool calling

    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