Skip to content

UserPromptSubmit and SessionStart hooks fire simultaneously on first prompt #15266

Closed
JimJafar/the-librarian-codex-plugin
#1

Description

@disrupt-labs-core

Bug

When both SessionStart and UserPromptSubmit hooks are registered, they fire simultaneously on the first prompt. On subsequent prompts, only UserPromptSubmit fires (expected).

Expected behavior

SessionStart should complete before UserPromptSubmit fires on the first prompt, or they should not overlap — since the first prompt is both a session start event and a prompt submit event.

Steps to reproduce

  1. Register both hooks in .codex/hooks.json:
{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [{ "type": "command", "command": "echo 'SessionStart fired'", "timeout": 10 }]
      }
    ],
    "UserPromptSubmit": [
      {
        "hooks": [{ "type": "command", "command": "echo 'UserPromptSubmit fired'", "timeout": 10 }]
      }
    ]
  }
}
  1. Start Codex CLI with codex -c features.codex_hooks=true
  2. Send the first prompt — both hooks fire simultaneously
  3. Send a second prompt — only UserPromptSubmit fires

Environment

  • Codex CLI v0.116.0
  • macOS

Activity

  1. added
    bugSomething isn't working
    CLIIssues related to the Codex CLI
    on Mar 20, 2026
  2. added a commit that references this issue on Mar 20, 2026
    f05514f
  3. mvanhorn commented on Mar 20, 2026

    @mvanhorn

    I've prepared a fix for this in branch mvanhorn:fix/session-start-hook-timing.

    The fix fires SessionStart hooks eagerly during session creation (right after SessionConfigured is emitted) instead of deferring them to the first turn. The hook outcome (should_stop + additional_contexts) is stored on SessionState and consumed by the first turn, preserving the existing context injection behavior while fixing the timing.

    Key changes:

    • hook_runtime.rs: new run_session_start_hooks_eager() fires hooks at init time using send_event_raw (no TurnContext needed)
    • hook_runtime.rs: run_pending_session_start_hooks() checks for a stored eager outcome before falling back to deferred execution
    • state/session.rs: new EagerSessionStartHookOutcome type and field
    • codex.rs: session init calls eager hooks instead of setting pending_session_start_source

    Builds cleanly with cargo check -p codex-core. Branch is at https://github.com/mvanhorn/codex/tree/fix/session-start-hook-timing

    (PR creation is blocked by org OAuth policy - will submit via web UI.)

  4. added
    agentIssues related to the core agent loop
    rust_toolchain_package_managerPull requests that update rust_toolchain_package_manager code
    hooksIssues related to event hooks
    and removed
    CLIIssues related to the Codex CLI
    rust_toolchain_package_managerPull requests that update rust_toolchain_package_manager code
    agentIssues related to the core agent loop
    on Mar 30, 2026
  5. eternal-openai commented on Apr 10, 2026

    @eternal-openai
    Contributor

    @abhinav-oai and I had a chance to look at this, and SessionStarts do run before UserPromptSubmits. They still wait for the first prompt as the official start of session, but ordering is enforced. So the practical way to test that is to put a sleep into a SessionStart hook, and notice that the UserPromptSubmit hooks don't run until that sleep is complete. So I think this works

  6. 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.

  7. Morriz commented on May 14, 2026

    @Morriz

    why would SessionStart not fire when the agent is ready to receive input (a valid use case we have and want this event for)? UserPromptSubmit is the event that gets triggered on you guessed it, the moment a user submits a prompt. So imo it's completely missing the goal when those timings are the same?

    Claude Code does it correct, so why not honor the same?

  8. Morriz commented on May 14, 2026

    @Morriz

    can we re-open this please @eternal-openai ?

  9. added 3 commits that reference this issue on May 26, 2026
    007ef71
    b236a1c
    65f36f7
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 workinghooksIssues related to event hooks

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions