# Claude Code /goal and /loop: Full Guide

> Learn how /goal and /loop make Claude Code work on its own, when to use each one, how to combine them, and five more commands worth knowing about.

By Jonathan Ben Haim. Updated 2026-11-29. Source: https://jonathanai.io/blog/claude-code-goal-and-loop-guide

Claude Code is no longer just a coding helper. A few new commands let it run on its own, keep track of whether it is finished, and stop only when a separate judge model confirms the goal is met. In this guide, I walk through the five most useful commands, and I spend extra time on the pair people are talking about most: /goal with /loop.

**In short:** /goal sets an end condition. Claude Code keeps working turn after turn until a judge model confirms the condition is met, decides it is impossible, or you run /goal clear. /loop runs a prompt again and again at a set interval. Use /goal for a task with a measurable end, and /loop for a recurring task.

## Key takeaways

- /goal sets an end condition, and a separate judge model checks it after each turn.
- /loop runs the same prompt on an interval you set, and scheduled tasks expire after 7 days.
- You can run /goal and /loop together in the same session, with no second terminal needed.
- A session can have up to 50 scheduled tasks, and a goal condition can be up to 4,000 characters.
- Use /loop alone when Claude can verify success itself, such as with passing tests or a build that passes. Use /goal when a false "I'm done" is costly.
- The official recommendation is /effort high for everyday work, and ultracode only for very large tasks.

## What is the difference between /goal and /loop?

/goal is for a task with a clear finish line, and /loop is for a task you want repeated. The table below shows how they differ.

| | /goal | /loop |
|---|---|---|
| What it does | Sets an end condition you can check. A separate judge model decides after each turn whether it has been met. | Runs the same prompt again and again on an interval you set. |
| When to use it | When a false "I'm done" is costly and you want a separate check on every turn. | When Claude can verify success itself (passing tests, a passing build), for polling CI, and for background monitoring. |
| When it ends | When the judge confirms the condition is met. | When you cancel it or the work is finished. |
| Example | `/goal "all tests in test/auth pass and git status is clean"` | `/loop 3m run npm run build and report any TypeScript errors` |

You can run both together in the same session. This pattern is covered in section 3 below.

## What is /goal and how does it work?

/goal lets you define what "done" means instead of telling Claude what to do. You give Claude a finish line, which is a condition you can check.

```
/goal "all tests in test/auth pass and git status is clean"
```

Here is what happens behind the scenes:

1. Claude works one turn.
2. A separate judge model, called the evaluator, reads the state and decides one thing: have we arrived or not?
3. If not, Claude takes the reason as its next instruction and keeps going on its own.
4. The session stops only when the judge says yes.

While the judge is checking, you will see a "Concocting" indicator at the bottom of the terminal.

How far can it go? A developer on Reddit ran an autonomous /goal session for 9 hours. It made 45 commits, processed 4.16 million rows of data in 5 passes, and ran 41 subagent sessions, chaining 4 goal commands together.

The golden rule for writing a goal is to write it like a contract, not like a process. Compare these examples:

| Weak (process) | Strong (final state you can check) |
|---|---|
| "Improve the code" | "No function is longer than 40 lines, and every function has JSDoc" |
| "Fix the performance" | "Lighthouse score is 90 or higher" |
| "Clean up errors" | "ESLint runs on /src with 0 errors and 0 warnings" |

You can also limit attempts:

```
/goal "..." --max-tries 8
```

Do not use /goal for exploratory refactors where "good enough" is subjective. You will end up arguing with the judge and burning tokens.

## How do you write a good condition for /goal?

Write a condition that Claude's output can prove. According to Anthropic's official Claude Code docs, the judge model does not run commands or read files itself. It judges only from what Claude has shown in the conversation. A condition that holds over many turns usually has three parts:

1. **One final state you can measure:** a test result, a build exit code, a number of files, or an empty task queue.
2. **A stated check:** how Claude will prove it got there, such as "npm test exits with code 0" or "git status is clean."
3. **Constraints that must not change:** what has to stay the same along the way, such as "no other test files are modified."

You can also add a cap. Put something like `or stop after 20 turns` inside the condition, and Claude reports its progress against the limit each turn. The condition itself can be up to 4,000 characters.

Here is a complete example:

```
/goal all tests in test/auth pass and npm test exits with code 0, without modifying any other test files, or stop after 20 turns
```

To check status, run `/goal` with no arguments. It shows the condition, how long it has been running, how many turns have been checked, how many tokens have been used, and the judge model's last reason.

To stop it before it is reached, run:

```
/goal clear
```

You can also use stop, off, reset, none, or cancel instead of clear. The /clear command, which opens a new conversation, also removes the goal.

For non-interactive runs, /goal also works with `claude -p`. The loop then runs to the end in a single launch:

```
claude -p "/goal CHANGELOG.md has an entry for every PR merged this week"
```

/goal does not change your permission mode. For turns to run without supervision, you start it in auto mode. In manual mode, Claude still asks for approval before commands you have not pre-approved in your settings. If you let an agent run on your computer by itself, it is worth isolating it in [Docker Sandboxes](/blog/docker-sandboxes-run-claude-code-safely).

