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 now has a native Loop feature for scheduling recurring prompts - from one-minute intervals to three-day windows. Fix builds on repeat, summarize Slack channels, email yourself pull request digests. All from the CLI.
Official Sources#
| Resource | Description |
|---|---|
| Claude Code Overview | Core features, installation, and architecture |
| Claude Code Commands | CLI reference including /loop and cron commands |
| 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 |
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 "Summarize any new posts tagged #announcements in the team Slack channel" --interval 30m --expires 8h
The minimum interval is one minute. Maximum window is three days. After the expiry, the loop stops automatically - no orphaned processes, no runaway API bills.
Each loop gets a scheduled prompt, optional notes for context, and the auto-expiry timer. Clean and predictable.
The Commands#
Three new commands handle lifecycle management:
cron create # Create a new scheduled loop
cron list # See all active loops in the current session
cron delete # Kill a specific loop by ID
cron list shows you every active loop with its interval, next run time, and expiry. cron delete takes the loop ID and stops it immediately.
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 active session. Close the terminal, close the session, loops stop. This is by design - it keeps the feature safe and predictable. No background daemons, no orphaned processes eating your API quota at 3am.
But it means loops aren't durable. If you need something that survives a reboot or runs when your laptop is closed, you need a different approach:
- Claude Desktop app - has a scheduling feature that persists independently of terminal sessions
- GitHub Actions - for truly durable, cloud-based scheduling with Claude Code as a step
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."
The 10% Time Offset#
A subtle but smart detail: Claude Code adds up to a 10% random offset to your scheduled interval. If you set a 10-minute loop, it might fire at 9:12, then 10:48, then 9:36.
Why? If a thousand developers all schedule a "every 10 minutes" loop, you don't want all of them hitting the API at exactly :00, :10, :20. The jitter spreads the load. Same principle as exponential backoff in distributed systems, applied preemptively.
You can disable this with a flag if you need precise timing, but for most use cases the offset is invisible and helpful.
Limitations Worth Knowing#
- Session-bound. Already covered, but it bears repeating. No session, no loops.
- Minimum one-minute interval. You can't run a loop every 10 seconds. This is a rate-limit guardrail.
- Three-day maximum expiry. Even if your session stays alive, loops cap out at 72 hours.
- Disable flag available. If your org wants to prevent loop usage entirely, there's a flag to turn it off. 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 - ephemeral, 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.
GitHub Actions - cloud-durable, runs when your machine is off, integrates with repos natively. Best for CI/CD-adjacent automation.
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 is based on a Developers Digest video. All feature behavior is based on direct testing with Claude Code at time of publication.
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 to every three days. 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 "Your prompt here" --interval 30m --expires 8h. The minimum interval is one minute and maximum window is three days.
Do Claude Code Loops run in the background?#
Loops are session-scoped - they run while your Claude Code session is active. Close the terminal or end the session, and loops stop. This is by design for safety. For durable automation that survives reboots or runs when your laptop is closed, use GitHub Actions or the Claude Desktop app's scheduling feature.
What is the minimum interval for Claude Code Loops?#
The minimum interval is one minute. This is a rate-limit guardrail to prevent runaway API costs. If you set a loop to run every minute for 8 hours, that's 480 API calls - 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.
What is the 10% time offset in Claude Code Loops?#
Claude Code adds up to 10% random jitter to your scheduled interval. A 10-minute loop might fire at 9:12, then 10:48. This spreads API load across users who might all schedule similar intervals. You can disable this with a flag if you need precise timing.
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.
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
Claude Opus 4.5 ran autonomously for 4 hours 49 minutes using stop hooks and the Ralph Loop pattern. Walk away, come back to completed work. Here's how it works.
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
Hooks give you deterministic control over Claude Code. Auto-format on save, block dangerous commands, run tests before commits, fire desktop notifications. Here's how to set them up.
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.







