What routines are
A routine is a Claude Code session that lives in the cloud. Unlike a CI/CD job that only runs when a pipeline fires, and unlike your local terminal, which only runs while your computer is on, a routine executes on Anthropic-managed infrastructure on its own schedule or in response to events you define.
Creating a routine
You can create routines two ways:
- From the web:
claude.ai/code→ Routines → New Routine - From the CLI: the
/schedulecommand, which opens the browser interface
Every routine has one of three trigger types:
1. Schedule
Cron-like timing — run nightly, every weekday morning, weekly, and so on.
2. API
Webhook-based — fire the routine from anywhere with an HTTP request.
3. GitHub
React to PR events, issue events, and pushes in your repositories.
Schedule trigger examples
Pair a cron expression with a natural-language prompt. The routine wakes up on schedule, runs the prompt against your connected repository, and acts.
# Nightly dependency audit (2 AM UTC)
Schedule: 0 2 * * *
Prompt: "Run npm audit. For any high-severity vulnerabilities, create GitHub issues
with the CVE details and a recommended fix."
# Morning PR review digest (9 AM Mon-Fri)
Schedule: 0 9 * * 1-5
Prompt: "Review all open PRs older than 24 hours. Post a summary comment on each
with quality feedback and action items."
# Weekly documentation sync (Friday 4 PM)
Schedule: 0 16 * * 5
Prompt: "Check if any API endpoints changed this week. Update the API documentation
in docs/ to reflect the changes and open a PR."
GitHub event triggers
Instead of a clock, the trigger is a repository event with an optional filter. This is how you build reactive automation — review-on-open, fix-on-bug-label, test-on-push.
Event: pull_request.opened
Filter: base_branch = "main"
Prompt: "Review this PR. Check for security issues, test coverage gaps, and
convention violations. Post your findings as PR comments with line references."
Event: issues.labeled
Filter: label = "bug"
Prompt: "This issue has been labeled as a bug. Investigate the described behavior
in the codebase. If you can identify and fix it, create a PR and link it to this issue."
Event: push.branches = ["main"]
Prompt: "A new commit was pushed to main. Run the full test suite. If any tests
fail, create an issue with the test failure details and assign it to the commit author."
API trigger workflow
API-triggered routines accept a JSON context payload, so you can pass in details from your own systems. Fire one with a single curl call:
# Trigger a routine via API
curl -X POST "https://api.anthropic.com/v1/routines/{routine_id}/trigger" \
-H "Authorization: Bearer $ANTHROPIC_API_KEY" \
-H "Content-Type: application/json" \
-d '{"context": {"issue_title": "Payment fails for expired cards", "issue_id": 1234}}'
This unlocks integration with Zapier and n8n, custom webhook flows, and programmatic triggering directly from your own services.
Environment configuration
Routines run in cloud environments that you configure once. Network access is restricted by default, so plan for what the routine actually needs.
Setup script — runs once when the environment is created, to install dependencies and configure tools.
SessionStart hooks — run at the start of every routine execution.
Allowed domains — network is locked down by default; explicitly add domains you need to reach.
Repository access — connect GitHub so the routine can perform repository operations.
Monitoring routines
- The web dashboard (
claude.ai/code→ Routines) shows full run history. - Each run has complete session logs you can inspect step by step.
- Failed runs surface error details and can be re-triggered.
- Routine usage counts toward your subscription, so watch frequency on high-volume triggers.
Practice project
Build a complete autonomous review pipeline using three routines:
- A routine triggered on every PR to
mainthat posts review comments with line references. - A nightly routine that closes stale PRs with a summary comment.
- A routine triggered when an issue is labeled
good-first-issuethat adds implementation hints.
Once your pipeline is running, revisit the rest of the Claude Code tutorial series to combine routines with the other automation patterns you've learned.
Notes
Routines vs CI/CD vs local cron
Use routines when you need Anthropic-managed uptime without maintaining a server. Use CI when the trigger is already a pipeline event. Use local cron only for experiments — your laptop going to sleep kills the job.
Allowed domains are easy to forget
Network is locked down by default. If a routine calls GitHub, your package registry, or an internal API, add every hostname up front — failed runs from DNS errors look like model failures.
High-frequency triggers add up
Every routine run consumes subscription quota. A webhook on every push to a busy monorepo can outspend a nightly cron — start with coarse schedules and tighten only after you measure cost per run.
Prompt drift without version control
Routine prompts live in the dashboard, not always in git. Export or mirror critical prompts into your repo (e.g. .claude/routines/) so changes are reviewable like any other production config.
Quick summary
- Routines run Claude in the cloud, independent of your local machine
- Three triggers: schedule (cron), API (webhook), and GitHub events
- Cloud environments need setup scripts, hooks, allowed domains, and repo access
- Monitor runs and re-trigger failures from the Routines dashboard
Routines FAQ
What are Claude Code routines?
A routine is a Claude Code session that lives in the cloud and runs on Anthropic-managed infrastructure rather than your laptop. It keeps working when your machine is off and fires from a schedule, an API call, or GitHub events.
How does scheduling a routine with cron work?
A schedule trigger pairs a cron expression with a natural-language prompt, so the routine wakes up on schedule, runs the prompt against your connected repository, and acts. For example, 0 2 * * * runs nightly at 2 AM UTC and 0 9 * * 1-5 runs at 9 AM on weekdays.
Do routines support webhook and event triggers?
Yes. Every routine uses one of three trigger types: schedule, API, or GitHub. API triggers are webhook-based and fire from an HTTP request with a JSON context payload, while GitHub triggers react to PR events, issue events, and pushes.
Where do routines run and how are they configured?
Routines run in cloud environments that you configure once with a setup script, SessionStart hooks, allowed domains, and repository access. Network access is restricted by default, so you explicitly add the domains the routine needs to reach.
How do I monitor routine runs?
The web dashboard at claude.ai/code under Routines shows full run history, and each run has complete session logs you can inspect step by step. Failed runs surface error details and can be re-triggered.