Skip to content

How to Use Claude Code /loop for Recurring Monitoring Tasks

Problem

I was deploying a critical update to staging and needed to monitor the CI/CD pipeline. But I didn’t want to:

  • Keep switching to GitHub Actions in my browser
  • Set up a cron job just for a 30-minute deployment
  • Install another monitoring tool

I just wanted Claude to check every few minutes and tell me when something changed.

What I tried first

My initial approach was manual polling:

Me: Check the deployment status
Claude: The build is running... 3/5 steps complete.
[5 minutes later]
Me: Check again
Claude: Still running... 4/5 steps complete.
[3 minutes later]
Me: Check deployment
Claude: Deployment succeeded! The staging environment is live.

This worked but required me to remember to check. I missed an error window because I got distracted by a Slack notification.

Then I considered setting up a proper monitoring solution:

Option 1: cron job
- Write a shell script
- Configure cron
- Parse JSON output
- Send notifications
- Remove when done
Option 2: CI/CD notifications
- Configure GitHub Actions webhooks
- Set up Slack integration
- Or email notifications
Option 3: Monitoring service
- Sign up for Datadog/PagerDuty
- Configure dashboards
- Pay for infrastructure

All of these felt like overkill for a temporary monitoring need during a deployment.

The solution: /loop command

Claude Code has a built-in /loop command that creates a session-level recurring task. Here’s what I tried:

Claude Code terminal
/loop 5m check the deploy status and alert if there are errors

Claude responded:

[Loop started] Checking deployment status every 5 minutes...
Check 1 (12:00): Build in progress - 2/5 jobs complete
Check 2 (12:05): Build in progress - 4/5 jobs complete
Check 3 (12:10): Build succeeded! Staging deployment starting...
Check 4 (12:15): Deployment complete. Application is live.
No errors detected. Continue monitoring? (loop will auto-cancel in 30 min of no activity)

This was exactly what I needed. Claude checked automatically while I continued working in the same terminal.

How /loop works

The syntax is straightforward:

Basic syntax
/loop [interval] [prompt]

Valid intervals:

SyntaxMeaningBest For
30s30 secondsQuick log tailing
1m1 minuteAPI health checks
5m5 minutesDeployment monitoring
10m10 minutesPeriodic reports
1h1 hourLong-running checks

Key behaviors I observed:

  1. Runs in background: Claude continues executing your loop while you work on other tasks
  2. Session-scoped: The loop stops when you close your Claude Code session
  3. Single active loop: Starting a new loop replaces the previous one
  4. Reports results: Each iteration shows you what it found

Practical examples I tested

CI/CD monitoring during deployment

Deployment monitoring
# Start deployment
npm run deploy:production
# Set up monitoring loop
/loop 2m check if the CI build completed and report any failures
# Continue with other work...
# Claude reports: "Build step 3/5 complete"
# Claude reports: "Build step 5/5 complete - deploying to production"
# Claude reports: "Deployment succeeded!"
# Cancel when done
/loop stop

Log file watching

I was debugging an intermittent error in production:

Log monitoring
/loop 30s check logs/app.log for any ERROR entries in the last minute and summarize
# Claude reports every 30 seconds:
# "No errors in last 60 seconds"
# "No errors in last 60 seconds"
# "Found 2 ERROR entries:
# - NullPointerException at UserService.java:145
# - ConnectionTimeout at DatabasePool.java:89"
/loop stop

API health checks

During a database migration, I wanted to verify API availability:

API health monitoring
/loop 1m curl https://api.example.com/health and report the status code and response time
# Claude reports:
# "Status: 200, Response time: 45ms"
# "Status: 200, Response time: 52ms"
# "Status: 503, Response time: 5000ms - SERVICE DEGRADED"
# "Status: 200, Response time: 48ms - Recovered"

Code quality during development

While refactoring a large codebase:

