Built-in image generation does not appear to emit PreToolUse hooks
What version of Codex is running?
Codex Desktop on Windows. Local CLI reports:
codex-cli 0.128.0
What platform is your computer?
Windows, PowerShell session.
What issue are you seeing?
PreToolUse hooks configured for built-in image generation matcher candidates did not fire before a real image_gen tool call. The same hook script blocks correctly when invoked with a simulated hook payload, so this looks like the built-in image generation call is not being emitted through the hook runtime.
I originally observed this on local CLI 0.124.0 and re-tested after updating the npm-installed CLI to 0.128.0. The behavior was unchanged in the tested Codex Desktop session.
Why this matters
Some projects need generated image assets to go through a wrapper that records provenance metadata, for example prompt/model metadata in EXIF, a manifest, or an asset ledger. If built-in image_gen cannot be observed or blocked by PreToolUse, that wrapper cannot be enforced before generation runs.
Steps to reproduce
- Enable Codex hooks in
config.toml:
[features]
codex_hooks = true
- Register
PreToolUsehooks for likely built-in image generation matcher names:
[[hooks.PreToolUse]]
matcher = "image_gen.imagegen"
[[hooks.PreToolUse.hooks]]
type = "command"
command = "python /path/to/check-image-generation-route.py"
[[hooks.PreToolUse]]
matcher = "imagegen"
[[hooks.PreToolUse.hooks]]
type = "command"
command = "python /path/to/check-image-generation-route.py"
[[hooks.PreToolUse]]
matcher = "image_generation"
[[hooks.PreToolUse.hooks]]
type = "command"
command = "python /path/to/check-image-generation-route.py"
- Use a hook script that exits non-zero for image generation events. I verified the script itself blocks when it receives a simulated image payload:
{"tool_name":"image_gen.imagegen","tool_input":{"prompt":"Project-bound website/app asset. Asset role: route validation."}}
The hook exited with code 2.
- Ask Codex Desktop to generate an image with the built-in image generation tool.
Actual behavior
The built-in image generation tool executed and saved an image under $CODEX_HOME/generated_images/.... The PreToolUse hook did not block the call and did not appear to receive the image tool event.
The generated file had no project provenance metadata when inspected with the local EXIF reader used by the provenance guard:
{
"prompt": "",
"model": ""
}
This does not prove whether image generation has no hook payload in all Codex builds, but in this tested Desktop session it shows the configured PreToolUse guard was not invoked before built-in image generation.
Expected behavior
Built-in image generation should emit a PreToolUse event before generation. The hook payload should include a stable hook-facing tool name, such as image_gen or image_gen.imagegen, and the prompt/options needed for policy decisions.
If the hook exits with the documented block/deny behavior, the image generation call should not execute.
Ideally, image generation should also emit PostToolUse with enough metadata to audit generated output paths, success status, and any generated file identifiers.
Additional context
Related issue/PR:
- #16732 reported that hooks only fired for Bash/shell and not for
apply_patch. - #18391 fixed
apply_patchby addingPreToolUse/PostToolUsepayload support and removing hardcodedtool_name: "Bash"behavior.
This issue is asking whether the built-in image generation handler needs the same kind of hook participation. From the outside, the symptom is the same class of problem: a built-in structured tool executes, but hook policy cannot observe or block it.
3 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
여기 그대로 붙여 넣을 수 있는 영어 답변입니다:
---
Not a duplicate of #20204, though they belong to the same family of "PreToolUse hook coverage gaps."
list_dir,view_image,mcp_resource,plan,goal,agent_jobs,tool_search,tool_suggest.multi_agents/*,multi_agents_v2/*, andweb_search(the latter because it has no handler skeleton yet).web_search, likely needs its own handler treatment rather than being lumped into the 8-handler PoC.The bot appears to have matched on the shared keywords (PreToolUse, hooks, tool handlers). The author of #20204 made a similar clarification when their issue was bot-flagged as a duplicate of #18491 — same logic applies here. Happy to coordinate scope with the #20204 PR if maintainers prefer, but flagging this as a distinct issue so the image-generation case isn't silently absorbed and lost.
Indexed this hook ticket in the umbrella tracker: #21753
Goal: collect the scattered Codex hook requests and bugs into one parity matrix for Full Claude Code Hook Parity (29+), while preserving this issue as the detailed thread for its specific behavior.