Add session support to "codex exec"

Resolved 💬 7 comments Opened Sep 1, 2025 by sldx Closed Sep 3, 2025
💡 Likely answer: A maintainer (gpeal, contributor) responded on this thread — see the highlighted reply below.

What feature would you like to see?

Currently, you can execute arbitrary prompts from the command line using

codex exec "Build a Tetris game"

However, this is a single shot with no option to continue the conversation. This is extremely limiting.

Claude Code has support for sessions, so you can send a command (with -p in their case) and add a session ID so that this message can be part of a longer conversation. This vastly increases the usefulness of this mode.

Please add something similar to Codex CLI

Are you interested in implementing this feature?

No

Additional information

_No response_

View original on GitHub ↗

7 Comments

wbdb · 10 months ago

Why don't you start the session with codex and then work with it? No need for exec in this case.

TIAcode · 10 months ago
Why don't you start the session with codex and then work with it? No need for exec in this case.

Huh? codex exec exists because it's useful in some automated situations where codex TUI can't be used. In those cases, having a session in the TUI doesn’t really help.

I guess the best workaround for now is to have codex exec output in JSON and then parse & use that (or LLM-compressed) as input for the next run. But I feel session support should be table stakes for this kinda tool. +1 on the request, would've needed this yesterday as well.

dnlo · 10 months ago

It's supported with experimental_resume = $session_file_path
It will pull the session if you specify it in the cli, doesn't seem to work if I put it in config.toml

echo what did we talk about | codex exec -c experimental_resume=$session_json_path

MaurUppi · 10 months ago
It's supported with experimental_resume = $session_file_path It will pull the session if you specify it in the cli, doesn't seem to work if I put it in config.toml echo what did we talk about | codex exec -c experimental_resume=$session_json_path

Would you mind educating me on how to use the command?

echo "what did we talk about" | codex exec  -c experimental_resume=$session_json_path
Reading prompt from stdin...
[2025-09-03T12:49:24] OpenAI Codex v0.27.0 (research preview)
--------
workdir: /Users/ouzy/Documents/DevProjects/workflow-test
model: gpt-5
provider: openai
approval: never
sandbox: read-only
reasoning effort: medium
reasoning summaries: auto
--------
[2025-09-03T12:49:24] User instructions:
what did we talk about

2025-09-03T12:49:24.102543Z ERROR codex_core::codex: Failed to create session: failed to resume rollout from "": No such file or directory (os error 2)
Error: internal error; agent loop died unexpectedly

SessionID-related issues/pull

https://github.com/openai/codex/pull/2377
https://github.com/openai/codex/issues/2434
https://github.com/openai/codex/pull/2377

dnlo · 10 months ago

$session_path is a path to file that has something like this inside

{"id":"b9c2b331-ffde-46c2-90e5-b763816c0bc8","timestamp":"2025-09-03T07:52:14.977Z"}

If you put that file in the same dir you are running the command from and the file is named session.jsonl the command will be:
echo what did we talk about | codex exec -c experimental_resume=session.jsonl
`

gpeal contributor · 10 months ago

duplicate of 1991

sldx · 10 months ago
duplicate of 1991

@gpeal wait what? No it's not the same thing. That issue is about resuming an interactive session. This is about using the exec param, non-interactive