Skip to content

Routines & Scheduled Tasks

Claude Code can run on a schedule, morning PR reviews, overnight CI failure analysis, weekly dependency audits. Routines run on Anthropic-managed infrastructure so they keep running even when your computer is off. Desktop scheduled tasks run on your machine with direct file access. /loop repeats a prompt within a session for quick polling.

Gnome mascot

What you'll learn

  • Routines run on Anthropic infrastructure, they keep running when your computer is off, and can trigger on API calls or GitHub events
  • Desktop scheduled tasks run on your machine with direct access to local files and tools
  • /loop repeats a prompt within a CLI session for quick polling

The problem

You want Claude Code to review every new PR at 9 AM, check for dependency updates every Monday, and sync documentation after every merge. You could run these manually, but scheduled automation is the whole point of having an agent, it should work while you don't.

Options & when to use each

Scheduling methodWhere it runsWhen it worksWhen to use
RoutinesAnthropic infrastructureEven when your computer is offProduction-grade recurring tasks, API/webhook triggers
Desktop scheduled tasksYour machineOnly when your machine is onTasks that need local file access, development workflows
/loopYour CLI sessionOnly while session is activeQuick polling, watching for changes
Cron (via claude -p)Your serverWhile server is runningSelf-managed infrastructure

Build it

Step 1: Create a routine

From the web, Desktop app, or CLI:

bash
/schedule

Follow the interactive prompt to set the schedule and task. Routines can trigger on:

  • Time schedules (cron-style)
  • API calls (webhook triggers)
  • GitHub events (PR opened, issue created)

Step 2: Desktop scheduled task

In the Desktop app, create a scheduled task that runs Claude Code on your local machine:

Every weekday at 9 AM: Review all open PRs in this repo and summarize them

Step 3: Use /loop for quick polling

/loop 30s: Check if the build server is responding on port 8080. If not, report the error.

/loop keeps running within the session. Press Ctrl+C to stop.

Step 4: Script a cron job

For environments with self-managed scheduling, you can trigger Claude Code directly via cron using the -p (print) mode. This runs the agent synchronously and exits once the task completes or hits the turn limit.

bash
# Crontab entry
0 9 * * 1 claude -p "Check for outdated dependencies and create a PR for any updates" --max-turns 10

What goes wrong

MistakeHow you notice itThe fix
Routine doesn't fireNo output at the scheduled timeCheck routine status in the web dashboard. Verify the schedule syntax
Desktop task fails when laptop is asleepTask shows as "missed"Desktop tasks need the machine awake. Use Routines for critical tasks that can't miss a window
/loop floods APIRate limit errors after many iterationsSet a longer interval. /loop is for quick polling, not long-running monitoring

Confirm it worked

Schedule a one-time routine to execute in a couple of minutes and write a test string to a temporary file. Check the file system afterward to confirm the routine triggered correctly and then clean up the file.

bash
# 1. Create a one-time routine for 2 minutes from now
/schedule "in 2 minutes: Write 'hello world' to /tmp/claude-routine-test.txt"

# 2. Wait 2 minutes, then check
cat /tmp/claude-routine-test.txt

# 3. Clean up
rm /tmp/claude-routine-test.txt

Next: Remote Control & Cross-Surface Work