UserPromptSubmit and SessionStart hooks fire simultaneously on first prompt
Resolved 💬 5 comments Opened Mar 20, 2026 by disrupt-labs-core Closed Apr 10, 2026
💡 Likely answer: A maintainer (eternal-openai, contributor)
responded on this thread — see the highlighted reply below.
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
- 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 }]
}
]
}
}
- Start Codex CLI with
codex -c features.codex_hooks=true - Send the first prompt — both hooks fire simultaneously
- Send a second prompt — only
UserPromptSubmitfires
Environment
- Codex CLI v0.116.0
- macOS
5 Comments
I've prepared a fix for this in branch
mvanhorn:fix/session-start-hook-timing.The fix fires
SessionStarthooks eagerly during session creation (right afterSessionConfiguredis emitted) instead of deferring them to the first turn. The hook outcome (should_stop+additional_contexts) is stored onSessionStateand consumed by the first turn, preserving the existing context injection behavior while fixing the timing.Key changes:
hook_runtime.rs: newrun_session_start_hooks_eager()fires hooks at init time usingsend_event_raw(noTurnContextneeded)hook_runtime.rs:run_pending_session_start_hooks()checks for a stored eager outcome before falling back to deferred executionstate/session.rs: newEagerSessionStartHookOutcometype and fieldcodex.rs: session init calls eager hooks instead of settingpending_session_start_sourceBuilds 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.)
@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
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.
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?
can we re-open this please @eternal-openai ?