Support --session-id flag for `codex exec` to specify session ID upfront
Resolved 💬 2 comments Opened Mar 20, 2026 by chenditc Closed Mar 20, 2026
💡 Likely answer: A maintainer (github-actions[bot], contributor)
responded on this thread — see the highlighted reply below.
Problem
When using codex exec to start a new session, there is no way to specify the session ID upfront. The session ID is only discoverable after the process starts (from its output). This contrasts with other CLI agents:
- Claude Code supports
--session-id <id>for new sessions and--resume <id>for existing ones - Cursor Agent accepts
--resume <id>which creates a new session if the ID doesn't exist
With Codex, the only session-related flag is codex exec resume <id>, which only works for existing sessions.
Use Case
When orchestrating multiple agent sessions programmatically (e.g., from a management console or automation tool), it's very useful to assign a known session ID before the process starts. This allows:
- Pre-registering the session in a database or UI before the run begins
- Correlating logs and output without needing to parse the initial output to discover the ID
- Simplifying resume logic — the orchestrator can use the same ID for both new and resumed runs
- Race-condition-free tracking — no window between process start and ID discovery where the session is "unknown"
Proposed Solution
Add a --session-id <id> flag (or similar) to codex exec that lets the caller specify the session ID for a new run. If the session already exists, it could either error or behave like resume (TBD).
# New session with caller-specified ID
codex exec --session-id my-custom-id-123 --json -m o4-mini < prompt.txt
# Resume existing session (already supported)
codex exec resume my-custom-id-123 --json < prompt.txt
Thank you!
2 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Closing as duplicate of #13242 which requests the same feature. Added our use case there as a +1.