Add --goal support to codex exec
Resolved 💬 5 comments Opened Jun 8, 2026 by earonesty Closed Jun 9, 2026
💡 Likely answer: A maintainer (github-actions[bot], contributor)
responded on this thread — see the highlighted reply below.
Feature request
Add baseline goal support to codex exec, exposed as a root-level flag:
codex exec --goal "here's a goal" "start working"
This is separate from resume support. The requested behavior is for a new codex exec thread to start with an active persisted goal before the initial user turn is submitted.
Proposed behavior
- Accept
--goal <OBJECTIVE>oncodex execwhen starting a new exec thread. - Persist the goal as active before the first turn.
- Make the goal objective visible to the first model request.
- Reject
--goalfor paths where a new persisted goal cannot be cleanly established, such as exec subcommands and ephemeral threads.
Implementation sketch
I put together a small implementation branch here:
https://github.com/openai/codex/compare/main...earonesty:codex/exec-goal-flag?expand=1
The implementation adds codex exec --goal <OBJECTIVE>, sets the active thread goal through thread/goal/set, suppresses idle goal continuation for this setup path so the initial prompt remains the first turn, and passes the goal objective into the initial turn as untrusted additional context.
Testing included in the implementation branch
- CLI parsing coverage for
--goal - exec integration test verifying the goal is set before the initial turn and reaches the model request
- rejection tests for
--goalwith--ephemeraland exec subcommands - regenerated app-server protocol schema for the small
thread/goal/setsetup flag
5 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
There's no need for a dedicated
--goalcommand-line switch. You can already just tell the agent to create a goal for itself. For example,codex exec "Create a goal to compute 1+1".I conducted detailed experiments and found that in some of my complex scenarios, even after multiple explicit requests for
codexto enter goal mode, it still does not work. I clearly saw thecreate_goaltool in the source code, but even when explicitly requesting the model to call it,gpt-5.5 xhighrarely complies. Therefore, I still urgently need this feature. Currently, we have to patch this functionality ourselves in the codex distribution.btw: Do not wish to disturb the official developers of codex, but if other users have the same need, a temporary patch is provided at https://github.com/zclllyybb/codex/tree/codex-exec-goal.
@zclllyybb, can you give me concrete repro steps that demonstrate the failure to create a goal when asked to do so?
Thank you for the reply, I will try to share a complete project and the corresponding trace to reproduce it in the coming days.