Tutorial · 01 · AI & Tools

Claude Code
loops,
explained.

Loops are what took Claude Code from "assistant" to "agent that works for me 24/7." I'll walk you through how they work, when to use them, 4 real use cases (one of them for non-devs), and what they actually cost.

7 min read Level Beginner Tools Claude Code
Jérémy Sagnier Jérémy Sagnier · I test AI every day · I share what actually helped me Published · Updated April 20, 2026
In 30 seconds

What you'll learn

  • What a Claude Code loop is — and why it's not a plain old cron
  • The difference between a timed loop (every X minutes) and a dynamic loop (Claude decides)
  • 4 real use cases (one of them for non-devs) that you can put to work today
  • What it costs: 3 scenarios with real numbers, and the $50/day trap to avoid

Brand new to AI?

If some of the terms lose you (Claude Code, terminal, agent, MCP, skill…), start with the beginner guide first and keep the glossary open in another tab. You'll come back here with the basics down.

— Before we start

What's a loop?

A loop is a command that tells Claude Code: "Re-run this action for me at regular intervals." You start a loop, and Claude re-runs the command on its own while you do something else.

Think of a cron job (a scheduled task that re-runs itself at a fixed time on your computer), but way smarter. A cron fires off a dumb script. A Claude loop can decide whether to re-run, whether to change its approach, whether to alert you — it understands what it's doing.

Important: the loop runs as long as your session is open

A /loop is tied to your Claude Code session. If you close your terminal or your Mac, the loop stops. To have it genuinely run overnight (Mac off), you need Routines (Anthropic's cloud feature — in other words, a task that runs on Anthropic's servers instead of your computer, released in April 2026) — more on that below.

Why this changes everything for me

I used to manually check my watch feeds 3 times a day. Now a loop runs, pings me when it finds something interesting, and I don't lose a single second. It's the simplest, most powerful AI automation I know.

— The two modes

Timed vs Dynamic.

Claude Code offers two kinds of loops. It matters that you understand the difference — it changes everything depending on your use case.

Timed loop versus Dynamic loop Side-by-side comparison: Timed loop (regular 5-minute intervals, fixed cost of 0.4 euros per hour) versus Dynamic loop (irregular intervals decided by Claude, variable cost of 0.1 to 0.8 euros per hour). TIMED LOOP Regular intervals · predictable 0 5m 10m 15m 20m /loop 5m /veille-ia FIXED COST €0.4 per hour DYNAMIC LOOP Claude decides when to re-run 0 30s 2m 7m 27m /loop /monitor-deploy VARIABLE COST €0.1 – €0.8 per hour · by context REGULAR + PREDICTABLE vs ADAPTIVE + CONTEXTUAL
Timed = regular, predictable. Dynamic = Claude decides when to re-run. The cost follows the pattern.
01

Timed loop · Fixed interval

You set a duration. Claude re-runs each time. Simple, predictable, perfect when you want to check a status on a steady cadence.

/loop 5m /veille-ia

Here, every 5 minutes, Claude re-runs your /veille-ia command. You can set 2m, 1h, 6h, and so on. Note: intervals in seconds (30s) are rounded up to the next minute — the real minimum is 1 minute. And every loop expires automatically after 7 days (official Anthropic docs · scheduled tasks) — a guardrail against forgotten loops.

02

Dynamic loop · Claude decides

You start the loop without specifying an interval. Claude reads the context and picks for itself when to re-run. Smarter, less predictable.

/loop /monitor-deploy

If your deployment just kicked off, Claude will re-run every 30 seconds. If it finished 20 minutes ago, it might wait 20 minutes before the next check. It self-adjusts.

Mind the prompt cache (5 min)

Anthropic's prompt cache (a mechanism that "holds your prompt in memory" so you don't pay for it on every call) has a 5-minute lifespan, refreshed on every successful call. As long as your loops run less than 5 minutes apart between two calls, the cache stays warm and you pay for the cached tokens (the "text bricks" the AI bills you for · roughly 0.75 words each) at about -90%. Beyond that, the cache drops and you pay full price again. Stay under 5 minutes (4m30s, 3m, etc.) if you want the cache benefit, or accept the cache miss (the "missed cache" that makes you pay full price again) beyond that. Official details · Anthropic prompt caching docs.

— Session, machine, or cloud

3 ways to automate.

Not all loops are created equal. Depending on what you want (computer on or off, truly overnight or not), Claude Code offers three mechanisms. Most of the time, people reach for /loop by default when they actually need a cloud Routine. Here's the difference. If you want to compare with other looping AI-agent approaches outside the Anthropic ecosystem, also look at Cursor (an in-IDE chat agent) or n8n (self-hosted visual workflows) — each has its trade-offs.

Mechanism Session open? Mac on? Best for
/loop (session) Yes, required Yes You're working with Claude and want it to check a status in the background
Desktop scheduled tasks No Yes You want your Mac to work during the day while you're in a meeting
Routines (cloud) No No Watching that runs overnight, on weekends, while you're on vacation

