Logo
FrontierNews.ai

OpenAI's Codex CLI Ditches Loop Commands: Here's Why /goal Changes Everything

OpenAI's Codex CLI uses /goal instead of /loop to keep tasks running toward a verifiable end state, not a timer-based interval. This distinction matters because developers trained on Claude Code often assume Codex is missing a feature when they type /loop and get an error. The two tools split the same job into different primitives, and understanding that split is essential for anyone building automated workflows with Codex.

Why Doesn't Codex CLI Have a /loop Command?

The confusion stems from how Claude Code and Codex approach agent loops differently. Claude Code's /loop is a timer: it reruns a prompt every N minutes while the session stays open. Codex's /goal, by contrast, is a finish line. It keeps a thread working until the system detects that a specific, verifiable end state has been reached. Both tools follow the same underlying agent loop discipline (trigger, goal, actions, verification, memory), but they expose different surfaces to users.

OpenAI itself documented this distinction in its "Unrolling the Codex agent loop" guide, which breaks down three separate layers: the inner harness loop (handled automatically by the Responses API), the durable objective (what /goal controls), and the recurring outer loop (managed by Automations or shell scripts). The inner loop is always running; it is not something users type. What developers author sits one layer up, and that is where /goal lives.

How Does /goal Actually Work in Codex CLI?

The /goal command became available in Codex CLI version 0.128.0 and later. To use it, developers first need to enable the feature flag by adding goals = true to their ~/.codex/config.toml file, or by running codex features enable goals from the command line. After toggling the configuration, users must close and reopen the terminal interface for the change to take effect.

Once enabled, /goal works by setting a durable objective and letting Codex continue working until it detects that objective is complete. The basic syntax is simple: /goal Complete [objective] without stopping until [verifiable end state]. The key is filling in both brackets with concrete, measurable criteria. A weak goal like "Complete the refactor" leaves too much room for interpretation. A strong goal like "Complete the refactor until pnpm test is green and auth/ has no remaining express imports" gives Codex a clear stopping condition.

Continuation is event-driven and happens when the thread is idle. After each turn finishes, Codex inspects the current evidence. If the goal is still open, still within budget, and not paused, it continues automatically from the latest state. Users do not need to type "keep going" or manually restart the process.

Steps to Set Up and Use /goal in Codex CLI

  • Enable the Feature: Add goals = true to ~/.codex/config.toml or run codex features enable goals from the command line, then restart your Codex session.
  • Define a Clear Objective: Write a /goal statement that includes both the objective and a verifiable end state, such as "Reduce p95 checkout latency below 120 ms, verified by the checkout benchmark, while keeping the correctness suite green."
  • Monitor Progress: Type /goal (with no arguments) to view the current goal and its status, or use /goal edit to revise the objective if needed.
  • Control Execution: Use /goal pause to suspend continuation while keeping audit context, /goal resume to continue from the preserved state, or /goal clear to remove the goal and return to single-turn prompts.
  • Set Budget Limits: Pair /goal with token or wall-clock budgets to prevent a stuck goal from running indefinitely and consuming resources overnight.

What About Recurring Tasks? Use Automations Instead

/goal is designed for one objective on one thread, not for recurring work like "every night at 2 a.m." For tasks that need to run on a schedule, Codex offers two outer-loop options. The first is Codex app Automations, which are scheduled tasks available in the Codex or ChatGPT desktop application. These support calendar or interval triggers, such as nightly triage, hourly pull request monitoring, or weekly reports.

The second option is to wrap codex exec in a shell or cron loop, which gives developers more control over scheduling and environment setup. Automations are best when users want a standalone run that starts a new chat each time, or when they want to return to the same chat's context across scheduled runs. However, Codex CLI itself does not provide a scheduled management interface; users must create and manage the cadence in the desktop app.

One practical example from the official documentation: schedule a standalone nightly task at 02:00 that pulls main, runs a flaky-test suite, opens a draft pull request only if it finds a failing test with a reproducer, and otherwise reports "queue empty." The task should stop and notify the user if git push would require force-push or if tests cannot run. This kind of recurring workflow is where Automations shine, whereas /goal is better suited for a single, long-running objective within one session.

Common Pitfalls When Migrating from Claude Code

Developers who are familiar with Claude Code often make three mistakes when switching to Codex CLI. First, they type /loop expecting a timer-based interval command, then assume Codex is missing the feature. Second, they write vague goals like "Complete the refactor" without a verifiable stopping condition, which leaves Codex unable to determine when to stop and can result in unnecessary token consumption. Third, they try to manage recurring schedules inside /goal instead of using Automations or shell loops, which conflates the durable-objective layer with the outer recurrence layer.

To avoid these pitfalls, developers should consult the official Codex CLI reference and the loop-engineering cookbook, which map Claude Code patterns to their Codex equivalents. The mapping is straightforward once the three-layer model is clear: the inner loop is automatic, the durable objective is /goal, and the outer recurrence is Automations or cron.

Why This Distinction Matters for Production Workflows

The difference between /loop and /goal reflects a deeper design philosophy. Claude Code's timer-based loop is useful for interactive sessions where a user is watching and can intervene. Codex's goal-based continuation is better suited for unattended, long-running tasks where the agent needs to verify progress and decide whether to keep working. For production workflows, this means developers can write more robust automation by defining clear stopping conditions upfront, rather than relying on a fixed time interval that may or may not be enough to complete the work.

Objectives must be non-empty and at most 4,000 characters. For longer specifications, developers can point the goal at a file (such as PLAN.md or a test command) instead of pasting the entire spec inline. This keeps goals readable while allowing for complex, multi-step workflows. When paired with a token or wall-clock budget, /goal becomes a powerful primitive for building self-directed agents that know when to stop.