What's New Intermediate Claude Code 6 min read ·

Claude Code's /goal Command: Set a Finish Line and Walk Away

Claude Code v2.1.139 added /goal — set a stop condition and the agent keeps working across turns until it hits the line. Here's how to write one that actually works.

On May 12, Anthropic shipped Claude Code v2.1.139 with a new top-level command: /goal. It does one thing — sets a completion condition and keeps Claude working turn after turn until that condition is met. No more sitting at the keyboard pressing Enter to nudge the agent through a long task.

Codex users have had a version of this since late 2025. The Claude Code version is tighter, with a real evaluator loop and proper exit signals. Once you set it, you get a live overlay showing elapsed time, turns spent, and tokens burned, and the goal clears automatically when the agent proves it's done.

How /goal Actually Works

You type /goal followed by a stop condition in plain English. Claude starts working immediately — the condition itself acts as the prompt, so you don't need a second message. After each turn, a small fast model reads the conversation and decides whether the condition is satisfied. If yes, the goal clears and control returns to you. If no, Claude takes another turn.

The evaluator only looks at what Claude has surfaced in the chat. It does not run tests independently, read files on its own, or check git state. That detail matters: your stop condition has to be something Claude's own output can prove.

plaintext
/goal all tests in tests/auth pass when I run pytest and the type checker reports zero errors

Writing a Condition That Actually Stops

The most common mistake is writing a goal the agent can fake. "Refactor the user module to be cleaner" has no exit. The agent can do work forever and the evaluator has nothing to grade. "Refactor the user module so each file is under 200 lines and all existing tests pass" gives the evaluator two measurable checks.

Good stop conditions share three traits. One end state: a test pass, a build exit code, an empty queue, a file count under N. One verification step: how Claude has to prove it, like "npm test exits 0" or "git status shows no unstaged changes." One constraint that must hold: anything that should not regress while the agent works.

Pro Tip

Always include the verification step inside the condition. "All tests pass" without saying how the agent should check tests will result in Claude declaring success based on vibes. "All tests pass when npm test is run" forces the agent to actually run the command.

Five Stop Conditions That Work

plaintext
/goal every file in src/ is under 300 lines and the build passes with bun run build returning exit code 0

/goal all 47 issues with label "perf" in the backlog are closed or have a written justification comment

/goal the migration from useUser to useSession is complete, every old call site updated, and grep finds zero remaining uses of useUser

/goal the new /export endpoint is implemented, has a happy-path test that passes, and the openapi.yaml is updated to match

/goal documentation in docs/api/ matches the actual handler signatures and mintlify dev reports no broken links

What /goal Does Not Replace

It's tempting to think of /goal as the end of human oversight, but the loop runs on your tokens and your account. A goal that runs for two hours burns two hours of model calls whether the work is useful or not. Three habits keep this honest.

First, set a turn budget mentally before you start. If the work should take five turns and you're at fifteen, the agent is probably stuck — check in. Second, choose conditions that fail fast when the approach is wrong. A goal tied to a passing test will show its hand quickly if the agent is heading the wrong direction. Third, do not stack goals back to back. Run one, review the diff, then run the next.

Managing an Active Goal

While a goal is running, /goal with no arguments shows the live status: turns spent, tokens spent, elapsed time. /goal clear stops the current goal and gives control back without losing the work done so far. Setting a new /goal while one is active replaces the old one — useful if you realize halfway through that you wrote a bad condition.

plaintext
# Check status of running goal
/goal

# Stop the current goal but keep the conversation
/goal clear

# Replace a bad goal with a better one mid-run
/goal all tests pass AND no console.log calls remain in src/

When /goal Is the Wrong Tool

Three patterns where /goal makes things worse, not better. Exploratory work where you don't know the end state yet — the agent will pick one and grind on it. Tasks where the right answer requires human judgment in the middle, like API design choices or which of two error messages reads better. And anything with no measurable end, like "improve the code quality" or "make this faster" without a specific target.

For those, stay in regular conversational mode. The /goal command was built for the boring, well-defined slog: migrations, cleanup passes, working through a labeled backlog, getting a test suite green. Aim it there.

Key Takeaway

Claude Code's new /goal command runs the agent across multiple turns until your stop condition is met. The condition must be something Claude's output can prove — write measurable end states with explicit verification steps, and the agent will work autonomously until it hits the line.

Frequently Asked Questions

Does /goal work outside interactive mode?

Yes. /goal works in interactive sessions, in non-interactive -p mode, and in Remote Control sessions. The same evaluator logic applies in all three. Headless mode is where /goal probably has the most upside — you can kick off a job and check back in an hour without leaving a terminal open.

What happens if Claude gets stuck in a loop trying to satisfy the goal?

There's no built-in turn cap as of v2.1.139, so a poorly written goal can chew through tokens. The live overlay shows turns and tokens spent — if you see the agent crossing 20+ turns on something that should take 5, /goal clear is the right move. Then either rewrite the condition or hand the task to the agent in regular mode.

Can I use /goal with subagents and the agent view together?

Yes. /goal spawns whatever subagents Claude decides it needs to satisfy the condition, and those show up in the agent view (claude agents) alongside the parent. Token cost adds up across all of them, so if you combine /goal with subagent-heavy work, watch the token counter — it can climb fast.

Personalized for your role

Get Your AI Career Action Plan

Our AI Advisor builds you a personalized AI Readiness Score, skills gap analysis, and 30/60/90 day plan based on your specific role and experience.

Try the AI Advisor →
← Back to AI Coding Hub