My advice

For a watch or a monitor that truly needs to run 24/7, use Routines (released in April 2026). Quotas: 5 routines/day on Pro, 15 on Max, 25 on Team. For anything that's "while I'm working on something else," /loop is plenty.

— My 4 use cases

What I actually do with them.

I'll share the 4 loops I run day to day. Copy-paste, adapt to your case.

Case 00 · For non-devs

A beta reader that rereads your sales page all day long

No code, no build, no deployment to watch? No problem — loops are for you too. You start a loop that rereads your landing page (or your email, your sequence, your video script) every hour, and you get a mini-audit on each pass. Keep it or skip it, your call.

/loop 1h "Reread my landing page landing.md
and give me 3 priority improvements
based on Hormozi copywriting rules."

Cost: about $0.5/day if you let it run over an 8-hour workday. Perfect for iterating while you do something else.

Case 01 · My auto AI watch

An AI brief that lands while I sleep

Every morning, I want a summary of the 10 most important AI releases from overnight. I write a watch prompt (the instruction you give the AI in words), run it in a loop every 4 hours, and get the digest the moment I'm free.

/loop 4h "Scan the last 50 releases across my 10 AI sources.
Summarize the 5 most important. Bullet format + links."

Tip: I store the result in a file with a timestamp so I have a history.

Case 02 · Build/deploy monitoring

I deploy, Claude watches, I come back when it's ready

After a push, I start a loop that checks the deployment status every 2 minutes. When it's ready (or if it crashes), Claude alerts me in the console.

/loop 2m "Check the status of the latest Vercel deploy.
If succeeded, tell me OK. If failed, show the error."

The upside: I can close the Vercel tab and go back to my code — Claude keeps me posted.

Case 03 · Auto proofreading a long article

A beta reader that rereads me every hour

When I write a long article over several days, I start a loop that gives me a critical reread every hour. It flags the redundancies, the fuzzy passages, the AI-ish phrasing.

/loop 1h "Reread /tmp/article-en-cours.md.
Flag the 3 passages I should rework first."

Used together with the skill humanizer to keep my text from sounding too "ChatGPT."

— In real life, concretely

What does a running loop look like?

That's the question everyone asks me. "OK, but I can't see anything — what's happening while it runs?" Here's a typical example of what I get in my console when my watch loop does its 7th pass of the day:

[14:32] Loop #veille-ia — run 7
Scanned: 42 articles, 5 X threads, 3 GitHub repos
Notable news: Anthropic ships "Claude Projects API"
  → could replace 3 internal workflows
No change on the other 4 topics tracked
→ ping sent to Slack #veille

When there's nothing new, the loop still runs, just tells you "nothing to report," and moves on. When it finds something, it alerts you (Slack, email, console, whatever you want). That's where the power is: 95% of runs are silent, but the 5% that matter show up without you having to lift a finger.

— The awkward question

How much does it cost?

That's the second question I get asked all the time — and honestly, it's the right one. A badly configured loop can blow up your bill overnight. Here are 3 scenarios with real numbers so you know what you're paying.

01

1 light loop · ~$1 to $2/month

A watch that runs 4 times a day, roughly 3,000 tokens per run (a short prompt + a summary). You won't feel the bill. That's my first piece of advice when you're starting out: begin with ONE loop, on a topic that genuinely helps you.

02

3 active loops · ~$8 to $15/month

AI watch + deploy monitoring + article proofreading. 3 loops with medium prompts (5 to 8k tokens per run). That's my current setup. At this level, you start to feel the ROI (Return On Investment — in plain terms, what you get back for what you put in) — you save 30 min to 1 hour a day, more than paid for.

03

The trap to avoid · $50 to $80/day

You set /loop 1m "do X" just to "see what happens," you leave your session open, you forget about it. 1,440 runs in 24 hours. If your prompt is 10k tokens, you can hit $50 to $80/day depending on the model. Read "Trap 1" below before you launch anything.

My straight advice

Turn on the spending cap on your Anthropic account (Settings → Billing → Usage limits). Set $20/month to start. You'll quickly know whether you need to raise it — and you won't wake up to a $300 bill.

Two commands I use all the time: /cost in your session shows you live how much you've spent since the start. And /model haiku switches to Anthropic's cheapest model: perfect for simple loops (checking a status, reading an email), it cuts the bill by about 10x.

— What I've learned

The 3 traps to avoid.

Trap 1 · Setting the interval too short

Beginner's temptation: /loop 1m (the allowed minimum). Result: 60 calls (each call = a question sent to the AI, so a billed one) an hour, a bill that blows up, and 95% of the calls bringing nothing new. My personal rule: never below 2 minutes, unless it's a real emergency.

Trap 2 · Forgetting the failure states

