Claude Code Automation Guide | How to Use Routines & Headless Mode
For developers looking to get started with Claude Code automation, this guide organizes the four approaches — cloud-based Routines, CI-integrated Headless mode, interactive /loop, and local overnight Desktop Schedule — to help you choose the right one. We present the optimal solution for each decision axis: PC dependency, team sharing requirements, and execution limits, and explain the fastest path to integrating these into your organization's operations.
The premier automation option is cloud-based Routines, which keeps processing running on Anthropic's servers even when your PC is closed, supporting three trigger types: schedule, API, and Git. Daily execution limits are Pro 5 / Max 15 / Team 25, and since they are tied to individual accounts, sharing is not supported.
For team sharing and CI integration, Headless mode (claude -p) is the go-to choice, enabling non-interactive execution from GitHub Actions or any script. API-triggered Routines are launched via HTTP POST with a beta header and can be directly integrated into webhook-driven incident response workflows.
The selection criteria come down to two axes: "PC dependency" and "sharing requirements" — Routines for personal cloud work, /loop for interactive iteration, and Desktop Schedule for local overnight processing. Routines should be configured with protection-branch restrictions and retry controls to prevent accidental triggers in production use.
目次 (20)
- Tasks Suited for Claude Code Automation — Overview of 3 Categories
- How to Identify Tasks Well Suited for Automation
- Prioritization When Getting Started
- Routines — 3 Types of Triggers Running in the Cloud
- Daily Execution Limits by Plan
- Implementation Example for API Triggers
- Usage Patterns for Git Event Triggers
- Headless Mode (-p / --bare) — Integration with Scripts and CI
- Quick Reference for Key Headless Mode Options
- Real-World Example of Processing JSON Output via Pipe
- Implementation Patterns for CI Environments
- Choosing the Right Automation Method
- How to Think About Cost Estimation
- Ease of Migration
- Security and Operational Considerations
- Understanding the Risks of Unconfirmed Execution
- Key Restrictions to Be Aware of in Operations
- Best Practices for Team Operations
- Ensuring Audit Logs and Reproducibility
- Sources
Tasks Suited for Claude Code Automation — Overview of 3 Categories
Tasks well suited for Claude Code automation fall into three broad categories.
① Scheduled Execution of Coding Assistance This pattern automatically runs code quality checks, test coverage report generation, and dependency update proposals at a fixed time each morning. Even in environments where multiple people work on the same project, AI performs nightly regression checks and outputs reports, significantly reducing the review burden at morning standups. It is also well suited for periodically detecting "code drift" — outdated documentation and neglected comments.
② Event-Driven Review Automation This approach triggers Claude Code based on change events in a Git repository, such as pull request creation or pushes to specific branches. It eliminates waiting time for reviewers and automates initial feedback such as coding convention checks, bug candidate identification, and library migration diff reviews.
③ Operations Automation via External Service Integration This pattern uses HTTP calls from external systems — such as deployment completion notifications, monitoring alerts, or customer feedback receipt — as triggers. Combined with connectors (MCP) for Slack, Linear, Google Drive, and similar services, it enables continuous processing of ticket auto-classification, document auto-updates, and post-deployment behavior verification. Since you can build an end-to-end flow that feeds received alert content to AI for scope identification and rollback decision drafting, this significantly lightens the load of initial incident response during on-call overnight shifts.
How to Identify Tasks Well Suited for Automation
What the three categories share is the nature of being "repetitive tasks with articulable decision criteria." For code quality checks, an internal review checklist; for PR reviews, a conventions document; for operational notifications, past incident reports — these become the sources of decision criteria you pass to the AI. Conversely, for tasks where "judgment calls are made by feel" or "the premise changes every time," the fastest path is to start by writing out a checklist. Since Claude Code excels at reading and executing checklists, a task enters the scope of automation the moment you can articulate its decision criteria in writing.
Prioritization When Getting Started
The first thing to tackle is "the same checks you do every morning." By eliminating rote tasks that engineers currently spend 30 minutes to an hour on manually — classifying test failure patterns, checking dependency vulnerabilities, detecting discrepancies between documentation and implementation — you can visualize ROI early. Conversely, starting with a large-scale flow like fully automating all PR reviews tends to stall midway because convention documentation cannot keep up, so it is best avoided at first.
Routines — 3 Types of Triggers Running in the Cloud
Routines is a cloud-based automation feature that Anthropic released as a research preview on April 14, 2026 ([src: https://claude.com/blog/introducing-routines-in-claude-code]). Its defining characteristic is that Claude Code continues running on Anthropic-managed servers even when the user's laptop is closed.
| Trigger Type | Mechanism | Representative Use Cases |
|---|---|---|
| Schedule | Auto-launches at a specified interval (minimum 1 hour) or at any set time | Morning backlog cleanup, weekly documentation drift detection |
| API Trigger | Launched by an HTTP POST request to an endpoint | Alert reception, post-deployment automated verification |
| Git Event | Launched by pushes to a repository or PR creation | Custom code review, library migration |
Daily Execution Limits by Plan
| Plan | Daily Routines Execution Limit |
|---|---|
| Pro | 5 |
| Max | 15 |
| Team / Enterprise | 25 |
| Free | Not available |
Scheduled Routines can also be configured as one-time "one-off executions" for running a process just once at a specific date and time. API triggers are launched via HTTP requests with the beta header anthropic-beta: experimental-cc-routine-2026-04-01, and runtime context can be passed in the text field ([src: https://code.claude.com/docs/en/routines.md]).
Since Routines are tied to an individual Claude.ai account, sharing with team members is not currently supported. For automation you want to share across your team, consider combining it with Headless mode or CI integration, described below.
Implementation Example for API Triggers
API-triggered Routines are well suited for automation that starts from receiving a webhook. POSTing to Anthropic's API endpoint launches a registered Routine, which reads the contents of the text field as additional context for that run. For example, you can build a flow where the moment a monitoring tool receives a failure alert, it immediately runs log analysis of the relevant service and generates a summary of the impact scope. The endpoint URL and trigger ID are issued from the Routines management dashboard and authenticated via a secret. For production use, implementing alert suppression (anti-flapping) and retry control on the calling side prevents accidental triggers from consuming your daily limit.
Usage Patterns for Git Event Triggers
Git event triggers launch a Routine in response to state changes in a specific repository, branch, or PR. Representative use cases include "generating a release notes draft immediately after merging to the main branch" and "running a custom review checklist when a draft PR switches to ready" — patterns where AI takes over the initial PR review work. Unlike GitHub Actions, there is no YAML to write; the advantage is that configuration takes just a few clicks in the Routines management dashboard. However, since broad write permissions are granted to the repository, it is recommended to restrict the target to protected branches.
Headless Mode (-p / --bare) — Integration with Scripts and CI
When Claude Code is launched with the -p flag, it enters a programmatic mode where it can be called directly from the command line or scripts without starting an interactive UI.
# Basic Headless execution
claude -p "Check the test coverage of src/app.ts and output a report"
# Output as structured JSON
claude -p "List the changes as bullet points" --output-format json
In CI environments (such as build pipelines), adding the --bare flag is recommended. Specifying --bare skips loading hooks, skills, MCP, and CLAUDE.md, speeding up startup. The official documentation explicitly states that "this is planned to become the default behavior of -p in the future," so adopting --bare now for CI use will save migration costs later ([src: https://code.claude.com/docs/en/headless.md]).
Quick Reference for Key Headless Mode Options
| Option | Purpose |
|---|---|
-p |
Programmatic execution (Headless) |
--bare |
Fast startup for CI (skips hooks, etc.) |
--output-format json |
Output as structured JSON |
--output-format stream-json |
Output as streaming JSON |
--allowedTools read,write |
Explicitly restrict which tools may be used |
--permission-mode dontAsk |
Execute without confirmation prompts |
--continue |
Continue the previous session |
Real-World Example of Processing JSON Output via Pipe
Combining --output-format json lets you receive Claude Code's responses as structured data and pass them to downstream scripts. For example, you can receive a "list of changed files and a diff summary for each file" as JSON, format it with jq, and post it to Slack. Choosing stream-json enables streaming reception at the token level, which is useful for real-time logging of progress on long-running analysis tasks. The output schema is documented in the official docs; the basic pattern is to identify assistant / tool_use / result via the type field and branch your processing accordingly ([src: https://code.claude.com/docs/en/headless.md]).
Implementation Patterns for CI Environments
When using Headless mode in CI, there are three key points to keep in mind. First, inject API keys from the CI's secret manager and never commit them to the repository. Second, use --allowedTools to minimize the tools available, preventing unintended file writes or network access. Third, ensure sufficient job timeout. If a CI runner receives SIGTERM mid-way through a long-running task, partial changes may remain in the repository, so it is safer to add a cleanup step that runs git reset on timeout.
Choosing the Right Automation Method
The four methods differ in whether a PC is required, whether local files can be accessed, and whether they can be shared with a team. Understanding these three axes makes the choice straightforward.
| Method | PC-Free | Local File Access | Team Sharing | Cost Profile |
|---|---|---|---|---|
| Routines (Cloud) | ✅ | ❌ | ❌ (tied to personal account) | Subscription usage |
| Desktop Schedule | ❌ (PC must be on) | ✅ | ❌ | Local execution, free |
| Headless Mode / CI | ✅ | △ (on CI runner) | ✅ | API token costs |
| /loop (in-session) | ❌ | ✅ | ❌ | Session usage |
Decision flow:
- Want it to run even when the PC is closed → Routines (Cloud)
- Want to work with local files every morning → Desktop Schedule
- Need team sharing or CI integration → Headless mode + build pipeline
- Want to repeat without confirmation during a session → /loop + Auto mode
In addition to these decision axes, cost estimation also needs to be considered. Routines incur no additional cost within the plan limit. Heavy use of Headless mode in CI will generate separate API token costs. For high-volume use, it is wise to compare the cost of upgrading your Routines plan against the cost of CI usage before deciding.
How to Think About Cost Estimation
Routines use subscription billing — "a fixed fee allows up to N runs per day" — while Headless mode uses usage-based billing charged per input/output token volume per run. As a rough guide, for jobs that run once each morning on 5 business days per week with a modest token volume per run, Routines will be far cheaper. On the other hand, if you want to run AI review on all PRs in a highly active repository that receives dozens of PRs per day, or integrate a heavy job such as auditing an entire monorepo into CI, running Headless mode via API key offers more flexibility without being constrained by daily limits. In practice, a hybrid configuration of "Routines for periodic sweeps, Headless+CI for PR-driven reviews" offers the best cost-performance ratio.
Ease of Migration
It is also important to note that the four methods are not mutually exclusive — incremental migration is possible. A natural progression is to start with /loop for manual repetition within a session, move to Desktop Schedule once it becomes routine, switch to Routines when you want it to run even with the PC off, and upgrade to Headless+CI when rolling it out to the team. Since prompts and instruction documents can be reused across stages, rather than aiming for a finished state from the start, it is less risky to first find "what works well for automation" with /loop and then promote it to a higher-tier method.
Security and Operational Considerations
Understanding the Risks of Unconfirmed Execution
When Routines launch, all operations are executed without confirmation prompts. Operations that would trigger a "May I edit this file?" confirmation in interactive mode are auto-approved in Routines. The official documentation states the following:
"When a routine runs, all tools included in connectors are used without approval."
— [src: https://code.claude.com/docs/en/routines.md]
As a countermeasure, it is recommended to explicitly restrict the operation scope in CLAUDE.md and to configure connectors (MCP) to allow only the minimum necessary tools. A safe approach is to start with "read-only" access for connectors to external services and grant write permissions only after sufficient testing.
Key Restrictions to Be Aware of in Operations
- Minimum interval is 1 hour: Scheduled Routines cannot be set to intervals shorter than 1 hour
- Auto-deactivation after 7 days of inactivity: A configured Routine will automatically turn off if it is not triggered for 7 days
- Not available on the Free plan: Routines require Pro or higher
- Currently a research preview: Specifications may change; caution is advised for use in production-critical contexts
Best Practices for Team Operations
If you want to roll out Routines — which are tied to personal accounts — to a team, the practical approach is to configure the Routine's Git event trigger on a shared repository, or switch to Headless mode in a CI environment managed by the repository. While there is a possibility that team sharing functionality will be added in the future, it is not supported as of May 2026. Before expanding to a team, deciding who owns which automation and handles on-call responsibilities will reduce handoff costs in the event of vacations or departures.
Ensuring Audit Logs and Reproducibility
As automation increases, having a mechanism to trace "why was this change introduced" becomes essential. Since Routines retain execution history and tool call details for each step in the management dashboard, exporting this log regularly is the minimum safeguard. When running Headless mode in CI, save the structured logs obtained with --output-format json as job artifacts so you can trace the cause of any changes after the fact. To improve reproducibility, commit your prompts and CLAUDE.md contents to the repository so you can always identify when and which version was running by commit hash.