The Claude Code /loop Command: In-Session Automation Explained
The /loop command in Claude Code lets you schedule a prompt to repeat at a regular interval within an active session. It is one of the less-documented features, and it is also one of the most misunderstood — particularly around what it cannot do.
This post explains what /loop actually is, the three scenarios where it genuinely earns its keep, and where cron jobs remain the better choice.
What /loop Does
/loop 5m check if the Vite dev server is still running and report any new errors
This runs the prompt immediately, then repeats it every 5 minutes for the duration of your session. The interval can be in seconds (30s), minutes (5m), or hours (2h).
Hard limits:
- Maximum 50 iterations per loop
- Auto-expires after 3 days of session inactivity
- Dies when you close the Claude Code session
That last point is the most important one. /loop is session-scoped. The moment you close the terminal or the session times out, the loop stops. It is not a daemon. It is not a cron job. It is a within-session automation tool.
flowchart LR
subgraph Session[Active Claude Code Session]
Loop[loop command] -->|every N minutes| Prompt[Runs prompt]
Prompt --> Result[Produces result]
end
Close[Session closes] -->|loop dies| End[Automation stops]
Session --> Close
When It Is Actually Useful
1. Build and CI monitoring during active development
You are in the middle of a refactor and you want to know immediately if the build breaks — without switching tabs every few minutes.
/loop 3m check if our TypeScript build is passing and summarise any new errors
Claude runs tsc --noEmit or reads your CI output, reports back, and you stay in flow. The moment you stop working and close the session, the loop stops — which is exactly what you want.
2. Accumulating code review notes across a long session
/loop 20m /review
Every 20 minutes Claude reviews the current state of your changes and adds new observations to its running notes. By the end of the session you have a comprehensive review built up incrementally rather than one big scan at the end.
3. Monitoring a deployment in progress
/loop 1m check kubectl rollout status deployment/api-server and report when complete
Claude watches the deployment, reports progress every minute, and you stay informed without polling yourself. Once the deployment finishes (or you close the session), the loop ends naturally.
/loop vs Cron: Choosing the Right Tool
flowchart TD
Task[Automation task] --> Q1{Runs while you\nare actively working?}
Q1 -->|Yes| Q2{Session-bound\nis acceptable?}
Q2 -->|Yes| Loop[Use /loop\nSimple, no setup]
Q2 -->|No| Cron[Use cron\nPersists beyond session]
Q1 -->|No - runs overnight\nor on schedule| Cron
| Scenario | Use /loop | Use cron |
|---|---|---|
| Monitor build during active work | ✅ | |
| Morning briefing while you sleep | ✅ | |
| Watch a 30-minute deployment | ✅ | |
| Weekly infrastructure audit | ✅ | |
| Accumulate review notes in a session | ✅ | |
| Daily Slack summary | ✅ |
The rule is simple: if the task needs to run while you are actively working in Claude Code, use /loop. If it needs to run without you present, use cron.
Combining /loop with Hooks
/loop becomes more powerful when combined with hooks. A hook can run tests after every file edit; /loop can then summarise the test results every few minutes:
# While hooks auto-run tests on every edit...
/loop 10m summarise the test results from the last 10 minutes and tell me if anything is consistently failing
This gives you a periodic human-readable summary on top of the deterministic hook behaviour — the hook catches individual failures, the loop gives you the bigger picture.
Practical Usage Tips
Be specific about what to check. “Check for errors” produces shallow results. “Check if the API server is responding to health checks and report the response time” produces actionable output.
Set an interval that matches the task. Build checks every 30 seconds is excessive. Deployment status every 5 minutes means you wait longer than needed. Match the interval to how fast the underlying state changes.
Use /loop to bridge gaps in your workflow. The best uses are for things you would otherwise manually check every few minutes — not for creating new workflows that require their own infrastructure.
Stop a loop with /skip. If you want to cancel the current loop before it completes all iterations, use /skip to stop the next scheduled run.
What /loop Is Not
- It is not a replacement for CI/CD monitoring (use PagerDuty or CI notifications)
- It is not a persistent agent (use cron +
claude -pfor that) - It is not suitable for tasks that need to run when you are not at your desk
- It is not infinitely scalable — 50 iterations maximum
Think of /loop as an in-session assistant that watches something so you do not have to, for as long as you are actively working. For everything else, cron is the right answer.
