The /loop Command: Recurring and Self-Paced Prompts
PL/loop is a Claude Code bundled skill that re-runs a prompt inside an open session: on a fixed interval, at a delay Claude chooses each round, or as a built-in maintenance routine. Cursor ships its own /loop skill; Codex has none and uses app automations instead. A loop is only as trustworthy as the check each iteration runs.
This page is for developers who babysit deploys and pull requests, and for tech leads who set the team’s defaults for unattended work. The deploy takes eight minutes, so you ask “is it done yet?” four times. The PR is in review, so you keep flipping back for CI results and new comments. That is a prompt you would run on repeat if something else ran it for you, and /loop is that something. The catch is that a loop you do not watch has to report evidence, not impressions, or you are back to reading everything it did. If you are new to unattended work, start with the Automate hub, which maps every option this page compares.
What this page covers
Section titled “What this page covers”- A rule for choosing between fixed-interval, self-paced and maintenance mode
- Two copy-paste loop prompts that end every iteration with checkable evidence
- A project
loop.mdthat tends a release branch and stops before it can do damage - How to cap a loop’s token spend and see what each loop cost
- What to use in Codex, and where Cursor’s
/loopdiffers - The failure modes that make a loop fire and do nothing, and how to recover
Which /loop mode fits the job?
Section titled “Which /loop mode fits the job?”Both the interval and the prompt are optional in Claude Code, and what you supply decides the mode. /loop arrived in v2.1.71 (March 2026) and is documented on Anthropic’s scheduled tasks page, checked on 2026-09-26.
| What you type | Example | Mode | Use it when |
|---|---|---|---|
| Interval and prompt | /loop 5m check the deploy | Fixed interval, converted to cron | The event has a known cadence: a deploy, a nightly build, a queue you drain |
| Prompt only | /loop check the deploy | Self-paced: Claude picks 1 minute to 1 hour after each round | Activity comes in bursts, such as a PR in review |
| Interval only, or nothing | /loop or /loop 15m | Built-in maintenance prompt, or your loop.md | You want a standing “keep this branch healthy” routine |
Start self-paced unless you have a reason not to. Claude waits briefly while a build is finishing and longer once things go quiet, so you pay for fewer empty iterations than on a fixed one-minute cadence.
How to run a fixed-interval loop
Section titled “How to run a fixed-interval loop”Type the interval and the prompt in the Claude Code prompt:
/loop 5m check if the deployment finished and tell me what happenedClaude converts the interval to a cron expression, schedules the job, and confirms the cadence and an 8-character job ID. The interval can lead as a bare token (30m) or trail as a clause (every 2 hours). Units are s, m, h and d. Seconds round up to a whole minute, because cron cannot go finer, and intervals such as 7m or 90m round to the nearest clean cron step. Claude tells you what it picked.
Three details decide whether a fixed loop behaves the way you expect:
- Only model-invocable skills run on a fire.
/loop 20m /review-pr 1234re-runs that skill each round. Built-in commands (/model,/clear), skills markeddisable-model-invocation: true(including the bundled/verify), skills hidden byskillOverridesor aSkilldeny rule, and MCP prompts such as/mcp__github__list_prsarrive as plain text and do nothing. - Fire times carry a fixed jitter. The scheduler adds a fixed offset derived from the task ID: recurring tasks fire up to 30 minutes after the scheduled time, or up to half the interval for anything more frequent than hourly. One-shot tasks set for
:00or:30fire up to 90 seconds early. For a one-shot reminder where the minute matters, ask for a time off:00/:30, such as3 9 * * *instead of0 9 * * *; recurring offsets still apply. Self-paced loops have no jitter. - Times are local, and a session holds at most 50 scheduled tasks.
How Claude paces a self-paced loop
Section titled “How Claude paces a self-paced loop”Leave out the interval and Claude chooses the delay after every iteration, then prints the delay and the reason:
/loop check whether CI passed and address any review commentsWhen the Monitor tool is available in the session, Claude may use it instead of re-running the prompt: Monitor runs a background script and streams each output line back, which is often faster to react and cheaper than polling. If the thing you are waiting for can push a notification, polling is the wrong tool altogether; Claude Code’s channels let CI push a failure into the session directly.
A bare /loop runs the built-in maintenance prompt at a self-paced interval. Each round it continues unfinished work from the conversation, then tends the current branch’s PR (review comments, failed CI, merge conflicts), then runs cleanup passes when nothing else is pending. It does not start new initiatives, and irreversible actions such as pushing or deleting proceed only when they continue something the transcript already authorized.
On Amazon Bedrock, Claude Platform on AWS, Google Cloud’s Agent Platform and Microsoft Foundry, or with feature-flag fetching turned off, self-paced mode and the maintenance prompt need v2.1.248 or later.
How do you trust a loop you are not watching?
Section titled “How do you trust a loop you are not watching?”A loop’s output is a stream of claims: “CI is green”, “comment addressed”, “deploy healthy”. You verify it the way you verify any agent work, by making each iteration produce evidence a machine already checked. Four rules make that true:
- Name the oracle. Every loop prompt says which command or status decides success:
gh pr checks, the deploy’s health endpoint,npm test. “Check if it looks OK” gives Claude nothing to fail against. - End every iteration with one evidence line. The command it ran, the result, and a link: a CI run URL, a commit SHA, a health-check status code. You skim the lines, not the transcript.
- Write the stop condition and the attempt cap into the prompt. A self-paced loop can end itself when the work is done (Claude calls
ScheduleWakeupwithstop: true). An iteration that fails the same way twice should stop and report, not push a third guess. - Keep the merge human. A loop may push fixes to a branch; a person approves the pull request using the evidence-first review triage. The loop never merges and never deploys.
Then check what the loop cost. Since v2.1.243, /usage shows a Loops breakdown: run count, total tokens, tokens per run and last run for each loop. A loop whose tokens per run keep climbing is re-reading too much or retrying; tighten the prompt or lengthen the interval.
Replace example.com/healthz with your service’s health endpoint. The prompt is read-only on purpose: the loop reports, and you decide.
Replace the maintenance routine with loop.md
Section titled “Replace the maintenance routine with loop.md”A loop.md file replaces the built-in maintenance prompt for a bare /loop. Claude Code reads .claude/loop.md in the project first and falls back to ~/.claude/loop.md. It is one default prompt, not a list of tasks, and Claude Code ignores it whenever you type a prompt after /loop. Edits take effect on the next iteration, so you can tighten it while the loop runs. Content beyond 25,000 bytes is truncated.
Commit the project file so the whole team’s bare /loop does the same, bounded thing. A tech lead reviews this file like any other policy: it runs unattended, and “push a fix” in it means a push every time the condition is met.
How to stop, resume and background a loop
Section titled “How to stop, resume and background a loop”-
Stop a waiting self-paced loop with
Esc. That clears the pending wakeup. It does not touch cron tasks. -
Cancel fixed-interval loops and scheduled tasks by ID. A fixed-interval
/loopis a cron task, like a task you scheduled by asking Claude directly (“every morning at 9, check…”), soEscdoes not stop it. Ask Claude to cancel it by description (“cancel the deploy check job”) or by ID (“cancel job a1b2c3d4”); Claude calls theCronDeletetool with that ID, and asking “list my scheduled tasks” makes it callCronListto show the IDs. Left alone, a recurring task runs until it expires after seven days. -
Let a self-paced loop end itself. When the prompt’s stop condition is met, Claude cancels its own wakeup. If an iteration neither reschedules nor stops, Claude Code schedules one fallback wakeup about 20 minutes later and ends the loop if that iteration does not reschedule either.
-
Re-start self-paced loops after a resume.
claude --resumeandclaude --continuerestore unexpired fixed-interval tasks, but a self-paced/loopis not restored. Run/loopagain. -
Background the session before you close the terminal. Tasks fire only while Claude Code runs and is idle. Backgrounding the session (
/background) carries its/looptasks to a background session that keeps firing without a terminal. -
Plan around the seven-day expiry. A recurring task fires one last time seven days after creation, then deletes itself. Self-paced loops have no jitter but are subject to the same seven-day expiry. For anything longer, use a durable scheduler (next section).
To switch the scheduler off entirely, for example on a shared machine, set CLAUDE_CODE_DISABLE_CRON=1. The cron tools and /loop become unavailable and scheduled tasks stop firing.
/loop in Claude Code, Codex and Cursor
Section titled “/loop in Claude Code, Codex and Cursor”Native, as described on this page. /loop is the in-session option for quick polling: it needs your machine on and the session open, and it inherits the session’s MCP servers and permission mode. When a fire needs an approval, it waits for you like any other turn. For work that must outlive the session, use Routines (research preview; Anthropic-managed cloud, 1-hour minimum interval, no permission prompts during a run), Desktop scheduled tasks (your machine, 1-minute minimum), or a GitHub Actions schedule trigger.
Codex has no /loop command: it is absent from OpenAI’s developer-commands reference, from the slash-command enum of Codex 0.162.1 and from that binary’s strings (checked 2026-10-12). Two features cover the need:
- Automations in the Codex desktop app schedule recurring tasks in the background. OpenAI’s Codex surface map (checked 2026-09-26) describes them as “scheduled checks, reminders, monitors, or follow-ups; use an existing-thread heartbeat when continuity matters”. A thread automation is the closest match to a Claude Code loop, because each run lands in the same conversation. The Codex automations guide covers setup, sandbox choice and testing a prompt before you schedule it.
/goalruns until a condition holds. That is a condition-based loop, not a scheduled one.
The copy-paste prompts above work in a Codex automation once you drop the /loop prefix, replace the CronDelete and “stop the loop” lines with “report and end the run” (the automation’s schedule supplies the cadence), and choose a sandbox that allows network access (gh and curl need it).
Cursor added a /loop bundled skill in 3.5 (2026-05-20). Cursor’s changelog describes it this way: “With /loop, Cursor can run a prompt repeatedly on a local schedule, until a certain outcome is achieved, or until you stop it.” That one skill covers both cadence and an outcome-based stop, which Claude Code splits between /loop and /goal. Cursor also has its own /goal, rolling out since 2026-08-19 and still marked that way in Cursor’s docs on 2026-10-12.
Cursor documents its /loop far more briefly than Anthropic documents Claude Code’s. None of the jitter, expiry, loop.md or task-limit details on this page are documented for it (checked against Cursor’s changelog and slash-commands reference, 2026-08-28). Test a Cursor loop on a short task before you leave it running.
For schedules that must run without an open editor, use Cursor Automations: cloud agents started on a schedule or by source-control, Slack, webhook, Linear, Sentry or PagerDuty events. The Cloud Agents and Automations guide covers them.
/loop, /goal or a scheduled job?
Section titled “/loop, /goal or a scheduled job?”| You need | Use | Why |
|---|---|---|
| Poll something for the next hour while you work | /loop, self-paced | Cheapest to start; dies with the session |
| Converge on a definition of done (“all tests pass”) | /goal | Stops when a checked condition holds, instead of running on a clock |
| A job that runs every day with your laptop closed | Routines, Codex automations, Cursor Automations or a CI schedule | Durable, and it runs with no session open |
| React the moment CI fails | Channels or a CI job that starts the agent | Event-driven; no polling cost |
The two commands pair well: /goal drives a feature to green, then /loop watches the pull request it produced. For the full comparison of unattended options across vendors, see background and cloud agents compared.
What breaks when a loop runs unattended?
Section titled “What breaks when a loop runs unattended?”The loop fires and nothing happens. The prompt is a skill Claude may not invoke on its own, or an MCP prompt, so it arrives as plain text. Recovery: rewrite the prompt as plain instructions, or remove disable-model-invocation: true from your own skill if running it unattended is safe.
The loop is gone after --resume. Self-paced loops are not restored. Recovery: run /loop again; for anything that must survive restarts, use a durable scheduler.
The loop fires 20 minutes late. That is jitter on an hourly task, not a fault. Recovery: drop the interval so the loop is self-paced (jitter rules don’t apply to self-paced loops), or move the job to a Routine or CI schedule when exact timing matters.
Tokens climb and nothing changes. A one-minute loop on a prompt that re-reads logs burns tokens every round. Recovery: open /usage and read the Loops breakdown, switch to self-paced mode or a longer interval, and tell the prompt to reply with one line when nothing changed.
The loop pushes the same broken fix again and again. The prompt had no attempt cap. Recovery: cancel it, revert the loop’s commits on the branch, and add “stop after two failed attempts and report” plus a local test that must pass before any push.
A review comment steers the loop. Comment text is untrusted input that anyone with access can write. Recovery: tell the prompt to treat comments as requests to evaluate, deny the tools the loop does not need, and keep merge and CI-config edits out of scope.
The loop does not keep a remote session alive. Since v2.1.172, Claude Code stops promoting /loop in remote sessions, because pending loops do not keep the container running. Recovery: use Routines for cloud-side schedules.
On Bedrock, Claude Platform on AWS, Google Cloud’s Agent Platform or Foundry, self-paced mode or the bare /loop is missing. You are on a version older than v2.1.248. Recovery: update Claude Code.