ModulesPhase 3: Working at scale

12. Automation

/loop/schedule/goal
The 30-second answer

"Claude Code can keep working without you typing each step, and the right tool depends on what should start the next run. /loop reruns a prompt on a timer while your session is open, either on a fixed interval or at a pace Claude picks. /goal keeps Claude working turn after turn until a separate model confirms a condition you wrote is true. /schedule creates a cloud scheduled task, formerly called a routine, that runs in Anthropic's cloud on a schedule, an API call, or a GitHub event, with your laptop closed. And claude -p runs Claude as a plain command, so a script or a CI job can call it and check the exit code."

The architect's follow-up: session-scoped automation dies with the session, so anything that must run reliably belongs in the cloud or in CI.

Say it yourself first, then compare.
See it

8 pictures, in order.

Use the arrow keys or the dots. Tap a picture to see it full size.

Pick by what starts the next run1 of 8
Know it

The facts someone can check.

Pick by what wakes Claude up
You want it to run Use Where it runs Stops when
Every few minutes while you work /loop This session, your machine You cancel it, Claude decides it's done, or 7 days pass
Until something is true /goal This session, turn after turn The evaluator says met or impossible, an error you must fix, or /goal clear
On a calendar, laptop closed /schedule (cloud task) Anthropic's cloud, fresh clone You turn it off
On a calendar, with local files Desktop scheduled task Your machine, app open and awake You turn it off
From a script or CI claude -p Wherever the script runs The run ends; the exit code tells the script
After every turn, by your own rule A Stop hook Settings, every session in scope Your script decides
/loop: three ways to call it
  • /loop 5m check the deploy: a fixed interval. Claude turns it into a cron job. Units are s, m, h, d; seconds round up to a minute, and odd intervals like 7m round to the nearest clean one. To stop it, ask Claude to cancel it. Esc doesn't stop a fixed loop.
  • /loop check the deploy: self-paced. After each pass Claude picks a wait between 1 minute and 1 hour, short while something is moving and long when it's quiet. Esc stops it, and Claude can end it itself once the work is done.
  • /loop alone: the built-in maintenance prompt. Finish unfinished work, tend this branch's pull request, then cleanup passes. It doesn't start new initiatives. A loop.md file (.claude/loop.md, or ~/.claude/loop.md) replaces this default; the first 25,000 bytes are read.
  • You can loop a skill: /loop 20m /review-pr 1234. Built-in commands like /clear arrive as plain text instead of running.
  • Limits: 1 minute shortest interval, 50 scheduled tasks per session, and recurring tasks expire after 7 days.
  • Tasks fire between turns, never mid-reply. There's no catch-up; a missed time fires once. Closing the session stops them, but /bg carries them into a background session.
Scheduled times are approximate

To keep every session from hitting the API at the same instant, Claude Code shifts each task's start. A recurring session task starts late by up to half its interval, capped at 30 minutes: 0 to 5 minutes late for every 10 minutes, 0 to 15 for every 30, 0 to 30 for hourly or daily. /loop 5m is the exception: it runs 15 seconds early each time. A one-shot task set for :00 or :30 can fire up to 90 seconds early. Session tasks use your local time zone.

Cloud, Desktop, or /loop?
Cloud (/schedule) Desktop /loop
Machine must be on No Yes Yes
Session must be open No No Yes
Local files No, fresh clone each run Yes Yes
Permission prompts Auto mode by default Set per task Same as the session
Shortest interval 1 hour 1 minute if Claude sets it, 1 hour in the form 1 minute

Desktop tasks only run while the app is open and the computer is awake. If it slept through a run, Desktop starts one catch-up run on wake for the most recent miss in the last 7 days.

Cloud scheduled tasks (formerly routines)
  • A task is a saved prompt, one or more repositories, connectors, and an environment. Each run is a full Claude Code session in Anthropic's cloud.
  • Triggers: a schedule (hourly, nightly, weekly, custom cron, or once), an API call with the task's bearer token, or a GitHub event (pull request, release, issue). One task can have several.
  • /schedule creates a task with a schedule trigger, and also handles list, update, and run. The alias is /routines. API triggers are set up on the web only.
  • Runs start in auto mode, clone each repository fresh, and push to claude/ branches unless the prompt says otherwise.
  • A bare five-field cron on a cloud task is read as UTC. Anything more often than hourly is rejected.
  • Limits: 100 scheduled runs an hour per account; 30 "run now" and API fires an hour per task. If the GitHub connection lapses, runs skip for up to 72 hours, then the task turns off.
  • Research preview, on Pro, Max, Team, and Enterprise. Owners can turn it off for the whole organization.
