How to Run Claude Code and Codex Overnight via /goal in 2026: 14-Hour Autonomous Mode
MarkdownThe /goal command in Claude Code 2.1.139 and Codex CLI runs an AI agent autonomously for hours. I explain the setup, real examples, and how many tokens it costs.
Read full article
Key takeaways
The /goal command appeared in Claude Code 2.1.139 (May 11, 2026) and Codex CLI 0.128.0 (April 30, 2026, stable since May 21). You define the “done” criterion once, and the agent cycles through plan, action, and verification on its own until the criterion is met or it runs out of tokens. OpenAI publicly showed a 25-hour run using 13 million tokens. This is suited to migrations, benchmarks, and refactors with measurable criteria. It is not suited to UI tasks, production databases, or vague requests like “make it better.”
Information about working with Ailoot is available in the documentation.
What Is /goal and Why Did It Appear in 2026?
Key takeaways
Before /goal, every agent turn required a manual “continue.” It opened a file, read it, wrote something, stopped, and waited. The /goal command sets a completion criterion once—the agent decides for itself when the task is done and does not return control until it has finished.
The scenario we all lived with before April 2026: I give Claude a task, “migrate the project from Pydantic v1 to v2.” It starts, stops after 30 seconds, I look at what it did, write “continue,” it takes the next step, stops, and I write “continue” again. On a large migration, that means 200–300 manual “continues,” and I am effectively babysitting the agent instead of writing other code in parallel.
OpenAI’s analysis was that the problem was not model “stupidity,” but the architecture of the loop. The model did not know when to stop, so it hit the brakes on every turn. Give it a “done” criterion, and it will decide for itself.
That is how /goal came about—a mechanism built into the harness, not the model.
How Do You Set Up Goal Mode in Claude Code?
Key takeaways
Claude Code 2.1.139 was released on May 11, 2026, with the /goal command. A small model (Haiku by default) checks the criterion after every turn. If the criterion is not met, Claude takes another turn. The criterion can be up to 4,000 characters long, and there is one goal per session.
A minimal example from Anthropic’s official documentation:
claude -p "/goal CHANGELOG.md has an entry for every PR merged this week"
This command launches the agent in the background with one goal. Claude finds the PRs, checks them against CHANGELOG.md, adds any missing lines, and stops when the criterion is met.
In interactive mode, just type /goal followed by the condition:
/goal all pytest tests pass and mypy strict reports zero errors
What Claude does next:
- After each turn, a separate fast model (Haiku by default) receives the current condition and conversation history
- This model answers “yes” or “no” with a short reason
- If the answer is “no,” Claude automatically takes another turn without returning control to you
- If the answer is “yes,” the goal is cleared and control returns to you
After each turn, a small, fast model checks whether the condition has been met. If it has not, Claude starts another turn without returning control to you.
Hard limits no one tells you about until you run into them:
/goalworks only in working directories where the trust dialog has been accepted. If you are on a new machine and Claude has not yet remembered that directory, the command will fail- In corporate settings with
disableAllHooksorallowManagedHooksOnly, the command is unavailable - The condition can be up to 4,000 characters long
- Only one goal can be active per session. A new
/goalresets the old one - With
--resume, the condition is preserved, but the turn, time, and token counters reset
Control commands:
/goalwith no argument—show the current status/goal clear(orstop,off,reset,none,cancel)—clear the goal
According to Anthropic, the evaluator’s cost is “usually negligible compared with the cost of the main turn.” Haiku evaluates the criterion and conversation text and does not call tools, so the check is cheap; the expensive part is the main model’s turns.
How Do You Set Up /goal in Codex CLI?
Key takeaways
Codex CLI 0.128.0 added /goal on April 30, 2026, as an experimental feature. On May 21, the mode became stable in release 26.519 / npm 0.133.0. It works through two prompt templates—continuation.md (“continue”) and budget_limit.md (“stop”). The goal is tied to the thread and survives restarts.
The command looks the same as in Claude:
codex
> /goal all vitest tests pass and there are no eslint errors
Codex offers more goal controls:
| Command | What it does |
|---|---|
/goal condition | set a goal |
/goal | view status |
/goal pause | pause |
/goal resume | resume |
/goal edit | change the condition (with GA) |
/goal clear | clear the goal |
The main difference from Claude is that Codex itself checks whether it is “done,” rather than a separate model. After each turn, Codex automatically inserts the continuation.md template from the openai/codex repository into the context. A literal translation:
“Continue working toward the active thread goal. Do not repeat work already done. Choose the next concrete action toward the goal. Mark the goal achieved only when an audit shows that the goal has actually been met and no required work remains.”
When the tokens approach their limit, a second template—budget_limit.md—is inserted:
“The goal has reached its token limit. Do not start substantial new work. Wrap up this turn as soon as possible: summarize useful progress, identify remaining work and blockers, and leave the user with a clear next step.”
The logic is the same: “do not lie about what you did.” Continuation requires continuing only if the goal has genuinely not been met. Budget_limit requires stopping, but honestly describing what remains.
Unlike Claude, Codex ties the goal to the thread, not the session. For example, you can close the terminal and open it again in the morning, and /goal resume picks up the same goal with the same facts in memory. This is useful for runs you split into chunks according to your own schedule.
How Does /goal in Claude Code Differ from /goal in Codex?
Key takeaways
Claude separates the writer and the judge: the main model writes code, and a separate small model judges. Codex is one agent that checks its own work—it reminds itself, “do not lie about what you did.” The architectures differ, but the risk of looping is the same.
This is the most common gap in comparisons, so let’s look at it in detail.
| Aspect | Claude Code /goal | Codex /goal |
|---|---|---|
| Release | v2.1.139, May 11, 2026 | v0.128.0, April 30, 2026 (experimental) → v0.133.0 / 26.519, May 21, 2026 (stable) |
| Goal scope | Session | Thread (survives restarts) |
| Controls | set, clear (+ aliases) | set, view, pause, resume, edit, clear |
| Who checks whether it is “done” | Separate model (Haiku by default) | The same agent, through an inserted prompt |
| Evaluator’s access to files | No; it judges only from conversation text | Yes; it can inspect files, tests, and logs |
| Budget | In the condition text: “or stop after 20 turns” | Built-in token limit + automatic insertion of budget_limit.md |
| Hard spending cap | None; subscription limit only | None; subscription limit only |
| Condition length | Up to 4,000 characters | Not specified |
| Where it works | Interactive mode, -p, desktop app, Remote Control | App, IDE extension, CLI, ACP clients |
The conceptual difference is that Claude treats the loop as a quality contract (an external evaluator), while Codex treats it as an execution mechanism (the agent manages itself).
In practice, this means: if you want the “done” criterion to be impartial, choose Claude. If you want the agent to be able to check files and logs while evaluating, choose Codex.
Read more about the tools themselves in the Codex vs Claude Code guide.
Real Example: Migrating from Pydantic v1 to v2 in 31 Hours
Key takeaways
Codex /goal completed the migration of 14,000 lines of an internal service from Pydantic v1 to v2 in 31 hours of real time, split across four sessions. The cost was approximately $44 on gpt-5.3-codex.
The task was set as follows: “migrate from Pydantic v1 to v2, all pytest tests must pass, and mypy strict must report zero errors.”
What happened:
- Session 1 (8 hours)—Codex analyzed the imports, rewrote
BaseModeldeclarations, and set up mypy - Session 2 (10 hours)—rewrote validators and broke about 200 tests
- Session 3 (7 hours)—fixed the tests and found circular dependencies
- Session 4 (6 hours)—resolved the remaining mypy errors and regressions
Token cost:
“Total time on the clock: about 31 hours across four sessions. Total Codex token cost at the gpt-5.3-codex rates: about $44.”
The price is dominated by gpt-5.3-codex output tokens at a rate of $14 per million. That means 31 hours of autonomous work costs about as much as weeks of a ChatGPT Plus subscription.
What the agent did not do on its own:
- It did not write migration documentation for the team (Codex did not understand that this was part of the “migration”)
- It did not update configuration files for publishing with the new version of Pydantic
- It missed one production regression, which was caught only a day later
In other words, /goal did 95% of the work; the remaining 5% still has to be done by hand. That is normal for the current generation, and no reason not to use it.
Which Tasks Fit Long Overnight Runs
Key takeaways
Drivers as a class of tasks are poorly suited to interactive work but fit long-running loops perfectly.
The kinds of tasks where this approach offers the biggest gains:
- Low-level work where an iteration and check take minutes (compilation, running tests)
- Migrations with clear formal criteria (types, tests, lint)
- Benchmarks and optimizations with measurable results
- Documentation and changelogs with a clear structure
Claude /goal does the same just as well, but Codex is more often chosen for drivers because it checks files and logs itself rather than relying on an external judge.
How Much Does It Cost, and How Do You Avoid Burning Through Tokens Overnight?
Key takeaways
/goal has no hard upper spending limit—only the limits of your plan. A real hour of Codex costs about $1.50–$3 on gpt-5.3-codex. Claude costs more to run and less to evaluate. The only safeguard is to write “or stop after N turns” in the condition itself.
Figures from public accounts:
| Run | Duration | Tokens | Cost |
|---|---|---|---|
| OpenAI design tool demo | 25 hours | 13M | (internal run) |
| Pydantic v1→v2 | 31 hours, 4 sessions | ~3.1M output | ~$44 |
| Voice interview system | 6 hours 44 minutes total (41 minutes compute) | 6.8 million input, 94% cached | - |
| Font smoke test | 5 minutes | 188,832 | less than 5% of weekly quota |
The main thing to understand: neither Claude Code nor Codex provides a hard “stop spending at $N” limit. There are three safeguards:
- Subscription limits—Pro, Max, or Enterprise. On Anthropic’s Max plan ($100/month), a 14-hour overnight run fits within the weekly quota with room to spare
- Text limit in the condition—write “or stop after 20 turns” directly in
/goal. The Claude judge will read it and close the goal - Token limit in Codex—built-in mechanism that inserts
budget_limit.mdwhen tokens run out
What runs up the bill overnight:
- A vague criterion like “make it more convenient”—the agent will never stop, because the evaluator does not know what “better” means
- Access to external APIs without stubs—each retry costs tokens
- Long context—after 6.7M tokens, context compaction kicks in and some memory is lost
Read more about saving costs in the guides where Claude Code tokens go and how not to burn through your limits.
When NOT to Run /goal: 5 Situations
Key takeaways
Vague criteria like “make it look nice,” one-line edits, production databases with user data, security-critical changes, and tasks with unclear external dependencies. In all five situations, the agent will either get stuck in a loop or burn tokens for nothing.
OpenAI’s documentation explicitly says what NOT to do:
- One-line edits—running
/goalto rename a variable costs more than doing it by hand - Vague goals—“improve performance,” “make the code cleaner,” “make it more convenient.” The evaluator has no criterion, so the agent will spin forever
- Production databases with user data—the agent could break a migration, and restoring from a backup costs more than any savings
- Security changes—authentication, encryption, payment processing. A person needs to review every commit here
- External APIs without stubs—every network failure costs tokens and is outside your control
What Should You Do If the Agent Gets Stuck?
Key takeaways
A sign of a loop is that the agent edits the same place for 3–4 turns and then reverts. Interrupt it with Ctrl+C, check the log, then either make the criterion stricter or narrow the task to one piece. In Claude, /goal clear helps; in Codex, use /goal pause and edit the condition.
How to spot a loop quickly:
- The agent touches the same files for 3+ turns and returns them to their previous state
- Repeated errors appear in the log, errors it has already responded to
- The condition looks met to you, but the agent says “not met”
- Token use per turn is rising, but there is no progress in the code
What to do next:
- In Claude Code:
/goal clear, then make the condition more specific - In Codex:
/goal pause, inspect the current thread, edit the condition with/goal edit, then/goal resume - In both: check that the criterion is actually verifiable (a command returns exit 0 or produces specific output)
Often the cause of the loop is the task itself, not the agent. The condition “all tests pass” assumes that the tests can pass in the first place. If there is a deep architectural problem in the code, the agent will keep circling around the symptom.
“Done” Criteria: Task Discipline for /goal
Key takeaways
A good criterion is a command that returns exit 0 or specific output. “All tests passed” works. “The code is cleaner” does not. It is best to combine a formal check with a measurable metric—for example, tests plus minimum coverage.
OpenAI states this rule plainly in its official Codex Cookbook:
A goal is not considered complete just because the model thinks it is. A goal is complete only when the result has been checked against files, tests, logs, benchmarks, or other concrete artifacts.
Criterion templates that actually work:
| Criterion type | How to phrase it |
|---|---|
| Tests | “pytest tests/ returns exit 0 and coverage is at least 80%” |
| Types | “mypy strict reports zero errors on src/” |
| Lint | “eslint . returns exit 0 on all changed files” |
| Build | “npm run build completes successfully, with no TypeScript errors” |
| Benchmark | “k6 run perf test shows p95 below 200 ms” |
| Diff | “git diff shows changes only in files X, Y, Z” |
| Combo | “pytest is green AND mypy strict reports zero errors AND ruff check passes” |
The Combo row uses a combination: tests plus mypy plus lint. If even one check is still red, the goal is not closed. The evaluator has no chance to cheat.
Anti-patterns:
- “The code is better”
- “Usability has improved”
- “Performance has improved”
- “The documentation is complete”
The difference between “works” and “does not work” is verifiability. If a criterion cannot be checked with a command, it cannot be checked at all. This is also what OpenAI means by “long-horizon coherence”: an agent can think for a long time, but it cannot decide for itself what counts as “good enough.”
You can test the idea of “one prompt—one result” on a real project: set /goal, formulate a criterion, run it, and analyze what went wrong.
Sources
Get to know Ailoot.
More details
Questions about How to Run Claude Code and Codex Overnight via /goal in 2026: 14-Hour Autonomous Mode
What makes a useful /goal completion criterion?
Use a checkable result: name the test, type check, build, or benchmark and its required outcome. Combine the required checks explicitly and include the allowed file scope; “make it better” gives the agent no measurable stopping point.
What should I do when the agent repeats the same failed edits?
Interrupt the run and inspect the log. If it keeps touching and reverting the same files, narrow the task or make the criterion more specific; verify that the required checks can actually pass before resuming.