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> on codex exec when 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 --goal for 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 --goal with --ephemeral and exec subcommands
  • regenerated app-server protocol schema for the small thread/goal/set setup flag

View original on GitHub ↗

5 Comments

github-actions[bot] contributor · 2 months ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #26949

Powered by Codex Action

etraut-openai contributor · 2 months ago

There's no need for a dedicated --goal command-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".

zclllyybb · 2 months ago
There's no need for a dedicated --goal command-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 codex to enter goal mode, it still does not work. I clearly saw the create_goal tool in the source code, but even when explicitly requesting the model to call it, gpt-5.5 xhigh rarely 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.

etraut-openai contributor · 2 months ago

@zclllyybb, can you give me concrete repro steps that demonstrate the failure to create a goal when asked to do so?

zclllyybb · 2 months ago
@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.