Claude Code Routines: Scheduled and Event-Driven AI Automation
Claude Code Routines execute automated tasks on Anthropic's managed cloud infrastructure. Unlike the local scheduling feature that predated them, Routines run in a dedicated cloud environment with configurable network access, environment variables, setup scripts, and connectors to external services like Slack and GitHub.
Execution modes
Routines formalize three ways to run automated tasks:
Loops run within an active session for iterative tasks you are monitoring directly.
Schedules run on recurring intervals, either with presets (Hourly, Daily, Weekdays, Weekly) or custom cron expressions. These execute in the cloud rather than locally.
Event-driven triggers start a routine in response to an external event, decoupling it from a fixed time schedule.
Core components
Every Routine has four configurable parts.
Prompt. Natural language instructions describing what Claude should do. This can be a simple single-step task or a multi-step workflow with branching logic.
Triggers. The event that starts the routine. Options are: Schedule (recurring time-based), GitHub Event (PR opened, PR merged, release published, and others), or API (an endpoint that accepts a POST request from any external system).
Environment. The sandboxed execution context. Configurable options include network access (blocked by default, or allowlisted domains, trusted sources, or full internet), environment variables for secrets and API keys, and setup scripts that run before Claude Code launches.
Connectors. Pre-built integrations with services like Slack, Gmail, and Google Calendar that provide tools for reading data or taking actions within those services.
Daily content curation routine
The following example creates a scheduled routine that fetches developer newsletter RSS feeds, selects 10 articles suitable for a developer YouTube channel, and posts the list to Slack each morning at 9 AM.
Creating via the CLI
The /schedule slash command accepts a full natural language description:
Claude parses the request and asks clarifying questions before creating the routine.
For this routine, the relevant answers are: the Slack destination channel, and selection criteria (prefer new releases, tutorials, deep-dives, and AI topics that can sustain a 10-minute video). After responding, Claude confirms creation of a remote trigger and provides a link to manage it in the web UI.
Managing routines in the web UI
The web UI shows all routines and their configurations. After creation, two small issues were visible in this example: a GitHub repository was automatically linked and was not needed, and Claude's default Slack formatting uses horizontal rule dividers (---) that cause invalid_blocks validation errors. Both are correctable by editing the routine's prompt to add: "When formatting Slack messages, do not use --- horizontal rule dividers; they cause invalid_blocks validation errors. Use blank lines between sections for spacing instead."
Configuring network access
By default, cloud routines block outbound network requests. Fetching RSS feeds requires allowlisting the relevant domains. Under the environment selector, selecting Add environment opens the network access configuration.
The Custom option creates an allowlist. Adding javascriptweekly.com, react.statuscode.com, and nodeweekly.com permits access to exactly these domains while blocking everything else. After saving and applying the environment, the routine can fetch from those domains.
Running and verifying
The Run now button triggers the routine immediately without waiting for the scheduled time. The runs panel shows a live log of Claude's execution: initializing the session, setting up the container, and working through the prompt steps. If an approach fails (the initial curl command failing due to DNS issues, for example), Claude self-corrects and retries with a different tool.
GitHub PR review routine
This routine triggers on every new pull request in a repository, analyzes the code changes, and posts a review comment directly on the PR.
Creating the trigger
GitHub event-triggered routines must be created in the web UI. Under New routine > Remote, selecting GitHub event as the trigger type shows the available events. Selecting PR opened and choosing the target repository completes the trigger configuration.
Skills and the shared repository approach
A PR review is complex and reusable, making it a good candidate for a Skill: a named, reusable prompt stored in a .claude/skills/ directory. Cloud routine instances are fresh containers with no access to skills defined on a local machine. The solution is a secondary GitHub repository that stores skills and is cloned alongside the primary repository.
Creating a repository (e.g., routine-env) with a .claude/skills/pr-review/SKILL.md file containing the review prompt, then adding this repository to the routine configuration, makes the skills available in the cloud container.
The SessionStart hook
With the skills files in the container, a hook tells Claude where to find them. A .claude/settings.json file in the skills repository defines this:
This command runs at session start and copies the skills from the cloned routine-env repository into the .claude/skills directory the cloud instance uses, effectively installing the custom skills for the routine.
Result
Opening a pull request fires the GitHub webhook within seconds. The run log shows both repositories cloning, the pr-review skill being recognized, Claude fetching the PR diff and details, and a review comment being posted via GitHub tools.
Limits and pricing
Routines are available on Pro, Max, Team, and Enterprise plans. Each run consumes the same token usage as an interactive chat session.
Automated runs (triggered by schedule, GitHub event, or API) have a daily cap:
- Pro: 5 daily automated runs
- Max: 15 daily automated runs
Manual runs via the Run now button do not count toward this cap and are treated as standard interactive sessions.
At 5 automated runs per day on the Pro plan, Routines are most cost-effective for a small number of high-value automations. For high-volume use cases requiring dozens of daily automated runs, self-hosted frameworks with cheaper model providers will be more economical, though they require more setup and maintenance. The primary advantage Routines offer is the ability to define a complex automation in natural language and have it running in the cloud without infrastructure setup.
Final thoughts
Routines make cloud-based AI automation accessible without requiring infrastructure configuration or orchestration code. The event-driven GitHub trigger is the most useful addition for development workflows: it turns a routine into a reactive agent that responds to repository activity rather than running on a fixed schedule.
The skills repository pattern with a SessionStart hook is a practical workaround for the stateless cloud environment, and is likely to become a standard pattern for routines that involve complex or reusable task definitions.
Documentation is available at docs.anthropic.com.