Skip to content
·12 min read

Loops, Stop Hooks, and Scheduled Agents in Claude Code

How the team uses cron-scheduled and looping agents to keep Claude running for hours and days

Share

I feel like loops are the future. If you haven't played with it, I strongly recommend.

Boris ChernyCreator, Claude CodeSequoia AI Ascent 2026

He was describing the dozens of cron-scheduled Claude Code agents he runs for PR maintenance, CI health checks, and feedback aggregation. This is the pattern that takes Claude Code from a session you sit in front of to a process you check on later.

Sid Bidasaria, also at Anthropic, recently mentioned that a gnarly refactor he ran with the new /goal command went for 14 hours straight. That is the new shape of the work. The interesting question is no longer how fast Claude responds, but how long it can keep going without you.

Stop Hooks, The Mechanism That Started It All

Stop hooks are the underlying primitive that makes everything else in this article possible. The idea is simple. After every model turn, Claude Code calls your hook. Your hook decides whether the model is allowed to stop. If your termination condition is not met, the hook returns a non-stop signal and Claude keeps working.

Boris described the canonical example on the Every / AI & I podcast:

If the tests don't pass, keep going. Essentially you can just make the model keep going.

Boris ChernyCreator, Claude CodeEvery / AI & I podcast

The hook reads the test output, checks for failures, and either lets Claude stop or sends it back to fix the next failing assertion. No human in the loop. No "are we done yet?" prompts.

The results compound. In a late December 2025 post on Threads, Boris noted that once you have stop hooks wired up properly:

Claude consistently runs for minutes, hours, and days at a time.

Boris ChernyCreator, Claude CodeThreads, December 2025

Erik Schluntz makes the same point about minimal scaffolding:

Give it some tools that it can call and it's able to keep calling the tools, keep thinking, until it thinks it's done.

Erik SchluntzEngineer, AnthropicSequoia AI Ascent 2026

You do not need a complicated agent framework. You need a tight loop with a clear exit condition.

Key Takeaway

Stop hooks turn Claude Code from a turn-by-turn assistant into an autonomous loop. Combined with rules-based verification, this is what makes Boris's "100% of my code is Claude-written" possible. The human role is shaping the rubric, not approving each step.

The leap from "Claude finishes a task" to "Claude keeps going until a condition is satisfied" is bigger than it sounds. Once you accept that the model can run unsupervised against a clear rubric, you start designing your work differently. The interesting question stops being "what should Claude do next" and starts being "what does done look like, and can a script tell me when we are there."

/loop, Cron for Claude

Boris announced /loop on March 7, 2026 with a perfect one-liner example:

/loop babysit all my PRs. Auto-fix build issues and when comments come in, use a worktree agent to fix them.

Boris ChernyCreator, Claude CodeX, March 2026

Read that twice. He is not asking Claude to fix one PR. He is asking Claude to maintain all of them, indefinitely, dispatching worktree-isolated subagents per PR as new comments arrive.

This is essentially cron for Claude, except the agent decides what to do each tick. A traditional cron job runs the same script every interval. A /loop agent wakes up on a schedule, looks at the current state of the world, and decides what work is worth doing now. Some ticks it has nothing to do. Other ticks it spawns three worktree agents in parallel because reviewers left comments overnight.

The shift Boris described at Sequoia is that he runs dozens of these. One loop watches CI health. Another aggregates feedback from internal Slack channels. Another keeps dependency PRs unstuck. Each one is small. Together they replace the rolling background work that a maintenance engineer would otherwise spend half their week on.

The pattern matters more than the specific command. Even before /loop shipped, you could build the same thing with a shell while loop, headless Claude invocations, and a sleep statement. What changed in March 2026 is that the team made it a first-class primitive with proper subagent isolation, log persistence, and a way to attach a stop condition that is more flexible than "did the tests pass."

