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 <interval> <command>The interval format supports:
mfor minutes (e.g.,5mfor 5 minutes)hfor hours (e.g.,1hfor 1 hour)dfor days (e.g.,1dfor 1 day)
I set up a loop to auto-address code review comments:
/loop 5m /babysitThis 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:
/loop 5m /babysit/loop 30m /check-tests/loop 1h /update-docsEach 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 <date> <time> <command>I use this for deployments during off-peak hours:
/schedule 2026-03-31 02:00 /deploy-productionThis runs the deployment at 2 AM when traffic is low.
I can also schedule multiple tasks:
/schedule 2026-03-31 09:00 /run-tests/schedule 2026-03-31 12:00 /generate-report/schedule 2026-03-31 18:00 /cleanup-logsPractical Examples
Here are the automation tasks I actually use:
1. Continuous code review monitoring
/loop 5m /babysitEvery 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
/loop 10m /check-ciEvery 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
/schedule 2026-03-31 06:00 /cleanup-branchesAt 6 AM, Claude runs my branch cleanup script to remove merged feature branches.
4. Weekly report generation
/schedule 2026-04-07 09:00 /weekly-summaryMonday 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
/loop 30s /check-statusThis 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
/loop 1d /backupLoops stop after one week. For permanent automation, I set calendar reminders to restart long-running tasks.
3. Running too many loops simultaneously
/loop 1m /task1/loop 1m /task2/loop 1m /task3/loop 1m /task4/loop 1m /task5This 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:
/loopsThis 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