Chapter 07 · Section II · 12 min read
Loops and scheduled runs
When a task is not one-shot — a recurring check, an overnight refactor, a cron-shaped chore — Claude Code has primitives for that: /loop for self-paced repetition and scheduled runs for real cron. Both dial autonomy up; both want careful framing.
Some work does not want a single turn. It wants many turns, over time. Polling a deploy every few minutes. Running an audit each morning. Grinding through a long refactor overnight. Claude Code has two primitives for this shape of work.
/loop
/loop re-invokes a prompt (or a slash command) on an interval. Two flavours:
- Fixed interval.
/loop 5m /check-deploys— every five minutes, run the/check-deploysskill. - Dynamic pacing.
/loop /finish-the-refactor— Claude picks the next interval itself based on what it just did.
Fixed is right for polling external state that changes on its own — a deploy, a CI run, a queue. Dynamic is right for work Claude drives itself — a long task where “how long to wait” depends on what just happened.
Scheduled runs
Beyond /loop, Claude Code can register real cron-style scheduled runs (CronCreate and friends). These fire on a schedule regardless of whether you have a session open. When they fire, a fresh session runs the prompt, does the work, and either notifies you or logs to a shared surface.
Good use cases:
- A daily 9 AM release-notes draft based on yesterday’s commits.
- An hourly health check on a service you own.
- A weekly digest of open PRs that have been stale.
Both dial autonomy up
The moment you set up either a loop or a schedule, you are trusting Claude Code to do work when you are not watching. That trust has to be earned; the safety chapter matters a lot more now than it did for interactive work.
Cadence: don’t be greedy
A common newcomer mistake is scheduling something every 60 seconds when the underlying state changes every 30 minutes. That costs money, floods your notifications, and gives the model 30x the chance to do something wrong. Pick a cadence matched to reality.
- External state polls: match the state’s actual change rate. CI checks every 30-60 seconds; queue depth every 5 minutes; deploy status every 2 minutes.
- Self-driven grind loops: the model can pick its own pacing; give it that latitude.
- Business-hour tasks: cron once a day at the right time, not once every hour.
Escaping a runaway loop
If a loop or scheduled run misbehaves, both are stoppable:
/loop stop(or the version your CLI uses) halts a running loop.CronDeleteremoves a schedule.- In extremis, killing the Claude Code process ends the current session; the schedule may still fire next cycle unless you explicitly delete it.
Knowing the “stop” command before you set up the first loop is the mark of an operator.
Check your understanding
Quick check
—