If your loop watches a build and your filter only catches success, you miss every crash. Always write: "If succeeded → OK · If failed → error · If cancelled → canceled · If anything else → alert". Cover all 4 cases.

Trap 3 · Starting a loop and forgetting it

A forgotten loop = a bill running silently. I keep a little ~/loops-actifs.md file where I note every loop I launch along with its goal. To stop a loop: press Esc in your session, or just tell Claude "stop the running loop." Good news: every loop also expires on its own after 7 days (official Anthropic docs), so you can't leave it running forever by accident.

My checklist before starting a loop

(1) Is the interval reasonable? (2) Does my filter cover every failure case? (3) Did I note the loop somewhere so I don't forget it? → If yes to all 3, GO.

— Going further

You want to master this.

Loops are just the beginning. If you really want to run Claude Code as an agent, here are my next steps:

  1. Claude Code workflow tips — how I structure my sessions and prompts so Claude really works for me (and not the other way around).
  2. The Superpowers plugin — the add-on that unlocks parallel sub-agents, driven TDD, and advanced patterns.
  3. Dev-browser, the AI-driven browser — the tool I often pair with a loop so it can verify, scrape, or screenshot while I do something else.
  4. Custom skills — building your own reusable "job" (like veille-ia, cold-email). See my Claude Code pack.
  5. settings.json hooks (the "triggers" you configure in Claude Code's settings file) — making Claude automatically fire an action at the end of every session (log, commit, Telegram notification).

What are "parallel sub-agents"?

When you tell Claude "run this in parallel," it can spin up several "mini-Claudes" that work at the same time on different tasks. Like hiring 5 interns for the same hour instead of one for 5 hours. You pay the same total, but you go 5x faster.

Each topic = a future article here. If you want a heads-up when I publish, the newsletter sign-up is at the bottom.

— Frequently asked questions

FAQ Claude Code loops.

What's the difference between a loop and a cron?

A cron blindly runs a script at a fixed time without understanding the result. A Claude Code loop can decide whether to re-run, change its approach, or alert you based on what it sees. The loop is smart; the cron is mechanical.

Does a loop work when my Mac is off?

No. A /loop in a Claude Code session stops the moment you close your terminal or your Mac. To truly run 24/7 (overnight, on weekends, on vacation), go through Anthropic's cloud Routines, released in April 2026.

How do I stop a running loop?

Three options: press Esc in your session to stop the run, just tell Claude "stop the running loop," or wait 7 days — every loop expires automatically after that (a native Anthropic guardrail).

How much does it cost per month?

Three ballparks: €1 to €2/month for a light loop (3,000 tokens, 4 runs/day), €8 to €15/month for 3 active loops (my setup), and up to €50-80/day if you fire off /loop 1m on a heavy prompt and forget about it. Turn on the Anthropic cap at €20/month to start.

Does the loop work with the free API?

Loops are a command inside Claude Code (the CLI), not the web API. You get to them with your subscription (free with limits, or paid Pro/Max). The Anthropic API lets you hack together your own looping system, but that's not the same product as /loop.

What's the minimum interval for a loop?

1 minute. Intervals in seconds (30s) are rounded up to the next minute. My personal rule: never below 2 minutes unless it's a real emergency, otherwise you rack up 60 pointless calls an hour.

How does the prompt cache work inside a loop?

The cache keeps your prompt in memory for 5 minutes, refreshed on every successful call. As long as your loops run less than 5 minutes apart, you pay for the cached tokens at about -90%. Beyond that, the cache drops and you pay full price again. Stay under 5 minutes to optimize.

Do Routines fully replace /loop?

No, they complement it. /loop is still ideal when you're working with Claude and want a check in the background. Routines (cloud) is for when things need to run without your Mac on: overnight watching, weekend monitoring. Quotas: 5/day on Pro, 15 on Max, 25 on Team.

Can you run a loop on ChatGPT or Cursor?

The native /loop is specific to Claude Code. On Cursor or ChatGPT, there's no built-in equivalent — but you can reproduce the pattern with a cron + a call to the model's API, or with an n8n workflow that calls the API on a schedule. More boilerplate, same result.

How do I get a notification when a loop finds something?

Three channels: the Claude Code console (the default), email via the Resend API (for calm alerts), Slack via webhook (for urgent ones). You tell Claude "if you find X, ping me on Slack #watch" and it wires the webhook call into the loop.

Did this article help? Say so.

Spotted a mistake?

Outdated info, a number that's moved, a stale source? Write to me at sagnier.jeremy@gmail.com · I fix it within 48h max and note the update date at the top of the article. Feedback from the field is worth a thousand times more than the articles — I read everything, I reply.

Jérémy Sagnier
Thanks for reading this far 👋

Shall we keep going?

I test AI for real and share what works, no jargon, no hype. If this article helped you, the easiest way not to miss anything is my Friday letter. And if you've got a question or a doubt: reply to me, I read everything.

Get the newsletter → Read more articles