⏰Routines & Scheduled Tasks
Run Claude on a schedule — morning reviews, nightly audits, weekly reports
Why Schedule Claude?
Most developers interact with Claude reactively — they open the terminal, type a prompt, and wait for a response. But what if Claude could work for you while you sleep, commute, or focus on deep work? Scheduled tasks turn Claude from an on-demand assistant into an autonomous teammate that handles recurring chores without your intervention.
Think about the tasks you repeat every day or every week:
- Reviewing overnight pull requests before standup
- Checking for outdated dependencies
- Generating a changelog for the next release
- Auditing security advisories
- Summarizing what happened in the repo since yesterday
All of these can be automated with Claude routines and scheduled tasks. This lesson covers every scheduling mechanism available today: Anthropic-managed Routines, Desktop scheduled tasks, the /loop command for in-session polling, and manual approaches using cron or CI triggers.
Understanding the Scheduling Landscape
Before diving into each mechanism, here is a high-level overview of how they compare:
| Feature | Routines (Anthropic) | Desktop Scheduled | /loop Command | Cron + CLI | GitHub Actions |
|---|---|---|---|---|---|
| Runs where | Anthropic cloud | Local machine | Current session | Local / server | GitHub runners |
| Trigger type | Cron, API, GitHub event | Time-based | Interval | Cron expression | Cron, webhook, event |
| Requires terminal open | No | No | Yes | No | No |
| Access to local files | Via git clone | Yes | Yes | Yes | Via checkout |
| Setup complexity | Low | Low | Very low | Medium | Medium |
| Cost model | Included in plan | Included in plan | Token usage | Token usage | Token usage + runner |
| Best for | Recurring cloud tasks | Personal machine tasks | Watching builds/deploys | Server automation | CI/CD integration |
Choose the mechanism that matches where your code lives and how critical the schedule is. For mission-critical tasks, prefer Routines or GitHub Actions. For personal quality-of-life automation, Desktop scheduled tasks or /loop work great.
Routines — Anthropic-Managed Scheduled Agents
Routines are the most powerful scheduling option. They run on Anthropic's infrastructure, so your laptop can be off and the routine still executes on schedule. Routines were introduced as a first-class feature of Claude Code and are managed entirely through the CLI or the web/desktop interface.
What Is a Routine?
A routine is a saved prompt + trigger configuration that tells Anthropic's servers: "Run this Claude Code session at the specified time, against the specified repository, and post the results somewhere." Each routine execution is a full Claude Code session with tool use, file access, and the ability to create commits or open PRs.
Creating a Routine from the CLI
The fastest way to create a routine is the /schedule slash command inside a Claude Code session:
# Start a Claude Code session
claude
# Inside the session, use the /schedule command
/scheduleThis opens an interactive flow that asks you:
- Prompt — What should Claude do each time the routine runs?
- Repository — Which GitHub repo should the routine operate on?
- Trigger — When should it run? (cron expression, GitHub event, or API call)
- Output — Where should results go? (GitHub issue, PR comment, commit, etc.)
Here is a concrete example — creating a morning PR review routine:
/schedule
# Prompt: Review all open pull requests in this repository.
# For each PR, post a review comment summarizing:
# - Code quality issues
# - Potential bugs
# - Missing test coverage
# - Suggestions for improvement
#
# Repository: myorg/backend-api
# Trigger: cron 0 7 * * 1-5 (7:00 AM UTC, Monday-Friday)
# Output: PR review commentsAfter confirming, the routine is registered with Anthropic's servers and will execute every weekday morning.
Managing Routines from the CLI
# List all your routines
claude schedule list
# View details of a specific routine
claude schedule show morning-pr-review
# Pause a routine without deleting it
claude schedule pause morning-pr-review
# Resume a paused routine
claude schedule resume morning-pr-review
# Delete a routine permanently
claude schedule delete morning-pr-review
# Trigger a routine manually (useful for testing)
claude schedule run morning-pr-reviewCreating a Routine from the Web or Desktop App
If you prefer a graphical interface:
- Open claude.ai or the Claude Desktop app
- Navigate to Claude Code > Routines (or Scheduled Tasks)
- Click New Routine
- Fill in the prompt, select the repository, configure the trigger
- Click Save & Activate
The web interface provides a visual cron builder so you do not need to memorize cron syntax. You can also view execution history, logs, and output from previous runs.
Trigger Types in Detail
Cron Triggers
Cron expressions define exactly when a routine fires. The format is the standard five-field cron:
┌───────── minute (0-59)
│ ┌───────── hour (0-23)
│ │ ┌───────── day of month (1-31)
│ │ │ ┌───────── month (1-12)
│ │ │ │ ┌───────── day of week (0-6, Sun=0)
│ │ │ │ │
* * * * *
Common examples:
# Every weekday at 7:00 AM UTC
0 7 * * 1-5
# Every night at midnight
0 0 * * *
# Every Monday at 9:00 AM
0 9 * * 1
# Every 6 hours
0 */6 * * *
# First day of every month at 8:00 AM
0 8 1 * *API Triggers
API triggers let you fire a routine from any external system — your CI pipeline, a Slack bot, a webhook handler, or a custom script:
# Trigger a routine via the Anthropic API
curl -X POST https://api.anthropic.com/v1/schedules/{schedule_id}/run \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "Content-Type: application/json" \
-d '{"context": "Triggered after production deploy v2.4.1"}'The optional context field lets you pass runtime information to the routine. Claude sees this context alongside the saved prompt, so you can customize behavior per invocation.
GitHub Event Triggers
Routines can fire in response to GitHub events. This is particularly powerful for repository automation:
# Trigger on every push to main
/schedule --trigger github:push --branch main
# Trigger when a new PR is opened
/schedule --trigger github:pull_request --action opened
# Trigger when an issue is labeled "needs-review"
/schedule --trigger github:issues --action labeled --label needs-review
# Trigger on new releases
/schedule --trigger github:release --action publishedGitHub event triggers turn Claude into an event-driven automation layer for your repository. Combined with Claude's ability to read code, write files, and open PRs, this creates a powerful CI/CD extension.
Practical Example 1: Morning PR Review
This routine reviews all open pull requests every weekday morning before your team's standup:
/schedule
# Name: morning-pr-review
# Trigger: cron 0 7 * * 1-5
# Repository: myorg/backend-api
# Prompt:
# Review all open pull requests that have not been reviewed in the last 24 hours.
# For each PR:
# 1. Read every changed file
# 2. Check for code quality issues, bugs, and security concerns
# 3. Verify test coverage for new code paths
# 4. Post a review comment with findings
# 5. If the PR is clean, approve it with a summary
# Prioritize PRs labeled "urgent" first.Why this works: By the time your team opens Slack at 9 AM, every PR already has a detailed review waiting. Human reviewers can focus on architectural decisions instead of catching typos and missing null checks.
Practical Example 2: Nightly Dependency Audit
This routine checks for outdated or vulnerable dependencies every night:
/schedule
# Name: nightly-dependency-audit
# Trigger: cron 0 0 * * *
# Repository: myorg/backend-api
# Prompt:
# Run a full dependency audit:
# 1. Check package.json / requirements.txt / Cargo.toml for outdated packages
# 2. Cross-reference with known vulnerability databases
# 3. Identify packages more than 2 major versions behind
# 4. For each critical finding, open a GitHub issue with:
# - Package name and current vs latest version
# - CVE details if applicable
# - Suggested upgrade path
# - Breaking changes to watch for
# 5. If no issues found, post a summary comment on the tracking issueWhy this works: Security vulnerabilities are caught within hours of disclosure, not weeks. Your team starts each day knowing the dependency health of the project.
Practical Example 3: Weekly Changelog Generation
This routine creates a polished changelog every Friday:
/schedule
# Name: weekly-changelog
# Trigger: cron 0 16 * * 5
# Repository: myorg/backend-api
# Prompt:
# Generate a changelog for this week:
# 1. Read all commits from the last 7 days
# 2. Group them by category (Features, Fixes, Refactoring, Docs, Tests)
# 3. Write clear, user-facing descriptions (not raw commit messages)
# 4. Include links to relevant PRs and issues
# 5. Create a new file: changelogs/YYYY-MM-DD.md
# 6. Update CHANGELOG.md with the new entry at the top
# 7. Open a PR titled "docs: weekly changelog for YYYY-MM-DD"Why this works: Your changelog is always up to date without anyone needing to remember to write it. Product managers and external stakeholders get a clean weekly summary automatically.
Practical Example 4: Post-Merge Documentation Sync
This routine fires every time code is merged to main and ensures documentation stays in sync:
/schedule
# Name: doc-sync
# Trigger: github:push --branch main
# Repository: myorg/backend-api
# Prompt:
# Documentation sync after merge to main:
# 1. Identify all files changed in the latest push
# 2. For each changed file, check if related documentation exists
# 3. If docs exist, verify they still match the implementation
# 4. If docs are outdated, update them to reflect the new code
# 5. If new public APIs were added without docs, create stub documentation
# 6. Open a PR with all documentation updates
# 7. Title: "docs: sync documentation with latest changes"Why this works: Documentation drift is one of the biggest problems in software teams. This routine catches it at the source — every merge to main triggers a doc review.
Desktop Scheduled Tasks
Claude Desktop supports local scheduled tasks that run on your machine. Unlike Routines (which run in the cloud), desktop scheduled tasks have full access to your local filesystem, environment variables, and tools.
Setting Up Desktop Scheduled Tasks
In Claude Desktop preferences:
- Go to Settings > Scheduled Tasks
- Click Add Task
- Configure the schedule, working directory, and prompt
- The task runs as a local Claude Code session at the scheduled time
When to Use Desktop vs Cloud Routines
Use Desktop scheduled tasks when:
- You need access to local files not in a git repository
- You work with local databases or services
- You want to run tasks against private codebases without cloud access
- The task involves local tooling (Docker, local servers, etc.)
Use Cloud Routines when:
- The task should run even when your laptop is off
- You need reliability guarantees (no missed runs)
- The task operates on GitHub repositories
- Multiple team members should benefit from the results
The /loop Command — In-Session Polling
The /loop command is the simplest scheduling mechanism. It repeats a prompt at a fixed interval within your current Claude Code session. It is not a persistent schedule — it stops when you end the session.
Basic Usage
# Inside a Claude Code session:
# Check deployment status every 5 minutes
/loop 5m Check the deployment status at https://status.myapp.com and tell me when it shows "healthy"
# Monitor CI pipeline every 2 minutes
/loop 2m Check the GitHub Actions status for the current branch. If all checks pass, let me know.
# Watch for new issues every 10 minutes
/loop 10m Check if any new issues were opened in myorg/backend-api in the last 10 minutes. Summarize them.Default Interval
If you omit the interval, /loop defaults to 10 minutes:
# Runs every 10 minutes by default
/loop Check if the build passedStopping a Loop
Press Ctrl+C or type /loop stop to cancel the active loop:
/loop stopPractical /loop Examples
# Wait for a long-running migration to complete
/loop 2m Check if the database migration in migrations/042_add_index.sql has completed. Query the migrations table and report status.
# Monitor error rates after a deploy
/loop 5m Check the application logs for the last 5 minutes. If error rate exceeds 1%, alert me immediately.
# Watch for PR approvals
/loop 3m Check if PR #142 has been approved. If approved, run the merge and let me know.Advanced: Cron + Claude CLI
For maximum control, you can use your operating system's cron scheduler (or systemd timers, launchd on macOS) to invoke Claude CLI directly:
macOS (launchd)
Create a plist file at ~/Library/LaunchAgents/com.claude.morning-review.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.claude.morning-review</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/claude</string>
<string>-p</string>
<string>Review all open PRs and post comments</string>
<string>--output-format</string>
<string>json</string>
</array>
<key>WorkingDirectory</key>
<string>/Users/you/projects/backend-api</string>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>7</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
<key>StandardOutPath</key>
<string>/tmp/claude-morning-review.log</string>
<key>StandardErrorPath</key>
<string>/tmp/claude-morning-review.err</string>
</dict>
</plist>Load it:
launchctl load ~/Library/LaunchAgents/com.claude.morning-review.plistLinux (crontab)
# Edit your crontab
crontab -e
# Add a line for the morning review
0 7 * * 1-5 cd /home/you/projects/backend-api && claude -p "Review all open PRs and post comments" --output-format json >> /tmp/claude-morning-review.log 2>&1GitHub Actions
name: Nightly Dependency Audit
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Claude CLI
run: npm install -g @anthropic-ai/claude-code
- name: Run audit
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
claude -p "Run a full dependency audit. Open issues for any critical findings." \
--output-format json \
--max-turns 20Best Practices
1. Start Simple, Then Expand
Begin with one routine — like the morning PR review — and observe its output for a week. Tune the prompt based on what you see before adding more routines.
2. Set Token Budgets
Use --max-turns or token limits to prevent runaway costs:
claude -p "Review PRs" --max-turns 153. Use Output Channels Wisely
Direct routine output where it is most useful:
- PR comments for code review routines
- GitHub issues for audit findings
- Slack webhooks for team notifications
- Log files for debugging and history
4. Monitor Execution History
Check routine logs regularly to ensure they are running correctly:
claude schedule logs morning-pr-review --last 75. Handle Failures Gracefully
Routines can fail due to API rate limits, repository access issues, or prompt ambiguity. Set up notifications for failed runs:
claude schedule configure morning-pr-review --on-failure notify:slack6. Version Control Your Routine Prompts
Store routine prompts in your repository so they are reviewed and versioned like any other code:
.claude/
routines/
morning-pr-review.md
nightly-dependency-audit.md
weekly-changelog.md
post-merge-doc-sync.md
Summary
Scheduled tasks transform Claude from a reactive tool into a proactive teammate. The key scheduling mechanisms are:
- Routines — Cloud-managed, reliable, trigger on cron/API/GitHub events
- Desktop scheduled tasks — Local machine, full filesystem access
/loop— In-session polling, great for temporary monitoring- Cron + CLI — Full control, runs anywhere you have a shell
- GitHub Actions — CI/CD native, version-controlled schedules
Start with one simple routine, observe its behavior, and gradually build a library of automated tasks that keep your codebase healthy while you focus on building features.