Claude Code Loop: How to Use /loop to Repeat Prompts

Claude Code loop guide: how /loop repeats a prompt on an interval, syntax and units, examples for deploys, PRs and tests, how to stop it, and its limits.

Josh Pocock7 min read

/loop command cover

AI Coding

/loop command

Stride AI Academy

The Claude Code loop is the /loop command: it re-runs a prompt in your open session on a schedule, such as /loop 5m check if the deployment finished. Give it an interval and it runs on a fixed timer. Leave the interval out and Claude picks the wait between runs itself. It only fires while your session is open, so it suits polling a build or a pull request, not jobs that run for weeks.

This guide covers the syntax, intervals, practical examples, how to stop a loop, its limits and when to use something else. Everything here was checked against Anthropic's scheduled tasks docs, cloud scheduled tasks docs and Desktop scheduled tasks docs on November 18, 2026.

What /loop does

/loop is a bundled skill that schedules a prompt to run again and again inside the current session. Under the hood, Claude turns your request into a cron job with its CronCreate tool and confirms the cadence and an 8-character job ID.

A scheduled run never interrupts Claude mid-answer. It fires between your turns, and if Claude is busy, it waits until the current turn ends.

/loop syntax: three ways to call it

Both the interval and the prompt are optional. What you give it decides how it behaves.

You type Example What happens
Interval and prompt /loop 5m check the deploy Runs on a fixed schedule
Prompt only /loop check the deploy Claude picks the wait after each run
Interval only, or nothing /loop Runs the built-in maintenance prompt, or your loop.md

You can also pass a skill as the prompt, for example /loop 20m /review-pr 1234. Only skills Claude is allowed to invoke on its own will run. Built-in commands such as /model or /clear, and MCP prompts, reach Claude as plain text instead. If you haven't made a skill yet, see how to create Claude Code skills.

Intervals and units

The interval can lead the prompt as a token like 30m, or trail it as a phrase like every 2 hours. Supported units:

Unit Meaning Example
s seconds /loop 90s ...
m minutes /loop 10m ...
h hours /loop 2h ...
d days /loop 1d ...

Two rounding rules matter:

  • Seconds round up to a minute. Cron works in whole minutes, so one minute is the shortest gap.
  • Odd intervals get rounded. Something like 7m or 90m doesn't map to a clean cron step, so Claude picks the nearest one that does and tells you what it chose.

Times are in your local time zone, not UTC.

Let Claude choose the interval

Skip the interval and the loop becomes self-paced. After each run, Claude picks a delay between one minute and one hour based on what it saw: short waits while a build is finishing or a PR is busy, longer ones when nothing is happening. It prints the delay and the reason at the end of each run.

/loop check whether CI passed and address any review comments

A self-paced loop can also end itself. Once the job is done, Claude can cancel its own next wakeup.

Run the built-in maintenance prompt

A bare /loop runs Anthropic's built-in maintenance prompt at a self-paced interval. Each run works through this list in order:

  1. Continue any unfinished work from the conversation.
  2. Tend to the current branch's pull request: review comments, failed CI runs, merge conflicts.
  3. Run cleanup passes such as bug hunts or simplification when nothing else is pending.

Each run still goes through your session's permission checks before it pushes or deletes anything. Add an interval, like /loop 15m, to run it on a fixed schedule.

Replace it with loop.md

To swap in your own default, write a plain Markdown file:

Path Scope
.claude/loop.md This project. Wins when both exist.
~/.claude/loop.md Every project without its own file.
Markdown
Check the open PR for this branch. If CI is red, read the failing
job log and push a minimal fix. If there are new review comments,
address each one. If everything is green and quiet, say so in one line.

Edits take effect on the next run, so you can tune it while the loop is going. The file is ignored whenever you type a prompt after /loop, and anything past 25,000 bytes is cut off.

Examples: deploys, PRs and tests

Watch a deploy. A fixed short interval works while you wait for a release:

/loop 5m check if the deployment finished and tell me what happened

Babysit a pull request. Let Claude pace itself, since review activity comes in bursts:

/loop check PR 412 for failed checks and new review comments, fix what's clear, and tell me what you changed

Claude needs access to the repository's PRs for this to work. Our guide to Claude Code with GitHub walks through connecting it.

Re-run tests while you work. Useful when you're editing in another window:

/loop 10m run npm test and summarize any new failures since the last run

