Feat: Support streaming all outputs and also support passing history with -q
Hi, thanks for making this open source!
I want to propose a few cli options for non-interactive mode (-q):
--history - pass a message history for non-interactive mode to continue working
--stream - stream all outputs (not just the final output) from non-interactive mode.
Note that for --stream, I believe this may already be available as -j/--json and it needs to be exposed? https://github.com/openai/codex/blob/main/codex-cli/src/cli.tsx#L37
Example use case for history
If a user runs an initial command with -q (or -j), then gets all the message history from stdout, then they could pass that information back to another -q / -j call in order to incrementally work with the LLM. This is similar to interactive mode, but it also allows non-interactive consumers to pass message history properly in the standard openai message format.
I'm currently working on an API server at https://github.com/Flux159/codex-api-server that could then expose this functionality to other clients via HTTP/S (with auth) - allowing a number of other clients to be built with codex without being restricted by the terminal api.
Storing history
There's another potential command around history that may be useful purely for the interactive CLI --save-history. Essentially it would store chat history in ~/.codex/chats. This would allow a user to restart an interactive session with a previous history by using --load-history ~/.codex/chats/chat-1.json without losing the intermediate messages & context.
2 Comments
https://github.com/openai/codex/issues/146 and https://github.com/openai/codex/discussions/341 both appear related to this. It looks like sessions are already stored to
~/.codex/sessions/rollout-*.json, so we'd need some way to restart an interactive session with a previous history by using those.Thanks for the feedback! We're primarily focused on the native/Rust implementation of Codex CLI and would love to see if this is still an issue on the latest version. If it is, please let us know, and we can explore these features further.