Allows specifying a SessionID for better embedding of automated workflows.
What feature would you like to see?
In my automation workflow, I sometimes need to capture the session ID before resuming in the pipeline backend or during the previous iteration. This used to be inelegant, as I had to capture the session ID from the Codex exec output. Referring to ClaudeCode's --session option, we can specify the session ID from outside the Codex exec startup process. Codex then checks and validates the specified ID to ensure its availability. This is a very elegant and useful feature for automation.
Additional information
No response
If I understand your feature request correctly, I think it's already being tracked in #1780.
If I understand your feature request correctly, I think it's already being tracked in #1780.
Thanks for your attention, but these two threads are still different. #1780 essentially captures the Session ID managed internally by Codex from the output of an already started session, and will still output the session ID in non---json mode. This is the method I'm currently using. My idea is to have an external tool manage the session ID, avoiding capturing and parsing the string from the output of codex exec.
Thanks for the clarification.
I would also like to see something like this implemented. To clarify, when using Claude Code the correct flag to set the session ID is --session-id (ex. claude -p --session-id 550e8400-e29b-41d4-a716-446655440000 "Prompt text"). Rather than parsing the session ID from json output, you can keep your output configured however you want but always retain awareness of the session ID without parsing, as you yourself provided it.
This makes storing the session IDs and later resuming sessions very simple and easy. Right now the workaround with Codex is to parse ~/.codex/sessions which is very possible but is a bit of a hacky workaround that it would be better to avoid.
So something like: codex exec --session-id 550e8400-e29b-41d4-a716-446655440000 "Prompt text"
I would also like to see something like this implemented. To clarify, when using Claude Code the correct flag to set the session ID is
--session-id(ex.claude -p --session-id 550e8400-e29b-41d4-a716-446655440000 "Prompt text"). Rather than parsing the session ID from json output, you can keep your output configured however you want but always retain awareness of the session ID without parsing, as you yourself provided it.This makes storing the session IDs and later resuming sessions very simple and easy. Right now the workaround with Codex is to parse
~/.codex/sessionswhich is very possible but is a bit of a hacky workaround that it would be better to avoid.So something like:
codex exec --session-id 550e8400-e29b-41d4-a716-446655440000 "Prompt text"
Yes, this is an effective workaround and works well in most cases. It requires ensuring that Codex is not started in parallel, regardless of whether it's in the same working directory.
It requires ensuring that Codex is not started in parallel
Personally this breaks my use case. For the application I'm building I need to be able to run multiple instances concurrently and retain the ability to resume any session at a later point.
It requires ensuring that Codex is not started in parallel
Personally this breaks my use case. For the application I'm building I need to be able to run multiple instances concurrently and retain the ability to resume any session at a later point.
Does the Codex SDK or PTY meet your needs?
+1 I'm building an agent orchestrator and it's helpful for 2 scenarios.
- helpful in resuming deleted agent tasks.
- helpful in providing a pre-warmed agent that has the full context of the repo that it's working on. https://github.com/jemdiggity/kanna
+1, with another orchestrator use case: niles runs several interactive codex workers per workspace in tmux and needs to tie each pane to its session for telemetry (token usage per worker).
Claude Code lets the launcher pick the ID (claude --session-id <uuid>), so the link is exact. With codex we have to work it out after launch: scan ~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl, filter by session_meta.cwd, then match the first user message against the brief we sent. That's fragile in practice:
- Parallel starts. Several workers start in the same second in the same
cwd, so time and cwd alone are ambiguous. - Content matching is error-prone. Injected context can mention other sessions' paths, so matching on file content picks the wrong session unless you restrict it to the first user message.
- The file layout is internal and changes (see
migrate-rollouts), so any scanner can break silently.
What we'd need is the same contract as Claude's: codex [--session-id <uuid>] [PROMPT] creates the new session with that ID, fails if it already exists, and works in parallel with no locking. For us, the interactive TUI path matters more than exec.
Another use case for this, from link-assistant/hive-mind#3530. A supervisor creates one UUID per task and uses it for the process supervisor's session, the log file and the Docker container. With Claude Code it also passes claude --session-id <uuid>, so the AI session has the same id and one id finds everything for a task. codex exec (checked on codex-cli 0.163.0) has no equivalent: exec --help only offers resume / fork by an existing id. The supervisor therefore has to parse the thread id out of the JSON stream after the fact and keep a mapping.
Reproduction: codex exec --session-id "$(uuidgen)" "say hi" → Error: unexpected argument '--session-id' found.
Suggested behaviour (same as Claude Code): codex exec --session-id <uuid> creates the new thread with that id, and fails if a rollout with that id already exists (exec resume <uuid> remains the way to continue it).
Another orchestrator use case: Runner runs each agent in its own real terminal and reopens chats with codex resume <id>, so it needs each session's id.
Our current workaround is Codex's own hooks. Runner launches Codex with --enable hooks and a -c hooks.SessionStart=… entry whose command reports session_id back to Runner. It also hooks UserPromptSubmit, as a fallback when SessionStart was missed. Unlike scanning ~/.codex/sessions/, this has no race between concurrent launches, and it also catches /new and /resume inside the TUI. The costs: hooks have to be on with --dangerously-bypass-hook-trust, an MCP server starts on every launch, and the id is only known after startup.
A launch-time --session-id <uuid>, matching Claude Code's, would let us drop the startup part. We'd still want the SessionStart hook for in-TUI /new and /resume.