For a single run, skip /loop and just ask, for example in 45 minutes, check whether the integration tests passed.

What happens on each loop run

  1. 1The interval comes dueFixed cron or Claude's chosen delay
  2. 2Waits until Claude is idleNever interrupts a turn
  3. 3Claude runs your prompt in the sessionSame permissions, tools and context
  4. 4Next run is scheduledOr the loop ends itself when done

How to stop a loop

How you stop it depends on the kind of loop:

  • Self-paced loop (no interval): while it's waiting for the next run, press Esc on an empty prompt. Ctrl+C also works while Claude is idle. A Pending wakeup cancelled notice confirms it.
  • Fixed-interval loop (like /loop 5m): Esc and Ctrl+C don't stop it. Ask Claude to cancel it, for example cancel the deploy check loop.

To see what's scheduled, ask what scheduled tasks do I have?. Claude lists each task's ID, schedule, next run time and prompt with its CronList tool, and cancels by ID with CronDelete.

To turn the feature off entirely, set CLAUDE_CODE_DISABLE_CRON=1 in your environment.

Limits to know

  • The session must stay open and idle. Close the terminal and nothing fires.
  • Recurring loops expire after 7 days. The task fires one last time, then deletes itself. A loop you forget about can't run forever.
  • No catch-up. If runs are missed while Claude is busy on a long request, it fires once when Claude is free, not once per missed run.
  • 50 tasks per session, at most.
  • Runs drift a little on purpose. To spread out API load, recurring tasks start late by up to half the gap between runs, capped at 30 minutes. An hourly task can start up to 30 minutes late. /loop 5m is the exception: it runs 4 minutes 45 seconds after the previous run.
  • Resuming is partial. claude --resume or claude --continue restores fixed-interval tasks that haven't expired, but not a self-paced /loop. Run /loop again to restart that one.

Every run also adds to the conversation, so a long loop fills the context window. See Claude Code context management for ways to keep it under control.

When to use routines, Desktop tasks or headless mode instead

/loop is the quick option for polling during a session. For anything that has to run without you, pick one of these:

/loop Desktop scheduled task Cloud routine claude -p from cron
Runs on Your machine Your machine Anthropic's cloud Your machine or server
Session must be open Yes No No No
Machine must be on Yes Yes No Yes
Local files Yes Yes No, fresh clone Yes
Shortest interval 1 minute 1 minute when Claude sets it, 1 hour in the forms 1 hour Whatever your scheduler allows
  • Cloud routines (now called cloud scheduled tasks) run with your laptop closed, on a schedule, an API call or a GitHub event. Our Claude routines guide covers setting one up.
  • Desktop scheduled tasks run in the Claude Desktop app on your computer, with access to your local files, and survive restarts.
  • Headless mode is claude -p "prompt" called from your own cron job or CI. You own the scheduler and the logs. See the Claude Code headless mode guide.

Learn to build with Claude Code

The Stride AI Coding course teaches Claude Code and Codex for building client tools, written for non-programmers, with weekly live calls to review your builds. Many of the free guides cover Claude Code setups, and the Claude Code community is where members compare theirs.

FAQ

What does /loop do in Claude Code?

It re-runs a prompt or skill in your current session on a repeating schedule. With an interval like /loop 5m it runs on a fixed timer. Without one, Claude picks a delay between one minute and one hour after each run.

How do I stop a /loop in Claude Code?

For a self-paced loop, press Esc on an empty prompt while it waits for its next run. For a fixed-interval loop such as /loop 5m, ask Claude to cancel it, because Esc and Ctrl+C don't stop those.

What is the shortest interval for /loop?

One minute. Cron works in whole minutes, so an interval in seconds is rounded up to the nearest minute.

Does /loop keep running after I close Claude Code?

No. Tasks only fire while Claude Code is running and idle. Resuming with --resume or --continue restores fixed-interval tasks that haven't expired, but a self-paced loop has to be started again.

How long does a Claude Code loop run?

Until you cancel it, the session ends, or 7 days pass. Recurring tasks expire 7 days after they're created, firing one final time before they delete themselves.

What's the difference between /loop and /schedule?

/loop runs in your open session on your machine and can repeat every minute. /schedule creates a cloud routine that runs on Anthropic's infrastructure with your computer off, at most once an hour.

Build it with us in Stride AI Academy

Four courses, weekly live calls and a community of people building and selling AI. Or start with 310+ free guides.

Keep reading

Free AI Coding guides