hooks: no session identifier in hook payloads; SessionStart not emitted for app-server threads
Summary
Hooks receive no session identifier, and SessionStart is not emitted for threads created programmatically over app-server. Together these make per-session hook integrations (session memory, compaction continuity, telemetry) impossible on programmatic threads and unreliable on exec.
Environment
- codex-cli 0.162.1, macOS
~/.codex/hooks.jsonwithSessionStart/UserPromptSubmit/PreToolUse/PostToolUseregistered,[features] hooks = true- Driven both via
codex execand via a long-livedcodex app-serverprocess creating threads over MCP (orchestrator-style)
Observed
codex exec: hooks fire (SessionStart runs and returnsadditionalContextcorrectly), but the JSON payload delivered on stdin carries no session identifier, so a hook cannot key captured events to a conversation.app-serverwith programmatically created threads: noSessionStarthook invocation observed for new threads at all (PostToolUse-style events may fire during turns, but there is no session boundary signal), so session-scoped context injection never happens for these threads.
Impact
Any hook-based integration that does per-session capture or injection. Concrete case: context-mode (the MCP+hooks context manager) works fully on platforms where hooks carry a session id, and on Claude Code writes a session DB immediately; on Codex its capture layer writes nothing because there is no session key, and programmatic threads never even receive the SessionStart injection. The upstream integration documents the Codex session-id field as N/A for this reason.
Ask
- Include a stable session/thread identifier in hook payloads (stable across turns of one conversation, fresh per thread), so hooks can key state.
- Emit
SessionStart(or document an equivalent boundary event) for threads created throughapp-server.
Related adjacent gap already tracked: #18491 (PreToolUse updatedInput unsupported) - same theme of the hooks platform missing pieces integrations need.
(response from codex)
Thanks for the report. From the 0.162.1 sources, this appears to be expected behavior rather than a confirmed bug:
- Command hooks already receive
session_idon stdin. SessionStartruns on the thread’s first turn, not immediately onthread/start.- Hooks must be trusted individually;
[features] hooks = truealone does not make every hook eligible to run. - MCP-tool hooks receive only their configured arguments, so their template must include
session_idif the tool needs it.
An immediate creation-time hook or replaying SessionStart after a hook becomes trusted would be a feature request.
If a trusted command hook still receives stdin without session_id, or does not run on the first turn, please share the hook configuration, raw stdin, and exact app-server request sequence. That would let us investigate a concrete bug.
(Response from codex)
I checked this on macOS in both codex exec and a long-lived stdio app-server. Trusted command hooks receive session_id on stdin. SessionStart runs when the first turn starts, so creating the thread alone won't trigger it. For an MCP-tool hook, include the session ID in the configured arguments. Closing as expected behavior.