The /goal command in Claude Code sets a completion condition, and Claude keeps taking turns without you prompting it until that condition is met. After each turn, a separate evaluator model checks whether the condition holds. As long as it doesnāt, Claude starts another turn instead of handing control back to you. The command has been around since v2.1.139.
/goal doesnāt change your permission mode. To let goal turns run without permission prompts, run it in auto mode. Under the hood, itās a prompt-based Stop hook scoped to the current session.
How do you set a goal with /goal?
/goal all tests in test/auth pass and the lint step is clean
Setting a goal starts a turn right away, with the condition as the directive. A ā /goal active indicator shows how long the goal has been running. A session holds one goal at a time, and a new /goal replaces the current one.
After each turn, Claude Code sends the condition and the conversation so far to your configured small fast model. It returns a verdict with a short reason, which Ctrl+O shows.
| Verdict | What happens |
|---|
| Not yet met | Claude keeps working and uses the reason as guidance for the next turn |
| Met | The goal clears and the transcript records it as achieved |
| Impossible | The goal clears and the transcript records a failed entry with the reason |
How do you write a good condition?
The evaluator doesnāt run commands or read files. It only judges what Claude has surfaced in the conversation, so write a condition that Claudeās own output can demonstrate. āAll tests in test/auth passā works because Claude runs the tests and the result lands in the transcript.
According to the docs, a condition that holds up usually has:
- one measurable end state, such as a test result, a build exit code, or an empty queue;
- a stated check, for example ā
npm test exits 0ā;
- the constraints that matter on the way, such as āno other test file is modifiedā.
The condition can be up to 4,000 characters. To bound how long a goal runs, add a turn or time clause, which the evaluator also judges from the conversation.
/goal npm test exits 0 with no other test file modified, or stop after 20 turns
How do you check on a goal or stop it?
Run /goal with no arguments to see the condition, how long it has run, how many turns were evaluated, the token spend so far, and the evaluatorās latest reason.
/goal clear removes the goal before it resolves and prints Goal cleared: followed by the condition. stop, off, reset, none, and cancel work as aliases, and /clear removes the goal along with the conversation.
When you resume a session with --continue or --resume, Claude Code restores a goal that was still active. It keeps the condition but resets the turn count, the timer, and the token-spend baseline.
What ends a goal?
Apart from the Met and Impossible verdicts, four errors clear the goal because they need you to step in. They are an authentication failure when Claude Code manages its own credentials, an exhausted credit balance, a context overflow that auto-compaction couldnāt clear, and a model that isnāt available. The warning starts with Goal cleared after an unrecoverable error. Fix the cause and run /goal again.
Other errors leave the goal set. Since v2.1.269, in an interactive session, Claude Code retries on its own after a dropped connection or an overloaded server, and pauses the goal after three retries. An API rate limit or a usage limit pauses it right away.
If Claude keeps answering the evaluator for several turns in a row without using a tool, Claude Code stops the loop and hands control back with the goal still set.
When a subagent or a background shell command is still running at the end of a turn, evaluation waits. After 30 minutes, Claude Code asks Claude to check on that work. CLAUDE_CODE_GOAL_CHECKIN_MINUTES changes that interval, and 0 turns off both these check-ins and automatic retries.
Should you use /goal, /loop, or a Stop hook?
| Approach | Next turn starts when | Stops when |
|---|
/goal | The previous turn finishes | A model judges the condition met or impossible, or you run /goal clear |
/loop | A time interval elapses | You stop it, or Claude decides the work is done |
| Stop hook | The previous turn finishes | Your own script or prompt decides |
/goal only applies to the current session. A Stop hook lives in your settings, applies to every session in its scope, and can run a script for deterministic checks. Auto mode approves tool calls within a turn but never starts a new one. The docs describe the two as complementary, since auto mode removes permission prompts and /goal removes the need to nudge Claude between turns.
How much does a goal cost?
Evaluation tokens are billed on your providerās small fast model, and the docs describe them as typically negligible next to main-turn spend. Most of the cost comes from the turns Claude keeps taking. Bound the run in the condition and watch the token spend with /goal.
To evaluate on a different model, set ANTHROPIC_DEFAULT_HAIKU_MODEL, which also changes the haiku alias and the model behind background work.
Where can you use /goal?
/goal works with claude -p, in the desktop app, and through Remote Control. With -p, the loop runs to completion in a single invocation.
claude -p "/goal CHANGELOG.md has an entry for every PR merged this week" --output-format stream-json --verbose
With the default text output, only the final response prints, so a long goal can look stuck, hence stream-json. With no mode set, claude -p starts in Manual and denies calls that need approval, so add --permission-mode auto or --allowedTools.
Because the evaluator is part of the hooks system, /goal follows the same workspace trust rule as hooks. Itās unavailable when disableAllHooks is true or managed settings set allowManagedHooksOnly.
Section 5.6 of module 5, Hooks and automation, shows how to write your own Stop hooks when you want a scripted check or criteria shared across the team. To run Claude with claude -p in a script or in CI, see module 7, Optimization and pro workflow.