Skip to content

How to Automate Claude Code with /loop and /schedule Commands

Purpose

This post shows how to automate Claude Code to run tasks at scheduled intervals without manual intervention. The key commands are /loop for repeating tasks and /schedule for specific execution times.

The Problem

I review a lot of pull requests. Every time a new PR comment appears, I need to address the feedback. This means constantly checking GitHub and running Claude Code to fix issues.

I wanted Claude to handle this automatically. Instead of babysitting code reviews, I wanted Claude to run itself every few minutes and address new feedback as it arrives.

The Commands

Claude Code has two automation commands:

/loop runs a command repeatedly at a set interval. For example, /loop 5m /babysit runs the babysit command every 5 minutes.

/schedule runs a command at a specific time. For example, /schedule 2024-01-15 09:00 /deploy runs deployment at 9 AM on January 15th.

Both commands can run for up to one week. This makes them useful for ongoing automation tasks, not just one-time operations.

How to Use /loop

The /loop command takes an interval and a command to run:

Loop syntax
/loop <interval> <command>

The interval format supports:

  • m for minutes (e.g., 5m for 5 minutes)
  • h for hours (e.g., 1h for 1 hour)
  • d for days (e.g., 1d for 1 day)

I set up a loop to auto-address code review comments:

Auto-address PR feedback
/loop 5m /babysit

This runs my babysit skill every 5 minutes. The skill checks for new PR comments, reads the feedback, and makes the necessary changes.

I also run multiple loops at the same time:

Multiple loops running together
/loop 5m /babysit
/loop 30m /check-tests
/loop 1h /update-docs

Each loop runs independently. I can have several automation tasks going simultaneously without conflicts.

How to Use /schedule

The /schedule command runs a task at a specific time:

Schedule syntax
/schedule <date> <time> <command>

I use this for deployments during off-peak hours:

Schedule deployment
/schedule 2026-03-31 02:00 /deploy-production

This runs the deployment at 2 AM when traffic is low.

I can also schedule multiple tasks:

Multiple scheduled tasks
/schedule 2026-03-31 09:00 /run-tests
/schedule 2026-03-31 12:00 /generate-report
/schedule 2026-03-31 18:00 /cleanup-logs

Practical Examples

Here are the automation tasks I actually use:

1. Continuous code review monitoring

PR babysitting
/loop 5m /babysit

Every 5 minutes, Claude checks my open PRs for new comments. When it finds feedback, it reads the comment, understands the request, and makes the changes.

2. Test result monitoring

Watch CI status
/loop 10m /check-ci

Every 10 minutes, Claude checks the CI status of my recent commits. If tests fail, it reads the error logs and suggests fixes.

3. Daily cleanup

Daily maintenance
/schedule 2026-03-31 06:00 /cleanup-branches

At 6 AM, Claude runs my branch cleanup script to remove merged feature branches.

4. Weekly report generation

Weekly summary
/schedule 2026-04-07 09:00 /weekly-summary

Monday morning, Claude generates a summary of the past week’s activity.

Common Mistakes

I made some mistakes when I first started using these commands.

1. Setting intervals too short

Too aggressive
/loop 30s /check-status

This ran every 30 seconds and hit API rate limits quickly. I now use a minimum of 5 minutes for most tasks.

2. Forgetting the one-week limit

Won't work past a week
/loop 1d /backup

Loops stop after one week. For permanent automation, I set calendar reminders to restart long-running tasks.

3. Running too many loops simultaneously

Too many at once
/loop 1m /task1
/loop 1m /task2
/loop 1m /task3
/loop 1m /task4
/loop 1m /task5

This caused Claude to slow down. I spread out the intervals and limited myself to 3-4 concurrent loops.

4. Not checking loop status

I started a loop and forgot about it. Days later, I noticed Claude was still running tasks I no longer needed. I now use /loops to check active loops:

Check active loops
/loops

This shows all running loops and their next execution times.

How It Works

The /loop command creates a background process that tracks time. When the interval passes, it executes the command and resets the timer.

The /schedule command stores the scheduled time and checks periodically. When the time arrives, it triggers the command.

Both commands persist across Claude Code sessions. If I close Claude and reopen it, my scheduled tasks continue running. The one-week limit prevents abandoned tasks from running forever.

Summary

In this post, I showed how to automate Claude Code with /loop and /schedule commands. The key point is using /loop for repeated tasks at set intervals and /schedule for specific execution times.

My most common use case is /loop 5m /babysit for continuous PR monitoring. This lets Claude automatically address code review feedback while I focus on other work.

The commands support intervals from minutes to days, run for up to one week, and persist across sessions. I can run multiple loops simultaneously without conflicts.

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