[Feature request] Extend PreToolUse hooks beyond Bash + implement updatedInput rewrite
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
PreToolUseto all tool calls — specificallyread_fileandgrep, which are the other high-volume tools with the highest potential to overflow context when left unconstrained (apply_patchis now fixed — see progress below) - Implement
updatedInputin the hook response — the runtime currently rejects it with"PreToolUse hook returned unsupported updatedInput". Implementing this would let hooks enforce programmatic budgets (e.g. caplimiton a file read, caphead_limiton 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 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.
Progress
✅ Fixed in 0.123.0 (PR #18391, 2026-04-23)
apply_patchnow emitsPreToolUseandPostToolUsehook eventstool_namein hook stdin is now handler-supplied (no longer always"Bash")
❌ Still blocked
read_fileandgrephave noToolHandlerwithpre_tool_use_payload/post_tool_use_payload— only test files exist, no hook dispatchupdatedInputis explicitly rejected byoutput_parser.rs:
````
if output.updated_input.is_some() {
Some("PreToolUse hook returned unsupported updatedInput".to_string())
}
Suggested acceptance criteria
PreToolUsefires forread_fileandgrepin addition to Bash/shell andapply_patch- A hook emitting
{"decision":"allow","updatedInput":{...}}has the rewritten input passed to the tool - Documentation updated to reflect both
Downstream tracker
squeez CodexCliAdapter stays at BUDGET_SOFT (prose hints in AGENTS.md) until both remaining items land. Will flip to BUDGET_HARD once confirmed. Happy to test a dev branch.
Additional context
Related discussion: openai/codex#2150
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