/goal: work until a condition holds
  • /goal <condition> starts working immediately. After every turn, your configured small fast model reads the condition and the conversation and returns not yet met (keep going), met (goal clears), or impossible (goal clears, logged as failed).
  • Under the hood it's a session-scoped, prompt-based Stop hook. That's why /goal follows the same workspace trust rule as hooks, and is unavailable when hooks are disabled.
  • The evaluator calls no tools. It only sees what Claude has already shown in the conversation, so write a condition Claude's own output can prove: "all tests in test/auth pass and npm test exits 0".
  • One goal per session, up to 4,000 characters. /goal alone shows status (turns, time, tokens, last reason). /goal clear removes it.
  • It doesn't change your permission mode. For unattended goal turns, run it in auto mode: auto mode removes per-tool prompts, /goal removes per-turn prompts.
  • An error you have to fix (authentication, credit balance, context overflow, missing model) clears the goal. Other errors retry up to 3 times or pause it.
  • claude -p "/goal ..." runs the whole loop in one non-interactive call.
Headless mode: claude -p
  • claude -p "prompt" runs once and exits: 0 on success, non-zero on failure. It reads stdin (up to 10 MB), so you can pipe a log or a diff in.
  • --output-format is text, json (a result, a session ID, and an estimated cost), or stream-json. Add --json-schema for output in a shape you define.
  • From v2.1.302, a -p run starts in Manual mode, so anything needing approval is denied unless something approves it. Pre-approve tools with --allowedTools, set a baseline with --permission-mode (auto, dontAsk, acceptEdits), and use --permission-prompts none for jobs nobody watches.
  • --bare skips hooks, skills, plugins, MCP servers, auto memory, and CLAUDE.md, so the run behaves the same on every machine. It needs ANTHROPIC_API_KEY. The docs recommend it for scripts and say it will become the default.
  • The security point: without --bare, a -p run executes the repository's hooks and .mcp.json servers with no trust prompt.
Quiz

Answer out loud, then flip the card.

Mark each one honestly. Cards you miss stay flagged for review, in this browser.

0 of 8 right
Question 1

A developer set /loop 10m check CI and went home. Is it still running in the morning?

Only if the session is still open. /loop tasks are session-scoped: they stop when Claude Code exits. Running /bg before leaving moves the session, and its loops, into a background session that keeps going without a terminal, but it still needs the machine on. For anything that must run overnight with the laptop closed, use a cloud scheduled task (/schedule) or a CI job. Even an open loop expires after 7 days.

Question 2

When would you pick /goal over /loop?

When "done" is a condition, not a time. /loop reruns on a clock: good for polling a deploy. /goal keeps working turn after turn until a separate model confirms the condition, such as "every call site compiles and npm test exits 0". A goal is a work loop; a loop is a polling loop.

Question 3

A customer worries that /goal lets Claude declare itself finished. How does it actually decide?

It doesn't let the worker decide. After every turn, a separate small fast model reads your condition and the conversation and returns met, not met, or impossible. That evaluator calls no tools, so it judges only what Claude showed in the transcript, which is why a good condition names its own check ("npm test exits 0"). Bound it with "or stop after 20 turns" if needed.

Question 4

The team wants a nightly job that reviews yesterday's merged PRs and posts a summary. What do you set up?

A cloud scheduled task: /schedule every weekday at 9am, summarize yesterday's merged PRs. It runs in Anthropic's cloud from a fresh clone, so no laptop has to be on, and it can use connectors such as Slack. Two details: a raw five-field cron on a cloud task is UTC, and on-the-hour runs can start a few minutes late, so pick 9:07 rather than 9:00. If it needs files on someone's machine, a Desktop scheduled task instead.

Question 5

How do you call Claude from a CI pipeline, and what's the security risk?

claude -p "prompt" with --output-format json, branching on the exit code. Pre-approve only the tools the job needs with --allowedTools, or set --permission-mode dontAsk to deny everything else. The risk: without --bare, a -p run executes the repository's own hooks and .mcp.json servers with no trust prompt. In a pipeline that touches repos you didn't write, that's code execution. Use --bare and pass in exactly the settings and MCP config the job needs.

Question 6

A scheduled check is set for 9:00 but keeps firing around 9:20. Is it broken?

No. Claude Code deliberately shifts start times so sessions don't all hit the API at once. An hourly or daily session task can start up to 30 minutes late, and the delay is the same every run. If timing matters, a one-shot task should be set off the hour, and a cloud task at a time like 9:07.

Question 7

What's the difference between a cloud scheduled task and a routine?

Nothing. They're the same feature, renamed. The older name still shows up in the web address (claude.ai/code/routines), the /routines alias for /schedule, the API endpoint, and the organization toggle, labeled "Scheduled tasks (Was Routines)".

Question 8

How do you stop a loop that's running?

It depends on the kind. A self-paced loop (/loop with no interval) stops with Esc while it waits for its next pass, or Claude ends it when the work is done. A fixed-interval loop like /loop 5m ignores Esc; ask Claude to cancel it, and it'll delete the task by ID. Either way, a recurring task ends on its own after 7 days.

Traps

Wrong answers that sound right.

Before you tap, say why each one is wrong.

Try it

Three moves in a fresh project.

Facts checked against code.claude.com/docs/en/scheduled-tasks, routines, desktop-scheduled-tasks, goal, headless, best-practices, and commands on 2026-10-25. Claude Code ships fast: confirm anything that matters against the official docs.