EXPLAINER DIAGRAM: A 24-hour clock face shown as a horizontal timeline. Along the timeline are six different colored bars showing scheduled agent runs at different intervals. Top bar (teal) labeled HOURLY: BABYSIT PRS spans the full timeline with tick marks every hour. Second bar (golden) labeled EVERY 4 HOURS: CI HEALTH CHECK has six tick marks. Third bar (coral) labeled DAILY 6AM: FEEDBACK AGGREGATION has one tick. Fourth bar (violet) labeled DAILY 5PM: DEPLOY DIGEST has one tick. Fifth bar (pink) labeled WEEKLY MONDAY: DEPENDENCY UPDATES has one tick. Sixth bar (emerald) labeled ON-DEMAND: AS NEEDED has scattered marks. Caption below: BORIS RUNS DOZENS OF THESE.
Cron-scheduled Claude Code agents handle the maintenance work that used to require dedicated time blocks.

If you have never set one up, start with the smallest possible loop. Pick one repetitive thing you do at the same time every day, write the success condition as a single sentence, and let Claude run it on a schedule for a week. The boring discovery is that most maintenance work fits this shape.

Routines, Schedule Claude From Anywhere

A month after /loop, Cat Wu shipped Routines:

Routines, kick off Claude Code on a schedule, from GH events, from other APIs.

Cat WuHead of Product, Claude CodeX, April 2026

The /loop primitive is local to your machine and works on time intervals. Routines is the more general external trigger model. You can schedule a Claude Code run from a cron expression, but you can also trigger it from a GitHub webhook, a Linear status change, a Stripe event, or any HTTP call.

The reframing matters. /loop is "Claude on a timer." Routines is "Claude as an event handler." You are no longer just polling for work. You are reacting to it. A new issue is opened, a Routine wakes up Claude with the issue context and the standard triage checklist. A deploy completes, another Routine runs a smoke test and posts the result. The cost per trigger is small because Claude only runs when something actually happened.

Cat's longer view is even more telling. In a TechCrunch interview the next month she pointed to where this all leads:

The next big thing is proactivity. Claude understands what you work on, and just sets up some of these automations for you.

Cat WuHead of Product, Claude CodeTechCrunch, May 2026

The endpoint is not just that you can schedule Claude. It is that Claude proposes the schedules. Looks at your repo, notices that nobody is triaging stale issues, and offers to set up a Routine that does it.

See the team's playbook

We're publishing a deep-dive series on how Anthropic engineers actually use Claude Code.

Browse our Claude Code coverage

The practical thing to know today is that the two patterns coexist. /loop is great for things tied to a local working tree where worktree agents need to mutate files in your repo. Routines is great for orchestrating Claude across external systems where the trigger is some service emitting an event. Most serious users end up with a small constellation of both.

/goal, When You Need a 14-Hour Refactor

On May 13, 2026, Sid Bidasaria introduced /goal:

Long-horizon refactor mode. A gnarly refactor I did yesterday ran for 14h straight.

Sid BidasariaFounding Engineer, Claude CodeX, May 2026

The example matters. A 14-hour run is not interactive coding. It is overnight work where you describe the destination, set up a verification script, and come back in the morning.

The use case is specific. /goal is for work where the success rubric is clear but the path is long. Migrating a codebase from one ORM to another. Replacing a deprecated logging library across hundreds of files. Splitting a monolith package into three smaller ones. Each step is small. The total surface is huge. A human review at every step would multiply the wall-clock time by ten and contribute very little, because the human is just confirming what the rubric already confirms.

This connects back to a concept Thariq Shihipar at Anthropic described in early April:

One of my favorite concepts is the idea of defining outcomes where the agent will work until the rubric is satisfied.

Thariq ShihiparEngineer, Claude Code + Agent SDKX, April 2026

That is precisely the shape of /goal. You are not writing a prompt. You are writing a definition of done. Claude works against that definition for as long as it takes. Hours. Days. Whatever the rubric demands.

