The /loop Command: Recurring and Self-Paced Prompts
The deploy takes about eight minutes. So you wait, type “is it done yet?”, read “still building,” wait, ask again. Or the PR is in review and you keep checking back for CI results and new comments. None of this is hard — it’s just a prompt you’d run on repeat if you could, and being the thing that runs it on repeat is a waste of a developer.
/loop is that repeater. You give it a prompt and, optionally, a cadence, and it re-runs the prompt for you — on a fixed interval, on an interval it chooses based on what it sees, or as a standing maintenance routine. It’s the cadence-based half of autonomous operation; its sibling, /goal, is the condition-based half.
What you’ll walk away with
Section titled “What you’ll walk away with”- The three modes of Claude Code’s
/loop— fixed interval, self-paced, and maintenance — and when to use each - The exact syntax, including how intervals map to cron and how to stop a loop
- How to replace the default maintenance prompt with your own
loop.md - What to use instead in Codex and Cursor
- How
/loopdiffers from/goal
The three modes (Claude Code)
Section titled “The three modes (Claude Code)”/loop is a bundled skill (requires Claude Code v2.1.72 or later). Both the interval and the prompt are optional, and what you supply decides the behavior:
| What you provide | Example | What happens |
|---|---|---|
| Interval and prompt | /loop 5m check the deploy | Prompt runs on a fixed schedule |
| Prompt only | /loop check the deploy | Prompt runs at an interval Claude picks each round |
| Interval only, or nothing | /loop | The built-in maintenance prompt runs (or your loop.md) |
Fixed interval
Section titled “Fixed interval”Supply an interval and Claude converts it to a cron expression, schedules the job, and confirms the cadence and a job ID:
/loop 5m check if the deployment finished and tell me what happenedThe interval can lead as a bare token (30m) or trail as a clause (every 2 hours). Units are s, m, h, d. Seconds round up to the nearest minute (cron’s granularity), and odd intervals like 7m or 90m round to the nearest clean cron step — Claude tells you what it picked. You can pass another command as the prompt, too: /loop 20m /review-pr 1234 re-runs a saved skill each iteration.
Self-paced
Section titled “Self-paced”Omit the interval and Claude chooses the delay itself after each round — anywhere from one minute to an hour — based on what it observed, and prints the reason for each wait:
/loop check whether CI passed and address any review commentsShort waits while a build is finishing, longer waits once things go quiet. For this mode Claude may use the Monitor tool to stream a background script’s output instead of re-running the prompt — often more responsive and more token-efficient than polling.
Maintenance
Section titled “Maintenance”A bare /loop (no prompt) runs a built-in maintenance routine at a self-chosen interval. Each round it works through, in order: continue unfinished work from the conversation, tend the current branch’s PR (review comments, failed CI, merge conflicts), then run cleanup passes like bug hunts or simplification when nothing else is pending. It won’t start new initiatives outside that scope, and irreversible actions only proceed when they continue something the transcript already authorized.
Stopping and expiry
Section titled “Stopping and expiry”Press Esc while a loop waits for its next iteration to clear the pending wakeup. In self-paced mode, Claude can also end the loop itself by not scheduling the next wakeup once the task is provably complete. Every loop carries a seven-day expiry — it fires one last time seven days after creation, then deletes itself, so a forgotten loop can’t run forever. Loops are session-scoped; claude --resume or --continue restores any that haven’t expired.
Tool support
Section titled “Tool support”Native, as described above. For scheduling that outlives the session, Claude Code also offers Routines (Anthropic-managed cloud, 1-hour minimum), Desktop scheduled tasks (your machine), and GitHub Actions — /loop itself is the in-session, quick-polling option. Set CLAUDE_CODE_DISABLE_CRON=1 to disable the scheduler (and /loop) entirely.
Codex has no /loop command. Its looping primitive is /goal: enable features.goals, set an objective, and Codex runs plan → act → test → review on its own until the condition is met. That’s a condition-based loop rather than a scheduled one — there’s no native “every 5 minutes” in the CLI. For time- or event-driven runs, wire Codex into CI or a GitHub/Linear automation.
Cursor has no /loop command. The equivalent is Cursor Automations, which run a coding agent on a schedule or in response to events — file saves, git commits, test failures — without you initiating each task. It’s the closest analog to a fixed-interval /loop, but lives in Cursor’s automation layer rather than as a slash command in the chat.
/loop versus /goal
Section titled “/loop versus /goal”The two autonomous commands answer different questions:
/loopanswers “how often?” — it re-runs a prompt on a cadence and may never terminate on its own (the seven-day expiry is a backstop, not a finish line)./goalanswers “until when?” — it runs flat-out until a verifiable stopping condition is true, then stops.
Use /loop for monitoring and standing maintenance; use /goal for convergent work with a clear definition of done. They pair well: /goal drives a feature to green, then /loop watches the PR it produced.