Codex Hooks SKILL OpenAI's Codex now supports hooks, an extensibility framework that lets developers inject custom scripts into the agent's loop at lifecycle events such as PreToolUse, PostToolUse, SessionStart, and Stop. Hooks are discovered from hooks.json or inline [hooks] tables in config.toml at user and project config layers, and non-managed command hooks must be reviewed and trusted via the /hooks CLI command before they run. | name | codex-hook | |---|---| | description | Helps users and agents understand how to write codex hooks. Use this whenever hooks are mentioned. | For the complete documentation index, see llms.txt https://learn.chatgpt.com/llms.txt . Markdown versions of documentation pages are available by appending .md to the page URL Hooks are an extensibility framework for Codex. They allow you to inject your own scripts into the agentic loop, enabling features such as: - Send the chat to a custom logging/analytics engine - Scan your team's prompts to block accidentally pasting API keys - Summarize chats to create persistent memories automatically - Run a custom validation check when a chat turn stops, enforcing standards - Customize prompting when in a certain directory Runtime behavior to keep in mind: - Matching hooks from multiple files all run. - Multiple matching command hooks for the same event are launched concurrently, so one hook can't prevent another matching hook from starting. - Non-managed command hooks must be reviewed and trusted before they run. Hooks run at different points in a conversation: | When | Hooks | |---|---| | During a turn | PreToolUse , PermissionRequest , PostToolUse , PreCompact , PostCompact , UserPromptSubmit , SubagentStop , Stop | | When a session or subagent starts | SessionStart , SubagentStart | | When the main thread ends | SessionEnd doesn't run for subagents | Codex discovers hooks next to active config layers in either of these forms: - hooks.json - inline hooks tables inside config.toml Installed plugins can also bundle lifecycle config through their plugin manifest or a default hooks/hooks.json file. See Build plugins https://developers.openai.com/plugins/build/plugins bundled-mcp-servers-and-lifecycle-hooks for the plugin packaging rules. In practice, the four most useful locations are: - ~/.codex/hooks.json - ~/.codex/config.toml -