惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
博客园_首页
博客园 - 【当耐特】
V
Visual Studio Blog
博客园 - 叶小钗
月光博客
月光博客
美团技术团队
J
Java Code Geeks
小众软件
小众软件
Y
Y Combinator Blog
博客园 - Franky
Martin Fowler
Martin Fowler
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
IT之家
IT之家
MyScale Blog
MyScale Blog
人人都是产品经理
人人都是产品经理
Microsoft Security Blog
Microsoft Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
酷 壳 – CoolShell
酷 壳 – CoolShell
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Claude Code Routines: Put Your AI Agent on Autopilot
ArshTechPro · 2026-04-30 · via DEV Community

If you have been using Claude Code interactively, you already know what it can do in a session. Routines take that further: you define a prompt once, wire up a trigger, and Claude Code runs autonomously on Anthropic-managed cloud infrastructure whenever that trigger fires. Your laptop can be off. The job still runs.

This article walks through what routines are, how to set them up, and where the rough edges are during the current research preview.


What Is a Routine?

A routine is a saved Claude Code configuration. It packages three things:

  • A prompt (the instructions Claude runs each time)
  • One or more GitHub repositories to work in
  • A set of connectors (MCP servers for external services like Slack, Linear, etc.)

You attach one or more triggers to it. Each trigger type determines when a run starts:

  • Schedule - recurring on a cron cadence, or a one-off at a specific timestamp
  • API - an HTTP POST to a per-routine endpoint with a bearer token
  • GitHub event - reactions to pull requests, releases, and similar repository events

A single routine can combine all three. A PR review routine could run nightly, also fire when your CD pipeline calls the endpoint, and also react to every new pull request.

Routines are available on Pro, Max, Team, and Enterprise plans with Claude Code on the web enabled. You manage them at claude.ai/code/routines or from the CLI using /schedule.


Why This Matters

The key property is that routines run without you present. A regular Claude Code session expects you to review, approve, and guide. A routine is designed for unattended, repeatable work tied to a clear outcome.

That changes the use cases you can build:

Backlog maintenance. A schedule trigger runs every weeknight. The routine reads issues opened since the last run, applies labels, assigns owners based on the area of code referenced, and posts a summary to Slack. Your team starts the day with a groomed queue.

Alert triage. Your monitoring tool POSTs to the routine's API endpoint when an error threshold crosses. The routine pulls the stack trace, correlates it with recent commits, and opens a draft PR with a proposed fix. On-call reviews the PR instead of starting from a blank terminal.

Bespoke code review. A GitHub trigger fires on pull_request.opened. The routine applies your team's review checklist and leaves inline comments covering security, performance, and style issues. Human reviewers focus on design decisions.

Library porting. A trigger fires on merged PRs in one SDK repository. The routine ports the change to a parallel SDK in another language and opens a matching PR. Two libraries stay in sync without a human re-implementing each change.


Creating a Routine

You can create routines from the web UI, the Claude Desktop app, or the CLI.

From the Web

  1. Go to claude.ai/code/routines and click New routine.
  2. Name it and write the prompt. The prompt is the most important part. Since the routine runs autonomously, the prompt must be self-contained and explicit about what to do and what success looks like.
  3. Select one or more GitHub repositories. Each is cloned fresh at the start of every run from the default branch.
  4. Pick a cloud environment (controls network access, environment variables, and setup scripts). A Default environment is provided.
  5. Add triggers (Schedule, GitHub event, or API).
  6. Review connectors. All your connected MCP connectors are included by default. Remove any the routine does not need.
  7. Click Create.

After creation, click Run now on the detail page to start an immediate run without waiting for a trigger.

From the CLI

/schedule daily PR review at 9am

Enter fullscreen mode Exit fullscreen mode

/schedule in 2 weeks, open a cleanup PR that removes the feature flag

Enter fullscreen mode Exit fullscreen mode

Claude walks through the same information the web form collects and saves the routine. The CLI supports scheduled triggers only. To add API or GitHub triggers, edit the routine on the web afterward.

Useful CLI management commands:

/schedule list        # see all routines
/schedule update      # change a routine
/schedule run         # trigger a routine immediately

Enter fullscreen mode Exit fullscreen mode


Configuring Triggers

Schedule Triggers

Pick a preset: hourly, daily, weekdays, or weekly. Times are entered in your local timezone and converted automatically. Runs may start a few minutes after the scheduled time due to stagger, but the offset is consistent for each routine.

For custom intervals (every two hours, first of each month), pick the closest preset in the form and then use /schedule update in the CLI to set a specific cron expression. The minimum interval is one hour.

One-off runs fire the routine a single time at a specific timestamp, then auto-disable. Useful for cleanup after a rollout, follow-ups when an upstream change lands, or end-of-week summaries.

One-off runs do not count against the daily routine run cap. They draw down your regular subscription usage like any other session.

API Triggers

An API trigger gives the routine a dedicated HTTP endpoint. POSTing to it with the bearer token starts a new session and returns a session URL.

To set one up:

  1. Open the routine for editing.
  2. Click Add another trigger and choose API.
  3. Copy the URL and click Generate token. Store the token immediately - it is shown once and cannot be retrieved later.

Here is how to call the endpoint:

curl -X POST https://api.anthropic.com/v1/claude_code/routines/trig_01ABCDEFGHJKLMNOPQRSTUVW/fire \
  -H "Authorization: Bearer sk-ant-oat01-xxxxx" \
  -H "anthropic-beta: experimental-cc-routine-2026-04-01" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"text": "Sentry alert SEN-4521 fired in prod. Stack trace attached."}'

Enter fullscreen mode Exit fullscreen mode

The text field is optional freeform context passed alongside the saved prompt. It is not parsed - if you send JSON, the routine receives it as a literal string.

A successful response looks like this:

{
  "type": "routine_fire",
  "claude_code_session_id": "session_01HJKLMNOPQRSTUVWXYZ",
  "claude_code_session_url": "https://claude.ai/code/session_01HJKLMNOPQRSTUVWXYZ"
}

Enter fullscreen mode Exit fullscreen mode

Open the session URL to watch the run in real time, review changes, or continue the conversation manually.

Note: The /fire endpoint ships under the experimental-cc-routine-2026-04-01 beta header. Request and response shapes, rate limits, and token semantics may change. Breaking changes ship behind new dated beta header versions, with the two most recent previous versions remaining active during migration.

Each routine gets its own token scoped to that routine only. To rotate or revoke it, return to the same modal and use Regenerate or Revoke.

GitHub Triggers

GitHub triggers start a new session automatically on matching repository events. Each matching event starts its own independent session - there is no session reuse across events.

Supported events:

Event Triggers when
Pull request A PR is opened, closed, assigned, labeled, synchronized, or otherwise updated
Release A release is created, published, edited, or deleted

You can subscribe to a specific action (like pull_request.opened) or to all actions in the category.

Filters let you narrow which events actually start a session:

Filter Matches
Author PR author's GitHub username
Title PR title text
Body PR description text
Base branch Branch the PR targets
Head branch Branch the PR comes from
Labels Labels applied to the PR
Is draft Whether the PR is in draft state
Is merged Whether the PR has been merged

Operators: equals, contains, starts with, is one of, is not one of, matches regex.

One thing to watch with regex: the matches regex operator tests the entire field value, not a substring. To match any PR title containing hotfix, write .*hotfix.*. Without the surrounding .*, it only matches a title that is exactly hotfix and nothing else. For substring matching without regex syntax, use the contains operator.

Example filter combinations:

  • Auth module review: base branch main, head branch contains auth-provider
  • Ready-for-review only: is draft is false
  • Label-gated backport: labels include needs-backport

The Claude GitHub App must be installed on the repository. The trigger setup prompts you if it is not already. Note that running /web-setup in the CLI grants repository access for cloning but does not install the GitHub App and does not enable webhook delivery. GitHub triggers require the App specifically.

During the research preview, GitHub webhook events are subject to per-routine and per-account hourly caps. Events beyond the limit are dropped until the window resets.


Branch Behavior and Safety

By default, Claude can only push to branches prefixed with claude/. This prevents routines from accidentally modifying protected or long-lived branches.

To allow pushing to any branch (for example, if you need Claude to push directly to main or a release branch), enable Allow unrestricted branch pushes for that repository when creating or editing the routine. Scope this permission carefully.


Connectors

Routines can use your connected MCP connectors to read from and write to external services during each run. A backlog routine might read from a Slack channel and create issues in Linear. An alert triage routine might read from PagerDuty and push to GitHub.

All connectors are included by default when you create a routine. Remove any the routine does not actually need. During a run, Claude can use every tool from an included connector, including writes, without asking for permission.


Usage and Limits

Routines draw down subscription usage the same way interactive sessions do. There is also a daily cap on how many routine runs can start per account.

You can check your current consumption and remaining daily routine runs at claude.ai/code/routines or claude.ai/settings/usage.

When a routine hits the daily cap or your subscription usage limit, organizations with extra usage enabled can keep running routines on metered overage. Without extra usage, additional runs are rejected until the window resets. Enable extra usage from Settings > Billing.

One-off runs are exempt from the daily routine run allowance. They still consume your regular subscription usage.

There is no per-run token count displayed directly in the routine detail view. Usage is reflected in your overall account consumption at the settings page rather than being itemized per routine run.


Managing Runs

Click a routine in the list to open its detail page. From there you can view past runs, see what Claude did in each run, review changes, create a pull request, or continue the conversation.

You can also:

  • Click Run now to start an immediate run
  • Toggle the schedule on and off to pause or resume
  • Edit the name, prompt, repositories, environment, connectors, or triggers
  • Delete the routine (past sessions created by it remain in your session list)

Things to Know Before You Ship

Routines run as you. Anything a routine does through your connected GitHub identity or connectors appears as your account. Commits and pull requests carry your GitHub user. Slack messages and Linear tickets use your linked accounts.

Routines belong to your individual account. They are not shared with teammates and count against your account's daily run allowance.

The prompt is everything. The routine runs autonomously with no approval prompts. There is no permission-mode picker. Write prompts that are self-contained, explicit about the goal, and explicit about what success looks like.

This is research preview. Behavior, limits, and the API surface may change. The /fire endpoint ships under a dated beta header for exactly this reason.


Related Resources