TIPS 37 · LOOP

The loop

The three loops I use in Claude Code: the site after a deploy, the tests on the main branch and the reply you're waiting for. With the texts to copy and how to stop them.

What it is and why it matters

/loop is a Claude Code command that repeats a task on its own, inside the session you have open. You tell it how often and what to do, and it comes back to it until you stop it, for seven days at most.

The problem it solves is checking by hand. You do a deploy and every so often you open the site to see if it works. You wait for the App Store review and keep opening your email. With a loop Claude does the looking, and you work on something else.

But what makes it useful is something else: I ask it to write to me only if something changes. A loop that says “all good” every five minutes is noise, and after an hour you stop reading it. One that stays quiet until something happens, you listen to when it speaks.

It isn't a routine. The loop lives in the session: it starts in a moment, but it stops when you close the terminal. You'll find the routines that run even with your computer off in the guide on routines.

1. How you write it

In a Claude Code session you type /loop, then the interval, then the task. Like /loop 5m followed by what to check.

  • The interval is a number with a unit: s for seconds, m for minutes, h for hours, d for days. So 5m, 1h, 1d.
  • The shortest step is one minute: seconds are rounded up to the minute.
  • If you pick an odd interval, like 7m or 90m, Claude rounds it to the nearest one it can schedule and tells you which one it picked.

When you launch it, Claude confirms how often it will run. From then on the task starts again by itself, in the same conversation. So on the next round it knows what it saw on the round before, and that's why it can tell you whether something changed.

Without an interval

If you type /loop and then the task straight away, without an interval, Claude decides the pace. After each round it picks how long to wait, from one minute to one hour, based on what it saw: a short wait if something is about to happen, longer if everything is still. At the end of each round it tells you how long it's waiting and why. And when the task is done, it can close the loop on its own.

2. The three loops

You copy them as they are. Only change the parts in [ ].

The site and the deploy

I launch it right after a deploy, or when I've changed something on the server and I don't trust it.

The prompt
/loop 5m open [site address] and check that it responds. If it doesn't respond or gives an error, read the logs of the last deploy and tell me what went wrong and what you suggest. Don't change anything without asking me. If everything is the same as before, don't write anything.

The last three sentences are the ones that matter. “Read the logs of the last deploy” tells it where to look. “Don't change anything without asking me” stops it from fixing the server on its own. “Don't write anything” keeps it quiet when everything is fine.

To read the logs, Claude has to be able to reach them from the session: with your hosting's command-line tool or with a connector. If it can't reach them, the loop only checks that the site responds. And every five minutes is a lot of rounds: keep it short, it should do one thing only.

The tests on the main branch

I need it when changes land on main that I didn't make at that moment: another Claude session, a collaborator. Every hour it pulls what's new and runs the tests again.

The prompt
/loop 1h pull the latest changes from the main branch and run the tests. Write to me only if a test that used to pass now fails: which one, which change broke it and the fix you suggest. Don't touch the code.

“Only if a test that used to pass now fails” is the filter: you don't need to hear every hour about a test that's been broken for days, you need to know what broke just now. “Don't touch the code” leaves the decision to you: it finds and suggests, you choose.

One thing to know: this loop pulls the changes into the folder you're working in. If you have files left half done, save your work first, or run it in a separate copy of the project.

The reply you're waiting for

For example the App Store review. Here I don't set the interval: I don't know when the reply will come, so I let Claude choose the pace. When the reply arrives, it tells me what to do and closes the loop.

The prompt
/loop check [where the reply arrives: the connected email, the status page] whether the reply about the review of [app name] has arrived. When something changes, tell me what it says and what I need to do, then close the loop.

Claude has to be able to see the place where the reply arrives. If it's email, your inbox has to be connected to the session with a connector. If it's a status page, it has to be able to open it. Before launching the loop I ask it once by hand:

The prompt
Can you see [where the reply arrives]? Tell me what's there right now, without changing anything.

3. How to stop it

A fixed-interval loop keeps going until you cancel it, or until seven days have passed. To cancel it you just ask in plain words. First ask for the list:

The prompt
what scheduled tasks do I have?

Claude shows you the active tasks, with how often they run and the task. Then you tell it which one to remove:

The prompt
cancel the deploy check

A loop without an interval, while it's waiting for the next round, you stop with Esc: the pending round is dropped and the loop doesn't start again. The fixed-interval ones, on the other hand, stay, and you cancel them by asking as above.

4. Before you leave it running

It only runs with the session open

The loop only runs while Claude Code is open and the computer is on. Close the terminal and it stops. If a round comes up while Claude is busy, it waits; and it doesn't make up for missed rounds: as soon as Claude is free it does just one.

If you close the session and then pick it up again with claude --resume or claude --continue, the fixed-interval loops come back, if they haven't expired. The ones without an interval don't: you launch them again with /loop.

It lasts seven days at most

Every loop lasts at most seven days from when you created it, the one without an interval too: it runs one last round and deletes itself. It's there so a forgotten loop doesn't keep running. If you need it longer, launch it again before it expires.

It uses the session's permissions

The loop has the same permissions as the session you launch it in. If on some round Claude has to use a command it usually asks you to approve, it stops there and waits for you. That's why I watch the first round and approve what it needs, like the command that runs the tests.

With the computer off you need something else

For things that have to run with the computer off there's /schedule: it creates a routine in Anthropic's cloud. You need to be signed in with your claude.ai account and have the project on GitHub, and it runs at most once an hour. I explained how to set it up in the guide on routines.

Common mistakes

  • Not telling it when to stay quiet: every round it writes “all good” and you stop reading. Always write “write to me only if something changes”.
  • Letting it fix things on its own: while you're not looking it can change the server or the code. Add “don't change anything without asking me”.
  • Closing the terminal and thinking it keeps going: the loop lives in the session. For something that runs with the computer off, use /schedule.
  • Sending it to look at a place it can't see: the loop runs for nothing. First ask it once by hand whether it can get there.
  • Walking away on the first round: if Claude needs to ask you for a permission, the loop sits there waiting for you. Watch the first round and approve what it needs.
  • Forgetting the expiry: after seven days the loop deletes itself. If you still need it, launch it again before then.

Checklist

  • Interval with its unit: 5m, 1h, 1d
  • Parts in [ ] changed
  • “Write to me only if something changes” in the prompt
  • “Don't change anything” in the prompt
  • Claude can reach the logs, email or status page
  • First round watched, permissions approved
  • Noted when the seven days run out

Frequently asked questions

Can I use the session while the loop is running?

Yes. The loop fires between messages: if a round comes up while Claude is working for you, it waits for it to finish. But the rounds end up in the same conversation, so the shorter the prompt and the quieter it stays when there's nothing to say, the better.

What if I need a check just once?

You don't need /loop. Write it in plain words, like “in 45 minutes, check whether the tests passed”: Claude schedules a single check, which deletes itself after it runs.

← All guides