10uGet early access
10u / claude-code-loop

Claude Code loop guide: /loop, the Ralph loop, /goal and routines

There are four ways to put Claude Code in a loop, and they answer different questions. /loop re-runs a prompt on a timer while your session is open, such as /loop 5m check the deploy. The Ralph loop, from Anthropic's ralph-loop plugin, feeds Claude the same prompt again every time it tries to stop, until it prints a completion phrase. /goal keeps Claude taking turns until a condition you set is met. And cloud scheduled tasks, which Anthropic used to call routines, run on Anthropic's machines on a schedule, from an API call or on GitHub events, with your computer off.

Claude Code loop: /loop 5m checking a deploy in one terminal and a Ralph loop re-running the same prompt until tests pass in another
Claude Code loop: /loop 5m checking a deploy in one terminal and a Ralph loop re-running the same prompt until tests pass in another

Which Claude Code loop should you use?

LoopThe next run starts whenIt stops whenBest for
/loopA time interval passesYou cancel it, it expires after 7 days, or Claude ends a self-paced loopPolling a deploy, babysitting a pull request
Ralph loopClaude tries to stopClaude prints your completion phrase, or the iteration limit is hitGrinding a well-defined task until tests pass
/goalThe previous turn finishesA model confirms your condition is met, or judges it impossibleMigrations and backlogs with a checkable end state
Cloud scheduled tasks (routines)A schedule, an API call or a GitHub eventYou turn the task offNightly or weekly jobs that must run without your machine

Source: Keep Claude working toward a goal, Claude Code docs

Run a prompt on repeat with /loop

/loop is a bundled skill that re-runs a prompt while the session stays open. Both the interval and the prompt are optional, and what you give it decides how it behaves:

You typeWhat happens
/loop 5m check the deployYour prompt runs on a fixed schedule
/loop check the deployYour prompt runs at an interval Claude picks each time
/loopThe built-in maintenance prompt runs, or your loop.md if you have one

Intervals can lead the prompt (30m) or trail it (every 2 hours), in s, m, h or d. Claude turns the interval into a cron schedule, so seconds round up to a minute, and odd intervals like 7m or 90m round to the nearest clean step, which Claude tells you. You can loop a skill too, such as /loop 20m /review-pr 1234.

/loop 5m check if the deployment finished and tell me what happened/loop check whether CI passed and address any review comments/loop 15m

Source: Run prompts on a schedule, Claude Code docs

Let Claude choose the interval

Leave the interval out and Claude picks a delay between one minute and one hour after each run, based on what it saw: short waits while a build is finishing or a pull request is busy, longer waits when nothing is pending. Claude can also end a self-paced loop on its own once the task is done.

The built-in maintenance loop and loop.md

A bare /loop works through three things each time: continue any unfinished work from the conversation, tend to the current branch's pull request (review comments, failed CI runs, merge conflicts), and run cleanup passes such as bug hunts or simplification when nothing else is pending. Every run still goes through your permission checks before it pushes or deletes anything.

To replace that default with your own, write a loop.md file in .claude/loop.md for one project or ~/.claude/loop.md for all of them. Write it as if you were typing the prompt. Edits take effect on the next run, and anything past 25,000 bytes is cut off.

Check the `release/next` PR. If CI is red, pull the failing job log,
diagnose, and push a minimal fix. If new review comments have arrived,
address each one and resolve the thread. If everything is green and
quiet, say so in one line.

Source: Run prompts on a schedule, Claude Code docs

Stop a loop

For a self-paced loop, press Esc on an empty prompt while it waits, or Ctrl+C while Claude is idle. For a fixed-interval loop such as /loop 5m, ask Claude to cancel it, for example "cancel the deploy check loop"; Esc and Ctrl+C do not stop those. Ask "what scheduled tasks do I have?" to list them. Under the hood Claude uses the CronCreate, CronList and CronDelete tools, and a session can hold up to 50 tasks.

How /loop timing works

  • Tasks fire between your turns, never mid-response, in your local time zone.
  • Runs are spread out to avoid everyone calling at once: hourly or daily tasks start up to 30 minutes late, and /loop 5m runs every 4 minutes 45 seconds.
  • Recurring tasks expire 7 days after you create them, firing one last time first.
  • Nothing fires once you close the terminal, and missed runs are not caught up; a busy session fires once when it is free.
  • Set CLAUDE_CODE_DISABLE_CRON=1 to turn the scheduler off entirely.

For a one-off, just say it: "remind me at 3pm to push the release branch" or "in 45 minutes, check whether the integration tests passed". Claude schedules a single run that deletes itself.

Source: Run prompts on a schedule, Claude Code docs

The Ralph Wiggum loop in Claude Code

The Ralph loop is a technique named after the Simpsons character, for persistent iteration despite setbacks. As Geoffrey Huntley, who coined it, puts it: "Ralph is a Bash loop", a simple while-true that keeps feeding an AI agent the same prompt so it improves its own work. Anthropic's official ralph-loop plugin does this inside your session with a Stop hook: when Claude tries to finish, the hook blocks the exit and feeds the same prompt back. The prompt never changes, but Claude's earlier work stays in the files and git history, so each pass sees what the last one did.

/plugin install ralph-loop@claude-plugins-official

Then start a loop with a clear finish line:

/ralph-loop "Build a REST API for todos. Requirements: CRUD operations, input validation, tests. Output <promise>COMPLETE</promise> when done." --completion-promise "COMPLETE" --max-iterations 50

--completion-promise is the exact phrase that ends the loop, and --max-iterations stops it after that many passes (it is unlimited by default). Run /cancel-ralph to stop an active loop.

Source: Ralph Loop plugin, Anthropic official plugins

