Codex exec does not fire Stop / SessionStop / PostToolUse hooks (only UserPromptSubmit fires)
Summary
In non-interactive mode (codex exec), only the UserPromptSubmit hook fires.
All post-session hooks (Stop, SessionStop, PostToolUse, PreToolUse) are
never invoked. The same hooks configured in ~/.codex/hooks.json fire correctly
in interactive TUI mode.
## Environment
- Codex CLI: 0.121.0 (broken)
- Last known working: observed working in some version <= 2026-04-19 (interactive TUI)
- OS: Windows 11 Pro 10.0.26200
- Node: v24.12.0
- npm: 11.7.0
- Install:
npm install -g @openai/codex@latest - Features:
codex_hooks = true(confirmed viacodex features list)
## Reproduction
- Install Codex and enable hooks:
```powershell
npm install -g @openai/codex@latest
codex features enable codex_hooks
- Create ~/.codex/hooks.json:
{
"hooks": {
"UserPromptSubmit": [{
"hooks": [{
"type": "command",
"command": "node -e \"process.stderr.write('HOOK UserPromptSubmit FIRED\\n')\""
}]
}],
"Stop": [{
"hooks": [{
"type": "command",
"command": "node -e \"process.stderr.write('HOOK Stop FIRED\\n')\""
}]
}],
"SessionStop": [{
"hooks": [{
"type": "command",
"command": "node -e \"process.stderr.write('HOOK SessionStop FIRED\\n')\""
}]
}],
"PostToolUse": [{
"hooks": [{
"type": "command",
"command": "node -e \"process.stderr.write('HOOK PostToolUse FIRED\\n')\""
}]
}]
}
}
- Run in non-interactive mode:
codex exec "Say hi"
Expected
All four hooks (UserPromptSubmit, Stop/SessionStop, PostToolUse) fire.
Actual
Only UserPromptSubmit fires. The Codex output shows:
hook: UserPromptSubmit
hook: UserPromptSubmit Completed
codex
Hi
tokens used
...
No other hook lines appear. Hook scripts are not invoked (verified via
file-level log writes — only UserPromptSubmit produces log entries).
Event names verified present in the Codex binary
Using PowerShell UTF-8 regex scan over codex.exe:
UserPromptSubmit, PreToolUse, PostToolUse, SessionStart,
SessionStop, Notification, Stop, CompactStart
So the events exist as valid hook names, they just aren't emitted in exec mode.
Comparison with interactive mode
The same hooks.json works perfectly when running the interactive TUI
(plain codex, no exec). Session files in ~/.codex/sessions/YYYY/MM/DD/
from interactive runs have "originator":"codex-tui" and "source":"cli"
and the hook log shows Stop firing. Session files from codex exec runs
have "originator":"codex_exec" and "source":"exec" and no Stop fires.
Impact
Any workflow that relies on post-response automation — auto-save to external
memory systems, telemetry, triggering follow-up actions, structured logging —
is broken in codex exec. Users must fall back to manually invoking hooks
from a wrapper script after each codex exec call.
Suggested fix
Either:
- Emit Stop / SessionStop in codex exec after the final response is
delivered (before process exit), OR
- Document that exec mode intentionally skips session hooks and provide
a dedicated --post-hook CLI flag for non-interactive use cases.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