Skip to content

Codex exec does not fire Stop / SessionStop / PostToolUse hooks (only UserPromptSubmit fires) #18607

Closed as not planned

Description

@MichalPoterek

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 via codex features list)

Reproduction

  1. Install Codex and enable hooks:
    npm install -g @openai/codex@latest
    codex features enable codex_hooks
    
  2. 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')""
    }]
    }]
    }
    }
  3. 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.

Activity

  1. added
    bugSomething isn't working
    CLIIssues related to the Codex CLI
    execIssues related to the `codex exec` subcommand
    hooksIssues related to event hooks
    windows-osIssues related to Codex on Windows systems
    on Apr 20, 2026
  2. github-actions commented on Apr 20, 2026

    @github-actions
    Contributor
  3. removed
    CLIIssues related to the Codex CLI
    windows-osIssues related to Codex on Windows systems
    on Apr 20, 2026
  4. etraut-openai commented on Apr 20, 2026

    @etraut-openai
    Contributor

    I think this bug report is based on some incorrect assumptions.

    1. Codex doesn't support a hook named "StopSession". It does support "Stop".
    2. PreToolUse and PostToolUse fire only for actual tool use. The prompt "Say hi" will not typically result in any tool calls.
    3. Hooks are implemented in the core agent loop, which sits beneath exec, TUI, and other client layers. That means you should see no differences in behavior related to hooks between exec and TUI.

    Refer to this documentation.

    If you have more detailed questions, you can clone this repo and ask Codex to diagnose issues you're having with your hook.

  5. oxysoft commented on May 8, 2026

    @oxysoft

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingexecIssues related to the `codex exec` subcommandhooksIssues related to event hooks

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions