Skip to main content
Tips

practitioner tip

Make Claude Code Watch Your Code While You Work

AIErudit angle: /loop runs a prompt on a recurring interval inside your live session, so each iteration keeps full context of the files you changed and decisions you made. It's a context-aware watchdog for delivery work like deploys, PR comments, and log errors, versus a blind cron that starts fresh every run.

loopbackground-tasksmonitoringclaude-code
Tip visual

Published: Mar 31, 2026 Updated: 2026-05-23

Original: https://wmedia.es/en/tips/claude-code-loop-recurring-tasks

TL;DR /loop 5m <prompt> runs a prompt on a recurring interval inside your active session. Unlike a cron with claude -p, each iteration has full access to your conversation context: files read, decisions made, changes in progress. It's a watchdog with a brain, not a blind script. And to place /loop inside the full picture of background mechanisms (Agent View, headless, Routines), the map with its decision table lays them all out.

You could set up a cron that runs claude -p "check deploy status" every 5 minutes. It works. But each execution starts from scratch — no memory of what happened before, no session context, no ability to act on what it finds.

/loop is different: it runs inside your open session. Claude knows which files you changed, what you were trying to do, and can compare with the previous iteration. If something changes, it can act immediately with all your tools.

The limitation: you need the session open. Close the terminal, and it's gone. Tasks also auto-expire after 7 days. For monitoring that survives a reboot, use headless mode with cron — or, if you want it running on Anthropic's infrastructure without your machine on, a Routine. Confused about which option fits — /loop, Desktop tasks, Cloud tasks, or system cron? See Stop Confusing /schedule, /loop, and Cron. For the full picture (including Monitor for events and Channels for external push), see the map of all 6 autonomous primitives. If what you want is Claude not stopping until a specific condition holds (instead of polling on a fixed interval), see /goal.

Result:

> /loop 5m check if the staging deploy at localhost:3000 is responding

Loop started (every 5m). Task ID: loop-a1b2c3
Next run: 12:05:00

# 12:05 — localhost:3000 returns 503. Deploy still in progress.
# 12:10 — localhost:3000 returns 200. Deploy complete. All health checks pass.

How to use it

1. Basic syntax

/loop [interval] <prompt>

Default interval is 10 minutes. Formats: 5m (minutes), 2h (hours), 1d (days).

2. Practical examples

# Watch a deploy
/loop 5m check if the staging deploy finished and tests pass

# Monitor PRs
/loop 15m check open PRs for new comments, summarize responses needed

# Detect merge conflicts
/loop 30m detect merge conflicts between current branch and main

# Scan logs for errors
/loop 5m scan app.log for FATAL/ERROR entries in the last 5 minutes

3. Best practices

  • Define alert conditions — you don't want noise on every iteration, only anomalies
  • Limit the scope — src/ instead of the entire project
  • Set termination rules — "stop after 3 consecutive passes"

/loop vs cron + claude -p

Aspect/loopcron + claude -p
ContextFull session (files, history, decisions)None — each run is fresh
Can actYes — edits, executes, uses toolsYes, but without prior context
Accumulates knowledgeYes — compares with previous iterationsNo
PersistenceOnly while session is openSurvives reboots
Expiry7 days automaticallyNo limit
ConcurrencyMax 50 tasks per sessionNo limit
Use caseWatch while you workReal monitoring / scheduled tasks

Reference

AspectDetail
Command/loop [interval] <prompt>
Default interval10 minutes
Formats5m, 2h, 1d
Max tasks50 per session
Expiry7 days
PersistenceDoes not survive terminal close
TypeBundled skill (ships with Claude Code)

Official docs: Skills — Bundled skills

Related: Computer use — when the terminal is not enough · Headless mode · The map of 4 ways to send Claude to background