EXPLAINER DIAGRAM: Three columns showing different timescales of Claude work. Column 1 header SESSION (5 MINUTES TO 1 HOUR) with icon of a single arrow loop and label PROMPT TO RESULT. Column 2 header STOP HOOK LOOP (1 HOUR TO 1 DAY) with icon of three stacked loop arrows and label RUNS UNTIL TESTS PASS. Column 3 header GOAL OR ROUTINE (DAYS) with icon of a clock + arrow loop and label RUNS UNTIL RUBRIC SATISFIED. Below each column is a small icon: Column 1 shows a coffee cup labeled YOU WAIT. Column 2 shows a laptop with a checkmark labeled YOU CHECK IN. Column 3 shows a phone labeled YOU CHECK TOMORROW. Teal arrows connect the columns left to right with the label INCREASING AUTONOMY.
Three tiers of Claude Code autonomy, each with a different rhythm of human supervision.

The thing nobody tells you is that the hard part of /goal is not the running, it is the rubric. A bad rubric ("the code should work") will burn 14 hours of compute and leave you with subtly broken refactors. A good rubric is mechanical and falsifiable. The full test suite passes. The new module passes the old module's golden snapshots. The bundle size is within five percent of baseline. The build succeeds on three target platforms. If your rubric is checkable by a script, /goal can deliver against it. If your rubric is "vibes," it cannot.

Common Mistake

Scheduling a Claude agent without a clear termination signal. A loop without a stop condition burns tokens forever and produces nothing useful. The team's pattern is always: define the rubric (tests pass, screenshot matches, no open issues), then start the loop.

Sid's 14-hour refactor worked because every iteration had a clear verification step that either advanced the work or signaled failure. The model was never guessing whether it was done. It was running checks, getting structured results, and looping.

When to Use Which Pattern

The decision tree is short. Short interactive work goes in a plain Claude Code session, because the human in the loop is the fastest verifier you have. Work that has a clear pass-fail signal (tests pass, type checker is clean, snapshot matches) goes in a stop hook loop, where Claude iterates until the signal flips green. Recurring maintenance work goes in /loop or Routines, where the trigger is time or an external event. Long-horizon work with a stable goal goes in /goal, where the rubric defines done and the path is whatever the model figures out.

The interesting middle case is termination logic that is fuzzier than a unit test but more rigorous than vibes. Thariq has been experimenting with prompt-based stop hooks since November 2025:

Sends hook input to Haiku to decide continue/stop.

Thariq ShihiparEngineer, Claude Code + Agent SDKX, November 2025

You forward the model's last response and the task definition to Haiku and let a cheaper model judge whether you are done. This is the bridge between mechanical rubrics ("did the tests pass") and judgment-based ones ("is this PR description good enough to ship").

The combinations get interesting fast. A /loop that, on each tick, spawns a /goal-style agent against any PR with unaddressed review comments, with a Haiku-judged stop hook deciding whether the comments are actually addressed. That is roughly the shape of Boris's "babysit my PRs." It is not exotic. It is just three primitives composed.

What This Means For You

  • If you're a founder: Scheduled agents replace a meaningful chunk of the assistant or contractor hours you currently spend on routine maintenance. Triage, dependency updates, weekly digests, deploy monitoring. Pick one, write the rubric, and put it on /loop or a Routine. You will get the hours back.
  • If you're changing careers: The skill that is suddenly valuable is writing the success rubric, not the implementation. Practice describing tasks as "done when X is true, where X is checkable by a script." This is the language of modern AI-assisted engineering, and it is a teachable skill that does not require knowing every framework.
  • If you're a student: Start with one /loop on your homework or a side project. Have Claude run your test suite every fifteen minutes during a study session and ping you when something breaks. The habit of working with a background agent teaches itself within a week, and once you have the muscle, every other pattern in this article becomes obvious.
From sessions to loops

Three patterns the Claude Code team uses every day. Pick the one that fits your work.

See the team's playbook
PJ
Pranay Joshi

20+ years building products at scale. VP of Product & Engineering, startup founder, and AI coach. Helping dreamers turn ideas into reality with vibe coding.

The Tuesday Shipping Report

Every Tuesday, one focused email:

  • - The tool or technique that's actually working right now
  • - A real problem from the community (and how to solve it)
  • - What changed this week in the vibe coding landscape

Read by 1,000+ founders, developers, and creators building with AI. Free forever. No spam.