Writing a good Ralph loop prompt

  • Clear completion criteria: list what done means, such as all endpoints working, tests passing and a README, then the promise line.
  • Incremental goals: break big work into phases, each with tests, instead of "build a complete e-commerce platform".
  • Self-correction: tell Claude to write failing tests, implement, run them, and fix until green.
  • An escape hatch: always set --max-iterations, and say what to do if stuck, such as documenting what is blocking progress after 15 passes.

Because the completion phrase is an exact text match, you cannot use it for two outcomes such as SUCCESS and BLOCKED, so the iteration limit is your main safety net. The plugin's README says Ralph suits well-defined tasks with automatic checks like tests and linters, and greenfield work you can walk away from. It does not suit tasks needing human judgement or design decisions, one-shot jobs, unclear success criteria, or production debugging.

On Windows, the plugin's Stop hook needs Git for Windows. If bash resolves to WSL and the hook fails, point the plugin's hooks.json at C:/Program Files/Git/bin/bash.exe, as the README describes.

Source: Ralph Loop plugin, Anthropic official plugins

Loop until it is done with /goal

/goal is Claude Code's built-in way to keep working toward a condition. After each turn, a separate model checks whether the condition holds; if not, Claude starts another turn instead of handing back to you. It stops when the condition is met, when the model judges it impossible, or when you clear it.

/goal all tests in test/auth pass and the lint step is clean

Setting a goal starts work straight away, and a goal active indicator shows how long it has run. Run /goal on its own to see the condition, turns so far, token spend and the evaluator's latest reason, and /goal clear to stop. A goal does not change your permission mode, so run it in auto mode if you want it unattended. One goal can be active per session, and it is restored when you resume.

Write the condition as something Claude's own output can prove, since the evaluator reads the conversation rather than running commands: one measurable end state, a stated check such as "npm test exits 0", and any constraints, such as "no other test file is modified". Add "or stop after 20 turns" to cap it. Conditions can be up to 4,000 characters.

Source: Keep Claude working toward a goal, Claude Code docs

/goal or the Ralph loop?

Both keep Claude going after each turn. The Ralph loop repeats a fixed prompt and stops on an exact phrase or an iteration count. /goal is built in, needs no plugin, and uses a model to judge a plain-language condition, reporting progress each turn. A Stop hook in your settings is the third option, for when your own script should decide.

Source: Keep Claude working toward a goal, Claude Code docs

Claude Code routines: loops that run in the cloud

Cloud scheduled tasks, formerly called routines, are saved Claude Code setups (a prompt, one or more repositories and some connectors) that run on Anthropic's infrastructure, so they keep working with your laptop closed. Each can have one or more triggers: a schedule (hourly, nightly, weekly or once), an API call to its own endpoint, or a GitHub event such as a pull request or release. They are a research preview on Pro, Max, Ultra, Team and Enterprise plans.

/schedule daily PR review at 9am/schedule in 2 weeks, open a cleanup PR that removes the feature flag/schedule list

Create them at claude.ai/code/routines, in the desktop app, or with /schedule in the CLI (/routines still works as another name). Each run clones the repositories fresh, works on claude/ branches, and opens as a full session you can review. Anthropic's examples include nightly backlog labelling, alert triage from your monitoring tool, a custom pull request review checklist, deploy verification and weekly docs-drift checks.

LimitValue
Shortest schedule1 hour
Scheduled runs per account100 an hour
Run now and API fires per task30 an hour
UsageCounts against your subscription like an interactive session

Source: Automate work with scheduled tasks, Claude Code docs

/loop, desktop or cloud?

CloudDesktop app/loop
Runs onAnthropic's cloudYour machineYour machine
Machine must be onNoYesYes
Session must be openNoNoYes
Local filesNo, a fresh cloneYesYes
Shortest interval1 hour1 minute when Claude sets it1 minute

Anthropic's rule of thumb: cloud tasks for work that must run reliably without your machine, desktop tasks when you need local files and tools, and /loop for quick polling during a session.

Source: Run prompts on a schedule, Claude Code docs

Watch every loop at once

Loops are how one person ends up with several Claude Code sessions working at the same time, and the hard part becomes noticing which one has finished or needs you. 10u is an AI coding agent dashboard that shows every Claude Code and Codex session side by side, each in its real terminal, marked Needs you, Working, Waiting or Parked. They do the building. You decide what gets built.

10u: every sample agent side by side under its goal, with the ones waiting on you marked
10u: every sample agent side by side under its goal, with the ones waiting on you marked

Questions people ask

How do I make Claude Code loop?
Type /loop with an interval and a prompt, such as /loop 5m check the deploy. Leave out the interval and Claude picks one; type /loop alone for the built-in maintenance loop.
What is the Ralph Wiggum loop in Claude Code?
A technique that feeds Claude the same prompt every time it tries to stop, so it keeps improving its work. Anthropic's ralph-loop plugin runs it with /ralph-loop and a completion phrase.
How do I stop a Claude Code loop?
Press Esc on an empty prompt for a self-paced /loop, ask Claude to cancel a fixed-interval one, run /cancel-ralph for a Ralph loop, or /goal clear for a goal.
What are Claude Code routines?
The earlier name for cloud scheduled tasks: saved prompts that run on Anthropic's cloud on a schedule, from an API call or on GitHub events. Create them with /schedule.
How long does /loop run?
Recurring tasks expire after 7 days, and they only fire while the session is open and idle.
Is /goal the same as a Ralph loop?
Similar idea. /goal is built in and uses a model to judge a plain-language condition; the Ralph loop is a plugin that repeats a fixed prompt until an exact phrase appears.

10u is in early access. Leave your email and we will let you in as places open.