Lint monitoring
/loop 5m run npm run lint and report if new errors appeared since last check
# Claude reports:
# "15 errors (no change from last check)"
# "18 errors - 3 new issues in utils.ts"
# "12 errors - 6 errors fixed, 3 new issues in api.ts"

Important limitations I discovered

Through trial and error, I learned these constraints:

1. Session-scoped execution

What I expected: Loop continues even if I close my laptop
What actually happens: Loop stops when Claude Code session ends

This makes /loop perfect for:

  • Active development sessions
  • Ongoing deployments
  • Debugging sessions

But NOT for:

  • Overnight monitoring
  • Permanent health checks
  • Production alerting

2. Single loop per session

Terminal window
/loop 5m check deployment status
# (works fine)
/loop 1m check log errors
# (this REPLACES the previous loop)

You can only have one active loop. Starting a new one cancels the previous one.

3. Intervals are approximate

Claude processes each check before scheduling the next. A complex check might take 30 seconds, so a 1m interval might actually run every 90 seconds:

Scheduled: Check every 1 minute
Actual timeline:
12:00:00 - Check started
12:00:25 - Check completed (took 25s)
12:00:25 - Next check scheduled for 12:01:25
12:01:25 - Check started
12:01:30 - Check completed (took 5s)
12:01:30 - Next check scheduled for 12:02:30

When to use /loop vs alternatives

I made a decision matrix:

Scenario/loopCowork Scheduledcron
Monitor deployment during releaseYesOverkillNo
Daily report generationNoYesYes
Temporary log watchingYesNoNo
Permanent production monitoringNoYesYes
Debugging session with periodic checksYesNoNo

For persistent scheduled tasks, the Reddit discussion mentioned Cowork’s scheduled tasks feature as a better alternative. But for temporary, session-based monitoring, /loop fills the gap perfectly.

Best practices I developed

1. Be specific in your prompts

Terminal window
# VAGUE - Claude might not know what to check
/loop 5m watch the deploy
# SPECIFIC - Clear success/failure criteria
/loop 5m check if deployment succeeded and report any error messages from the build log

2. Set appropriate intervals

Terminal window
# TOO SHORT for complex operations
/loop 10s run the full test suite
# This might not finish before the next trigger
# BETTER
/loop 5m run the full test suite and report results

3. Include cleanup in your workflow

Terminal window
# Start monitoring
/loop 2m check staging health endpoint
# ... do your work ...
# When deployment is verified, STOP the loop
/loop stop
# Otherwise it continues until session ends

4. Combine with notifications for critical ops

For critical deployments, I use both:

  • /loop for in-terminal monitoring
  • Claude Channels for mobile alerts if something breaks

A complete workflow example

Here’s my full deployment monitoring workflow:

Complete deployment workflow
# 1. Start the deployment
git push origin main
# 2. Set up monitoring immediately
/loop 1m check the GitHub Actions workflow status at .github/workflows/deploy.yml
# 3. Claude reports periodically:
# "Workflow started - job 'test' running"
# "Job 'test' passed - job 'build' starting"
# "Job 'build' passed - job 'deploy' starting"
# "Job 'deploy' failed - Error: Cannot connect to Kubernetes cluster"
# 4. When I see an error, investigate
kubectl get pods -n production
# 5. Fix the issue and re-run
git push origin main
# 6. Monitor again
/loop 1m check the deployment workflow status
# 7. Success! Clean up
/loop stop

Summary

In this post, I showed how to use Claude Code’s /loop command for lightweight, session-level recurring monitoring. The key point is that /loop creates temporary monitoring without any infrastructure setup.

The command fills a specific gap: you need recurring monitoring for the next hour, not the next month. For deployments, debugging sessions, and temporary health checks, /loop eliminates the need for separate tooling.

Remember the limitations:

  • Session-scoped (stops when Claude Code closes)
  • Single loop per session
  • Intervals are approximate

For persistent scheduled tasks, consider Cowork’s scheduled tasks feature or traditional cron. But for “I need to watch something while I work,” /loop is the simplest solution.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments