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:
- 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
- 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
Summary
The
PreToolUsehook in~/.codex/hooks.jsoncurrently fires for Bash/shell tool calls only. Two related requests that together unlock full-parity middleware integrations:PreToolUseto all tool calls — specificallyread_file,grep, andapply_patch, which are the other high-volume tools and the ones with the highest potential to overflow context when left unconstrainedupdatedInputin 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. caplimiton a file read, caphead_limiton a grep) rather than relying on model complianceMotivation
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+PostToolUsehooks — that part works today. Butread_file/grep/apply_patchresults routinely push sessions past the context budget, and without a hook surface on those tools the only fallback is a prose hint inAGENTS.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
PreToolUsehook schema already handles matcher-based registration and supportsdecision: allow/denyresponsesupdatedInputfield is documented in the response shape but not currently applied by the Codex runtimeBUDGET_SOFT(prose hints in AGENTS.md) pending this featureSuggested acceptance criteria
PreToolUsefires forread_file,grep, andapply_patchin addition to Bash/shell{"decision":"allow","updatedInput":{...}}has the rewritten input passed to the toolHappy to help test once a dev branch is available.
Additional context
Related discussion: #2150