Event Hooks
Resolved 💬 76 comments Opened Aug 9, 2025 by aehlke Closed Mar 27, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor)
responded on this thread — see the highlighted reply below.
Let us define event hooks with pattern matching, to trigger scripts/commands before/after codex behaviors.
76 Comments
Prioritize please 🙏 - hooks in the lifecycle will allow for advanced steering/context-engineering, and enterprise guardrailing. Plus cool community whatever.
Would encourage the Codex team to follow Claude Code's schema!
https://docs.claude.com/en/docs/claude-code/hooks
+1
+1000, I'm really missing this from CC.
Claude Code and Cursor both support blocking + feedback providing hooks.
This will prove to be an integral feature for harnesses... looking forward to Codex's implementation.
Please prioritize 🙏 - hooks are very necessary
This is the final feature that will make me throw anthropic in the trash and never look back. You would get so many power users if you add hooks in.
Indeed, hooks unlock so much potential.
Missing this too!
We are badly missing approval requests hooks!!
My use case is that I need to run a script when user submits their prompt, so that I can show in a tmux status bar that an agent is active in that window. Claude can handle this with the
UserPromptSubmithook.My solution: clone this repository and implement the corresponding functionality using Claude; I really can't wait for the official team to add this feature.
Unfortunately, we are releasing https://github.com/eqtylab/cupcake without codex native support.
Optimistic in this getting implemented... working with large enterprises on cupcake and we want to get codex out there where stakeholders (cyber assurance, dev directors) feel confident and have an opportunity to own their own alignment.
yes, we can use hooks for skill https://scottspence.com/posts/how-to-make-claude-code-skills-activate-reliably#the-winner-sort-of-forced-eval-hook
I'd love to see hooks so I can apply things like newline separator normalization, formatting etc after edits. the builtin edit tool screws up new line separators on every edit.
+1
+1
This is important for holistic governance. The agentic OS is coming. If codex intends to compete - hooks are mandatory. In this harness and any future non-harness.
Also it's fun to build random integrations. For those that prefer plan mode - hooks around agent mode would enable better management or custom planning (similar to how opencode does plugins) - https://github.com/backnotprop/plannotator
Otherwise you can offload tasks like lint/format/test. You can prevent the agent from stopping. You can automate governance. Etc etc
I implemented an event hooks system in my fork, xCodex (xcodex), that can run external scripts on lifecycle events (fire-and-forget) and pass a JSON payload via stdin (with a payload-path file fallback for large payloads). It’s still WIP and may have bugs, but if you want to try it today: https://github.com/Eriz1818/xCodex (docs: docs/xcodex/hooks.md, examples: examples/hooks/).
If maintainers are interested in upstreaming something like this, I’m happy to open an issue/PR proposal and adapt it to match Codex’s contribution guidelines / desired behavior (I understand new feature PRs may not be accepted right now).
Supported events in xCodex include:
Config example ($CODEX_HOME/config.toml)
Pattern matching example (in the hook script)
You can also scaffold and test hooks in the fork:
Will there be a Rust API for this? If so, I'd be very interested to see what can be done with PyO3 to allow users to write Python hooks for Codex.
Interesting idea. I am not 100% sure, but I believe even Claude Code doesn't have in-process hooks yet. I am also concerned about the security, stability, and sandbox policy concerns with in-process hooks. But I am experimenting with it.
Yes please, ASAP, CC is starting to pass you from behind, do not sleep, add HOOKS :)
This is the single most important missing feature holding codex behind.
As of last night, OpenAI subscriptions work with OpenCode officially. You can use the plugin feature of OpenCode to create hooks 1:1 of Claude Code etc. I converted everything over to using it last night, and it is an amazing experience.
Event hooks would help open source tooling integrate with Codex, similar to how Claude Code exposes pre/post command hooks. Given the recent commitment to OSS support, this seems well-aligned.
xCodex (https://github.com/Eriz1818/xCodex) now has three hook modes:
Claude hooks are supported, as is.
Performance (release build, Python 3.11.14, payload 373 bytes; 3 runs):
Larger payloads:
that was easy - codex FTW
<img width="1907" height="767" alt="Image" src="https://github.com/user-attachments/assets/c3756c20-1765-44c5-b29d-a12a13398072" />
https://github.com/openai/codex/pull/9440
I created all of Claude Code's hooks, plus PostCompact hooks. I tried to make a PR, but they don't accept them. Slightly rude reponse from them but its my fault for letting Codex do the PR. I didnt read the contribution guidelines lol
Anyway, they work. Hopefully we get Hooks added sooner rather than later.
https://github.com/openai/codex/pull/9796
Oh I see you got the same comment I did. I dont feel so bad now lol. Nice to see they're coming soon. This will make Codex, more or less, as featured as Claude Code. Exciting times.
<img width="1010" height="360" alt="Image" src="https://github.com/user-attachments/assets/41ccf8fc-cf6f-4c9e-8fae-41a3a65e242a" />
@etraut-openai Thank you so much for all your work on Codex, it's one of my favorite agents, especially for complicated problems! I'm just wondering if you have an idea of the timeline for hooks? Don't mean to push -- just trying to figure out if it's worth spending the time to work on alternatives or if support is right around the corner.
For context, I'm trying to support Codex in Git AI. Thank you!
@svarlamov, support for hooks is under development. I'll be able to share more details once it's a little further along.
looks like agent-turn-start is in main now
This is an important feature. Need this to maintain audit trail of coding agents in https://github.com/safedep/gryph
I’d also like this for https://github.com/atbabers/intentra-cli
You’ll notice a lot of other vendors support this. Excited to see this come into fruition.
@etraut-openai congrats on Codex desktop app launch! Are hooks planned for both that and CLI?
@jbeno, we will integrate it into the core agent loop so all Codex surfaces will benefit from it.
Event Hooks are in the latest 0.99 build, all the plumbing for new event types have been added.
Stopping semantics need to be added, but this logic should be easy to implement since it already technically exists (for example, when it stops to ask for permissions).
I bet they launch soon.
I got hooks working. I'll let folks know if it blows up.
tell us or else
I'm new to GitHub.
You can't see the PR?
@michaeljboscia, we're not accepting unsolicited code contributions in this project. Please refer to our contribution guidelines for details.
Work on event hooks is underway. We'll announce when it's ready for use.
haha nah boss. i thought you were talking about the official hooks. they arent fully wired up yet so that's why i was confused lol.
they just added AfterToolUse hook. Not functional yet tho.
Meanwhile, I ported my changes from https://github.com/openai/codex/issues/3247#issuecomment-3762213637 to event hooks and it's available here: https://github.com/Mygod/codex/commit/f4d7a3dd174e10eea7a8af3158cf83b7f8ed70d0
Just in case anyone wants approval notifications. :)
Not sure if this issue is better separate so I kept it as a comment in this thread for now. Details below.
We hit a notify-hook noise issue with multi-agent sessions:
agent-turn-completefires for subagent completions (spawned/delegated threads), not just the top-level user turn.exec/apply-patch/input/elicitation) are already gated to avoid subagent dispatch.Why this is hard to handle downstream:
agent-turn-completedoes not include subagent/session-source metadata, so hooks can’t reliably filter parent vs subagent turns.Local patch we applied:
HookEvent::AfterAgentdispatch whensession_sourceisSessionSource::SubAgent(_).agent-turn-complete.Suggested upstream direction (backward-compatible):
agent-turn-completetop-level-only by default, and/orsubagent-turn-completenotify event, and/orsession_source/subagent info in notify payloads so hooks can filter.Use case: real-time tool call progress in SDK integrations
We're building a chat application that integrates Codex via
@openai/codex-sdk.Currently
thread.run()only returnsfinalResponseafter the entire turncompletes — there's no way to receive intermediate tool call events (tool name,
status, input/output) as they happen.
This makes it impossible to show users real-time progress like "running shell
command X" or "reading file Y" during long-running tasks. Users see a blank
loading state for several minutes with zero feedback.
What we need:
onToolCall/onProgresscallback inthread.run()options, orThe Claude Code Agent SDK (
@anthropic-ai/claude-agent-sdk) has the same gap.Both SDKs expose only a final-result API, making it hard to build responsive UIs
on top of them.
For anyone who urgently needs this feature for functionality you're building on top, note that codex already supports
CODEX_TUI_RECORD_SESSION=1andCODEX_TUI_SESSION_LOG_PATH=/path/to/file.jsonlwhich log all events for the current session immediately. So if your hooks are read-only (as in my use case), it's already possible to implement them with a simple wrapper that calls codex and polls the log file in the backgroundThis feature as been opened for over 6 months now? Wondering if there's an actual timeline for this or should we consider the hack above?
Given that it's already been over 6 "AI years", you can safely assume that this issue has been abandoned. /j
We are actively working on it! More details to come soon.
nice
There have been numerous commits related to hooks in the last 3 weeks. They built the scaffolding already. I predict they release an experimental version in the next 2-3 weeks
Awesome news. I just switched from Claude and this was one of the first few things I noticed were missing in Codex. Looking forward to this!
@aehlke Is there any documentation on using hooks?
Is this feature complete yet?
We need this if
codexis to be fully embraced in enterprise. It's my preferred coding agent harness by far right now but lack of custom hooks on bash calls is preventing me from using it for devops monitoring workflows at work because I can't satisfy our guardrail policies using codex.Production Use Case: Multi-Agent Memory Discipline with External DB
We run a multi-agent setup (4 agents: Codex CLI, Claude Code, Cursor, GPT-5) coordinating on a consensus-critical blockchain codebase. All agents share persistent memory via Neon PostgreSQL (pgvector embeddings for semantic search).
What we need hooks for (prioritized)
| Priority | Event | Use Case |
|----------|-------|----------|
| P0 |
SessionStart| Load hot context from Neon DB (agent statuses, recent memories, active tasks) before first turn. Currently using MCP tool call as workaround — agent can forget to call it. || P0 |
Stop/SessionEnd| Persist session summary + embeddings to Neon before exit. Without this, work done in last turns is lost if agent doesn't self-checkpoint. || P1 |
PreCompact| Write checkpoint with full-context embedding before compaction destroys it. This is the single highest-value hook for long-running sessions — once context is compacted, the agent can't recover what it knew. || P1 |
PreToolUse(blocking) | Governance: block destructive git commands (push --force,reset --hard,rm -rf). Currently usingapproval_policybut need finer control. || P2 |
PostToolUse(config-driven) | Detect merge/push events in tool output → trigger compliance checks. Currently theafter_tool_useVec is always empty — only programmatic registration. || P2 |
UserPromptSubmit| Inject cross-agent delta (what other agents did since last check) before each turn. |Current workaround: Discipline MCP Server
Since Codex lacks lifecycle hooks, we built a custom MCP server providing 6 lifecycle-equivalent tool calls:
session_init,checkpoint,session_summary,cross_agent_delta,post_merge_check,compliance_status.Problem: This is "soft enforcement" — the agent can skip calling
session_initeven though AGENTS.md says "MANDATORY". Real hooks would be deterministic.Config suggestion
Aligned with Claude Code's proven pattern, but adapted to TOML:
Context injection (critical)
The most valuable feature from Claude Code hooks is
additionalContext— hook stdout can inject text that the model sees as system context:This turns hooks from "fire-and-forget notifications" into "active context providers." Without this,
SessionStarthooks can run scripts but can't feed results back to the model.Source analysis notes
From reading the Rust source:
HookEventenum currently has onlyAfterAgentandAfterToolUse. TheHooksstruct hasafter_tool_use: Vec::new()(always empty — no config path). Thenotifyfield is the only config-driven hook and only populatesafter_agent. The scaffolding for expansion is clean — adding variants to the enum + config parsing + dispatch points intui/src/lib.rsandcore/src/tools/orchestrator.rswould cover all the events above.Looking forward to the official release! Happy to test early/experimental builds.
@aehlke may I ask why you closed this already?
@EddyVinck and where did you hear this?
@Morriz Many unnecessary pings in the ticket - that's why I closed it since they stated it's officially on the way. But I didn't realize they were using my ticket to officially track it. It's been reopened. I've unsubscribed from notifications instead.
We need hooks, has this feature been implemented?
<img width="603" height="823" alt="Image" src="https://github.com/user-attachments/assets/268b9e87-a901-4fd3-b3e4-ac69b9eb1f77" />
https://x.com/LLMJunky/status/2031582374064951414?s=20
First of many hooks are starting to roll out.
Async hooks would be awesome too!
@am-will I'm not available to view that thread. Can anyone give a quick overview of where these are defined? I'm not seeing options in config.toml or slash commands.
@Geogboe in the release notes you'll find the link to this PR: https://github.com/openai/codex/pull/13276/changes
you should be able to. its public.
here's a start. ask codex to read the prs and help you set it up, it'll oblige! cheers
<img width="609" height="1093" alt="Image" src="https://github.com/user-attachments/assets/99a19ac1-9107-47b5-888d-db23d2ecbbc9" />
<img width="680" height="601" alt="Image" src="https://github.com/user-attachments/assets/65ed6144-a474-4fec-b2f7-c7e261a72e1f" />
Claude Code shipped hooks recently and the pattern matching approach works well in practice. from our setup:
we define hooks in settings that fire on specific events - pre-tool-call, post-tool-call, notification triggers. the key design decision is whether hooks block the agent or run async.
for the scheduling side, we use launchd plists that trigger shell scripts on intervals. each script spawns an agent with a specific prompt. the hook system complements this by handling event-driven triggers that don't fit fixed schedules.
one thing that matters a lot: hooks that modify state need to be idempotent. our posting pipeline runs hourly and checks a database before posting to avoid duplicates - if the hook fires twice (launchd can do this on wake-from-sleep), the dedup query catches it.
would be useful if codex hooks supported: before/after patterns on specific tool names, environment variable injection from the hook config, and a way to pass hook output back into the agent context (not just succeed/fail)
our hook + scheduling setup: https://github.com/m13v/social-autoposter/tree/main/launchd - launchd plists that trigger Claude agents on intervals. the dedup and rate limiting logic: https://github.com/m13v/social-autoposter/blob/main/skill/SKILL.md. the multi-agent tmux orchestration: https://github.com/m13v/tmux-background-agents
Event hooks + GNAP could enable powerful multi-agent workflows:
Agent A completes task → event hook → triggers Agent B via shared git repo.
GNAP provides the coordination layer (tasks, runs, messages as JSON files). Codex event hooks could be the trigger mechanism. No external server needed.
I’d like to add one more request to the hook expansion discussion: please publish a documented contract alongside the feature.
At the moment, Codex hooks look promising, but from a user/operator perspective, the rollout still feels incomplete. If hooks are going to be exposed even in an experimental state, I believe there should be at least a minimal official reference covering the following:
Right now, users are left to reverse-engineer behavior from short changelog notes, scattered examples, and community experimentation. That makes it much harder to adopt hooks safely in real workflows, especially for people building orchestration, guardrails, or session lifecycle tooling.
The current frustration does not come only from the limited hook coverage, but also from the lack of a clear contract for the functionality that already exists. I think that is exactly the core issue. Even before adding many more events, it would already help a lot to properly document the current surface.
So my request is:
Without that, users are not integrating against a documented interface; they are effectively beta-testing it through reverse engineering.
That is what ChatGPT 5.4 said. As for my own opinion, I do not really have any strong thoughts either way.
Coming up soon @ksdf7235 ! It's all still experimental, but shaping up fast
Event hooks are now available as an experimental feature. Refer to this documentation for details.
@etraut-openai Why is Windows support temporarily disabled?
do you have a plan to support "Edit|Write" matcher in PostToolUse、PreToolUse ? i think plenty of feature relies on this
@etraut-openai
补充一条建议:在现有 Hooks 体系中新增
PreCompact生命周期事件(或BeforeCompact),触发于手动/自动 compaction 前。建议包含reason(manual/auto)、total_usage_tokens_before_compaction、auto_compact_limit、session_id/thread_id/turn_id、cwd、可选recent_rollup_summary,并支持失败策略on_error: continue|abort与可选decision返回(continue/abort)。这个可以直接承接之前 #12208 的诉求。@etraut-openai May I ask about the progress of this?
please and thank you. i have many hooks i can't even use because of this
I'm going to lock this thread since it's now closed. If you'd like to report bugs or request additional extensions to the Event Hooks feature, please open new issues.