Claude Code Loops: Recurring Prompts That Actually Run
Claude Code Mastery
20 parts- 1Claude Code: The Future of Coding?
- 2What Is Claude Code? The Complete Guide for 2026
- 360 Claude Code Tips and Tricks for Power Users
- 4Claude Code Sub Agents: Parallel AI Development
- 5Claude Code Worktrees: Parallel Development Without the Chaos
- 6Building Multi-Agent Workflows in Claude Code: A Practical Tutorial
- 7The Ralph Loop: Running Claude Code For Hours Autonomously
- 8Self-Improving Skills: Claude Code That Learns From Every Session
- 9Claude Code Usage Limits in 2026: The Practical Playbook for Pro and Max Teams
- 10Progressive Disclosure: How Claude Code Cut Token Usage by 98%
- 11Claude Code + Chrome: AI Agents That Use Your Browser
- 12Interview Mode: Let Claude Code Ask the Questions First
- 13Claude Code: Remote Control, Auto Memory, Plugins & More
- 14Claude Code Hooks Explained
- 15How to Use Claude Code with Next.js
- 16Claude Code Channels: Telegram, Discord, iMessage, and Webhooks
- 17How to Migrate from GitHub Copilot to Claude Code
- 18Building a SaaS with Claude Code: End-to-End Guide
- 19Create Beautiful UI with Claude Code: The Style Guide Method
- 20Claude Code Loops: Recurring Prompts That Actually RunCurrent
TL;DR
Claude Code /loop runs prompts on repeat in a session: fixed or self-paced intervals, seven-day expiry, jitter, and when Routines fit better.
Official Sources#
| Resource | Description |
|---|---|
| Claude Code Overview | Core features, installation, and architecture |
| Run prompts on a schedule | /loop, the cron tools, jitter and expiry rules |
| Claude Code Sub-agents | Parallel execution and task delegation |
| Claude Code MCP Integration | Connecting loops to external tools via MCP |
| Claude Code Settings | Configuration options and flags |
| Claude Code Pricing | API costs for loop iterations |
Last updated: October 13, 2026 - re-verified against the official scheduled tasks docs. Earlier versions of this post described a --interval flag, cron create commands, a three-day cap and a 10% offset; the current docs differ, and the sections below are corrected.
If you've ever wanted Claude Code to do something more than once without babysitting it, you've probably hacked together a shell loop or a cron job wrapping claude -p. That worked. Barely. Claude Code now has a first-class Loop feature that handles recurring prompts natively - scheduling, intervals, expiry, and session scoping built in.
This is the evolution of the "Ralph Wiggins technique" (yes, that was its name) into something you'd actually ship a workflow around.
Why Your Scheduled Tasks Keep Dying#
The core problem with wrapping Claude Code in external schedulers: context evaporates between runs. Each invocation is a cold start. No memory of the last run. No awareness of what changed. No ability to pick up where it left off.
Loops solve this by keeping the session alive. The prompt runs on a schedule within a persistent Claude Code session. Same context window, same tool access, same MCP connections. The agent remembers what it did last iteration and can build on it.
Setting Up Your First Loop#
Two entry points. Natural language or the /loop command.
Natural language works exactly how you'd expect:
Every 5 minutes, check if my PR build is passing. If it fails,
read the error log, fix the issue, and push a new commit.
Claude Code parses the schedule, sets the interval, and starts executing. You can also be explicit with the command:
/loop 30m summarize any new posts tagged #announcements in the team Slack channel
The interval can lead the prompt as a bare token like 30m, or trail it as a clause like every 2 hours. Supported units are seconds, minutes, hours and days; seconds round up to the nearest minute because cron has one-minute granularity, and intervals that do not map to a clean cron step (such as 7m or 90m) are rounded to one that does, with Claude telling you what it picked. Recurring tasks expire seven days after creation: the task fires one final time, then deletes itself.
What you provide changes the behavior, per the docs:
- Interval and prompt (
/loop 5m check the deploy): runs on a fixed schedule. - Prompt only (
/loop check the deploy): Claude picks a delay between one minute and one hour after each iteration, short while a build is finishing and longer when nothing is pending. - Nothing, or interval only (
/loop): runs a built-in maintenance prompt that continues unfinished work, tends the current branch's pull request, then runs cleanup passes. Put your own default in.claude/loop.md(project) or~/.claude/loop.md(user) to replace it.
You can also pass a skill, for example /loop 20m /review-pr 1234, as long as that skill is one Claude is allowed to invoke on its own.
Managing Loops#
You manage scheduled tasks in plain language ("what scheduled tasks do I have?", "cancel the deploy check job") or through the tools Claude uses underneath:
| Tool | Purpose |
|---|---|
CronCreate | Schedule a task from a 5-field cron expression and a prompt, recurring or one-shot |
CronList | List tasks with their IDs, schedules and prompts |
CronDelete | Cancel a task by its 8-character ID |
A session holds up to 50 scheduled tasks. These are tools Claude calls, not shell commands you type. To stop a self-paced loop while it waits, press Esc.
Use Cases That Actually Matter#
Fixing builds on repeat. Point a loop at your CI pipeline. Every few minutes, check the build status. If it's red, read the logs, identify the failure, fix it, commit, push. Keep going until green. This is the "leave it running overnight" play - wake up to a passing build instead of a Slack notification graveyard.
Slack channel summaries via MCP. If you've connected Slack through MCP, loop a prompt that pulls new messages from a channel, summarizes them, and writes the summary to a local file or posts it back to a different channel. Daily standup notes that write themselves.
Daily git recaps. Schedule a loop that runs once a day, pulls git log for the last 24 hours across your repos, formats a summary, and saves it to your desktop. Context on what your team shipped without opening GitHub.
Every day at 9am, run git log --since="24 hours ago" --oneline
across all repos in ~/Developer, summarize the changes by project,
and save to ~/Desktop/daily-recap.md
Combining Loops with Skills#
This is where it gets interesting. Loops compose with everything Claude Code already has - skills, MCP tools, CLI access. Chain them together.
A daily pull request digest is a good example of this in practice:
- Loop fires every morning
- The GitHub CLI lists open pull requests waiting on your review
- Claude summarizes each one and flags the risky changes
- Gmail CLI skill sends you the digest as an email
Every day at 7am, use the gh CLI to list open pull requests where my review is requested.
Summarize each one in two lines and flag anything that touches auth or billing.
Email me the summary using the Gmail CLI skill.
One prompt. Four tools. Runs daily until the session closes or the expiry hits. No glue code.
Session Scope: The Big Caveat#
Loops are scoped to the session. Tasks only fire while Claude Code is running and idle, so closing the terminal stops them. Two details from the docs matter: claude --resume and --continue restore tasks created with CronCreate that have not expired, but a self-paced /loop is not restored, so run it again; and backgrounding the session carries /loop tasks over to a background session that keeps running without a terminal.
If you need something that does not depend on an open session, the docs point to three options:
- Routines - run in the cloud on a schedule, via API call, or on GitHub events, with a one-hour minimum interval
- Desktop scheduled tasks - run locally on your machine without an open session, with a one-minute minimum
- GitHub Actions - a
scheduletrigger in CI
For anything that needs to run reliably for more than a working session, use those instead. Loops are for "I'm working and I want this thing happening in the background while I focus on something else."
Jitter: Runs Start Late#
Claude Code deliberately shifts run times so thousands of sessions do not hit the API at the same minute. Per the docs, a recurring task starts each run late by up to half the gap to the next run, capped at 30 minutes:
| Schedule | When each run starts |
|---|---|
Every 5 minutes (/loop 5m) | 4 min 45 s after the previous run |
| Every 10 minutes | 0 to 5 minutes late |
| Every 30 minutes | 0 to 15 minutes late |
| Hourly or less often | 0 to 30 minutes late |
The 5-minute case is special: a run exactly five minutes later would start after the prompt cache expired, so each run starts 15 seconds early. One-shot tasks on the hour or half hour run up to 90 seconds early, so schedule off the hour (3 9 * * *) when timing matters. Self-paced loops are not jittered.
Limitations Worth Knowing#
- Session-bound. Already covered, but it bears repeating. No session, no loops.
- Minimum one-minute interval. Seconds round up to a minute.
- Seven-day expiry. Recurring tasks fire once more after seven days, then delete themselves. Cancel and recreate, or use Routines, for longer.
- No catch-up. If a run comes due while Claude is busy, it fires once when Claude is idle, not once per missed interval.
- Disable switch. Set
CLAUDE_CODE_DISABLE_CRON=1to disable the scheduler,/loopand the cron tools. Useful for teams where runaway automation is a concern. - API costs accumulate. Each loop iteration is a full prompt execution. A 1-minute loop running for 8 hours is 480 API calls. Plan accordingly.
When to Use Loops vs. Cron vs. GitHub Actions#
Loops - session-scoped, great for "while I'm working" background tasks. Zero setup.
System cron / LaunchAgents - durable, survives reboots, but you lose Claude Code's session context. Each run is a cold start.
Routines and GitHub Actions - cloud-durable, run when your machine is off. Routines are Claude-native; Actions suit CI/CD-adjacent automation. See also Claude Code Routines vs Managed Agents Schedules.
Pick based on durability requirements. Most developers will use loops for the ad-hoc stuff and Actions for anything that needs to be reliable. When a looped job grows into multi-step agent work with branching and handoffs, the Claude Code dynamic workflows guide covers the next primitive up the stack. For runs that need to hold a lot of state across a long horizon, long-horizon agents with Fable 5 covers the 1M-context and memory angle.
- Claude Code Loops in 7 Minutes - full walkthrough with live examples
Official docs:
- Claude Code Documentation - Anthropic's official Claude Code docs
- Claude Code Skills - composable skills that pair well with loops
This article started from a Developers Digest video recorded in March 2026. Scheduling behavior was re-checked against the official docs on October 13, 2026, and the video may show older flags.
Further Reading:
- Anthropic: Introducing Claude Code - official announcement and feature overview
- Claude Code Sub-Agents Guide - parallel agents that compose with loops
- Claude Code Worktrees - another Claude Code primitive for parallel development
- GitHub CLI Manual - the
ghcommands used in the pull request digest example
Frequently Asked Questions#
What are Claude Code Loops?#
Claude Code Loops are a native scheduling feature that lets you run recurring prompts at set intervals - from every minute up, with a seven-day expiry. Unlike wrapping Claude Code in external cron jobs, loops maintain session context between runs, so the agent remembers what it did in previous iterations and can build on that work.
How do I create a loop in Claude Code?#
Two ways. Use natural language like "Every 5 minutes, check if my build is passing" and Claude Code parses the schedule automatically. Or use the explicit command: /loop 30m your prompt here. The minimum interval is one minute, and recurring loops expire after seven days.
Do Claude Code Loops run in the background?#
Loops are session-scoped - they run while your Claude Code session is open and idle. Close the terminal and they stop, though resuming with --resume restores unexpired cron tasks. For durable automation that survives reboots or runs when your laptop is closed, use Routines, Desktop scheduled tasks or GitHub Actions.
What is the minimum interval for Claude Code Loops?#
The minimum interval is one minute. If you set a loop to run every minute for 8 hours, that's up to 480 prompt runs - plan your usage accordingly.
Can I combine loops with MCP servers and skills?#
Yes. Loops compose with everything Claude Code has - skills, MCP tools, CLI access. A common pattern is a loop that fires daily, uses the GitHub CLI to pull the pull requests waiting on your review, summarizes them, and emails you the digest via the Gmail CLI skill. One prompt, multiple tools, runs automatically.
Why does my Claude Code loop start late?#
Claude Code adds jitter to spread API load. A recurring task starts each run late by up to half the gap to the next run, capped at 30 minutes, so a 10-minute loop runs 0 to 5 minutes late. The exception is /loop 5m, which starts each run 4 minutes 45 seconds after the previous one. Self-paced loops are not jittered.
When should I use loops vs cron vs GitHub Actions?#
Use loops for ephemeral, session-scoped background tasks while you're working - zero setup. Use system cron for durable scheduling that survives reboots but loses session context. Use GitHub Actions for cloud-durable automation that runs when your machine is off and integrates with repos natively.
Continue Reading#
- Claude Code - plans, install routes, and alternatives on one page
- Claude Code Power User course - hooks, headless runs, and GitHub Actions for the scheduled work loops pair with
Watch the Video#
Get the next deep dive like this in your inbox
One email a week on Claude Code and the rest of the AI dev stack. Free.
Read next on Claude Code
The Ralph Loop: Running Claude Code For Hours Autonomously
The Ralph Loop uses Claude Code stop hooks to keep an agent working autonomously for hours. How stop hooks, completion promises and max iterations fit together.
10 min readShip Code While You Sleep: The Overnight Agent Workflow
How to spec agent tasks that run overnight and wake up to verified, reviewable code. The spec format, pipeline, and review workflow.
11 min readClaude Code Hooks Explained
Claude Code hooks run shell commands at exact lifecycle points. Set up auto-format, dangerous-command blocking, tests before stopping and desktop notifications.
12 min readTechnical content at the intersection of AI and development. Building with AI agents, Claude Code, and modern dev tools - then showing you exactly how it works.







