Automation & Cloud Execution/Local Automation & CI/CD
Intermediate10 min

The /loop Command and Autonomous Monitoring

The /loop command runs a prompt on a recurring schedule — either at a fixed interval or self-paced where Claude decides when to check back. It's the foundation for CI monitoring, log watching, and the ticket-to-PR automation loop.

Quick Reference

  • /loop {interval} {prompt} — run a prompt every interval (e.g., 2m, 5m)
  • /loop with no interval — self-paced; Claude schedules its own wake-ups
  • Ctrl+B sends a running /loop to the background
  • Ctrl+C stops a foreground /loop; Ctrl+X Ctrl+K kills all background agents
  • Combine with gh pr checks for CI monitoring and auto-fix
  • Use Haiku + low effort for monitoring; Sonnet only for fix attempts
  • Self-pacing is better than fixed intervals for unpredictable tasks
  • /loop is session-local — machine must be on; use Routines for cloud-hosted loops

What /loop Does

/loop is the bridge between a one-shot instruction and a persistent background process. You give it a prompt and an interval, and Claude runs that prompt repeatedly — checking CI status, watching logs, monitoring external APIs, or running maintenance tasks — until you tell it to stop.

Session-Local vs Cloud-Hosted

/loop runs within your current Claude Code session on your local machine. The loop stops if you close Claude Code or shut down your laptop. For loops that need to persist when your machine is off, use Routines (covered in the next chapter).

The most powerful aspect of /loop isn't the repetition — it's the agency. Claude doesn't just re-run a script. It analyzes what it finds each time, decides whether action is needed, takes that action if so, and reports back. It's a monitoring agent, not a cron job.