If a goal hits a [usage limit](/blog/claude-code-pricing), the docs say it is paused, not deleted. If you do not want to wait for the reset, you can [keep working with a local model](/blog/claude-code-limit-keep-working-free) through claude-code-local.

## What is /loop and how do the durability levels work?

/loop runs a prompt again and again at an interval you set.

```
/loop 3m run npm run build and report any TypeScript errors
```

Here is what you should know:

- You can use a fixed interval, or let Claude choose the timing dynamically. It waits briefly when the build is active and longer when there is nothing to do.
- A session can have up to 50 scheduled tasks. Tasks expire after 7 days.
- Common uses include polling CI, babysitting a PR, periodic cleanup, and [background monitoring](/blog/always-on-ai-agents-guide) while you work.

It helps to understand the durability ladder. It shows where a loop runs and what happens when you close things:

| Level | Where it runs | What happens when you close it |
|---|---|---|
| /loop | In the local session | It stops when the session closes, unless you move it to a background session (backgrounding), which keeps running without a terminal. |
| Scheduled tasks in the desktop app | Locally, as long as the app is open | It stops when the app closes. |
| /schedule for Routines | In Anthropic's cloud | It keeps running even when your laptop is closed. |

Tip: `--resume` or `--continue` brings back tasks that have not expired. The environment variable `CLAUDE_CODE_DISABLE_CRON=1` turns off the whole scheduling system.

## Can you run /goal and /loop in the same session?

Yes. The basic pattern is to run both in one session, and you do not need two terminals. This is where the real value shows up.

```
/goal all files in /src pass ESLint with zero errors and zero warnings
/loop run ESLint on /src, find the first file with errors, fix it, run again on that file, and repeat until it is clean
```

This gives you an assess, act, verify machine:

- The goal sets the final target that Claude checks against at every step.
- The loop provides the engine that keeps running.
- The loop moves file by file, cleans up the whole codebase, and exits on its own when the judge confirms the target is met.

The difference between the two comes down to what you hand over and when it ends:

| Command | What you hand over | When it ends |
|---|---|---|
| /loop | The trigger (a time interval) | When you cancel it or the work is finished |
| /goal | The end condition | When the judge confirms the condition is met |

When would you use two terminals? There is an advanced pattern called "fix + watch." One terminal runs /goal to fix TypeScript errors. A second terminal runs `/loop 3m` to run the build and look for new errors the first loop may have created. One does the work, and the other acts as a safety net. It is optional, and one session is enough for most tasks.

A rule of thumb: use /loop alone when Claude can verify success reliably itself, such as with passing tests or a passing build. Use /goal when a false "I'm done" is costly, because a separate model verifies every turn.

## What is ultracode and when should you use it?

Ultracode works in two ways, depending on how you use it.

- **As a keyword in a prompt:** Write `ultracode` in your message. Claude then writes a dynamic orchestration script in JavaScript that runs in the background and coordinates up to 16 subagents in parallel. Intermediate results are stored in the script's variables, not in the context window. This is what lets it go beyond the limits of a single conversation. Run `/workflows` to see live progress.
- **As a session setting:** `/effort ultracode` combines xhigh reasoning with automatic orchestration for every significant task in the session. It applies to the session only and is not saved.

It is expensive on purpose. The official recommendation is `/effort high` for everyday work. Use ultracode only when you truly need it, such as a full codebase audit, a massive migration, or cross-referenced research. For cross-cutting work, there is also `/batch`, which splits the work into independent units. Each unit gets its own git worktree and its own PR.

Built-in safety guardrails include a limit of 200 subagent sessions and 200 web searches per session. `/clear` resets these counts. Any MCP call that runs longer than 2 minutes moves to the background automatically.

Ultracode coordinates Claude's own subagents. If you want a structured way to work, with planning, TDD, and review before you ship a long loop, there is a skill called Superpowers.

## What does /checkup do?

/checkup audits your Claude Code setup and cleans it up. Boris Cherny, the creator of Claude Code, announced it on July 9.

It does the following:

- Removes unused skills, MCPs, and plugins to save context.
- Finds duplicates between your local CLAUDE.md and the version in your repo.
- Splits a bloated main CLAUDE.md into nested files and skills.
- Turns off slow hooks.
- Updates Claude Code to the latest version.
- Pre-approves read-only commands that you keep approving or rejecting by hand.

Most importantly, it asks you to approve each change before it runs. In recent versions, /checkup has become an alias for an expanded /doctor. Both do the same thing.

Once your setup is clean, it is a good time to add only the skills and MCPs that really help you. For example, [n8n-MCP and n8n-Skills](/blog/n8n-mcp-skills-claude-guide) let Claude build automations, and book-to-skill turns [a technical book into a skill](/blog/turn-technical-book-into-claude-skill).

## What else changed in the last few weeks?

Three more upgrades stand out from the last few weeks:

- **/rewind** can now restore a conversation from before a /clear, not just regular checkpoints.
- **/code-review --fix** does more than review. It applies simplification and optimization suggestions directly to the working
