Step 1 — Open Claude Code in a project
Open a terminal in any project folder and start Claude Code, or launch the desktop app. If you do not have a real project to test on, an empty folder works fine — loops do not need a codebase to run.
cd ~/your-project claude
Step 2 — Pick a task worth repeating
Loops earn their keep on tasks you would otherwise type more than once. Good first candidates:
- Checking the status of a CI build.
- Watching for new commits on a branch.
- Re-running a flaky test until it passes (or fails consistently).
- Tailing a log file and surfacing new errors.
- Counting how many open PRs touch a specific file.
For this guide we will use a very simple example: check the current git status every minute and only report changes. Replace it with whatever fits your day.
Step 3 — Type your first /loop command
In the Claude Code prompt, type:
/loop 1m run git status. Only tell me if something is different from the last run.
Hit enter. Three things happen:
- Claude parses the interval (
1m) and the task body. - It runs the task immediately and reports the result.
- It schedules itself to wake up again in 1 minute.
Step 4 — Watch the first run
You will see Claude run git status via the Bash tool and print the working tree state. On a clean tree, the response is something like:
Working tree clean. Next check in 1 minute.
This is normal. Loops are most useful precisely when they are quiet — they only need to interrupt you when something changes.
Step 5 — Watch the scheduled re-run
After roughly a minute, Claude will wake up on its own. The interface shows a small "loop iteration" indicator and the task re-runs. If nothing has changed, Claude stays quiet. If you create a new file, edit something, or commit, Claude reports the diff:
Change detected: modified: src/app.ts Everything else clean. Next check in 1 minute.
Try editing a file in another terminal and watch the next iteration pick it up.
Step 6 — Try dynamic mode
Now let Claude pick its own pacing. Stop the current loop first (next step) and try:
/loop watch the dev server. Tell me if it crashes. Stop when it stays alive for 30 minutes straight.
No interval. Claude will decide how long to wait between checks based on what it observes — short waits when the server is bouncing, longer ones when it stabilizes. You will see Claude call ScheduleWakeup at the end of each iteration with a chosen delay and a reason.
Step 7 — Stop the loop
When you are done, end the loop with:
/loop stop
Or simply close the Claude Code session. Either way, the loop terminates cleanly and nothing runs in the background.
Common starter templates
Copy any of these, swap the details for your own project, and you have a useful loop:
Poll a long-running CI build
/loop 3m check the latest GitHub Actions run for branch feature/payments. Only ping me on success, failure, or a flaky retry.Watch for new error log lines
/loop 5m tail the last 200 lines of /var/log/app.log. Report any new ERROR or FATAL entries you have not seen before.
Track open PRs that touch a critical file
/loop 30m list open PRs that modify src/payments/charge.ts. Report new ones, closed ones, or new review requests.
Re-run a flaky test
/loop 90s run npm test -- payments.spec.ts. Stop when it passes 5 times in a row.Tips for your first week
- Start with longer intervals. 5-10 minutes is plenty for most things. Tighter intervals burn more tokens.
- Tell Claude when to stop. "Stop when X happens" produces cleaner loops than ones that run forever.
- Be specific about what counts as "new." "Only tell me about errors I have not seen before" is much better than "watch for errors."
- Use dynamic mode for unpredictable timing. Polling external services? Let Claude self-pace.
- Combine with skills.
/loop 1h /code-reviewworks, and so does/loop 15m /verify.
Where next?
- Browse 20+ real-world loops — copy-paste templates for CI, deploys, inbox, metrics, and more.
- Read the internals — understand modes, pacing, and best practices.
- Open the full docs — every command, every flag.
- FAQ — answers to the questions everyone asks on day two.