Background Tasks, /loop & Scheduling
Not everything is a quick edit. Claude Code can run work that outlives a single prompt: long commands in the background, recurring loops, and scheduled runs.
- Tell the three mechanisms apart: background tasks, /loop, and scheduled routines
- Start a long command without blocking the session — and know why polling it in a tight loop is the wrong move
- Pick the right one from a single question: does the work outlive the prompt, the session, or neither?
- Write instructions for a scheduled run that are self-contained, because each run starts fresh
- Put guardrails under anything that acts unattended
Background tasks
Kick off a long-running command (a dev server, a test watcher, a build) without blocking the session. Claude keeps working and is notified when the task produces output or finishes. Use it for anything you'd normally background with & — but managed, so Claude can read the output later.
Start the task in the background and continue; let the completion notification bring you back, rather than polling in a tight loop.
Recurring loops (/loop)
/loop runs a prompt or command on a recurring interval within a session — e.g. "every 5 minutes, check the deploy status." Give it an interval, or let Claude self-pace. Great for babysitting a CI run or polling an external job that the harness can't otherwise notify you about.
Poll a deploy every five minutes, in-session
/loop 5m check the deploy status and tell me the moment it goes green or fails
Omit the interval and Claude paces itself instead of running on your clock.
Scheduled cloud agents
For work that should happen on a clock, ongoing — "every morning summarize new issues," "hourly, check for news and update the docs" — use scheduled tasks / routines (cron-style). Each run starts fresh, so its instructions must be self-contained.
Choosing between them
| Need | Use |
|---|---|
| Run a long command, keep working | Background task |
| Poll something every N minutes this session | /loop |
| Do something on a schedule, indefinitely | Scheduled routine |
- One prompt, but not the session? Background task. The prompt, repeatedly, inside this session? /loop. The session itself, on a clock, indefinitely? Scheduled routine.
- Kick off the long command in the background and keep working. Claude is notified when the task produces output or finishes — don't poll it in a tight loop.
- Each scheduled run starts fresh, so its instructions carry all the context it needs. Nothing from the session where you set it up comes along.
- Tightly scoped, reversible work only, paired with strict permissions. Autonomy without guardrails is the failure mode this feature makes easy to reach.
Anything that acts unattended on a schedule should be tightly scoped and reversible. Pair it with strict permissions and read Hardening Autonomous Runs.
Check yourself
0/3- Three mechanisms, one question: does the work outlive the prompt (background task), repeat inside the session (/loop), or outlive the session entirely (scheduled routine)?
- Background tasks are managed, not just backgrounded with & — Claude can read the output later and is notified when they finish.
- Don't busy-wait. Start it, continue, let the completion notification return you to it.
- /loop takes an interval, or self-paces if you leave the interval off.
- Every scheduled run starts fresh, so its instructions must stand alone.
- Unattended autonomy needs strict permissions and reversible scope — that pairing is not optional.
Next
- Cloud Sessions and Cloud Environments — the fourth option: work that outlives your machine entirely
- Auto-Commit Background Agents: Draft-PR Handoff — what happens when a background session finishes
- Headless Mode & the Agent SDK
- Permissions & Modes
- Hardening Autonomous Runs