Giới thiệu
Claude Code Routines là tính năng mới cho phép định nghĩa và chạy tự động các tác vụ trên hạ tầng cloud của Anthropic. Khác với local scripts, mỗi routine chạy trong một Claude Code session đầy đủ — có thể dùng tools, MCP connectors (Slack, Linear, Google Drive), và tương tác với GitHub repositories, kể cả khi laptop đã tắt.
Routines hiện đang ở research preview. API surface và limits có thể thay đổi.
Cấu trúc của một Routine
Mỗi routine gồm:
- Prompt: hướng dẫn Claude làm gì mỗi lần chạy — phải self-contained và rõ ràng về điều kiện thành công
- Repositories: repo GitHub nào được clone cho mỗi run (clone từ default branch)
- Environment: network access, environment variables, setup script
- Connectors: MCP tools như Slack, Linear, Google Drive
- Triggers: điều kiện kích hoạt routine
Các loại Trigger
Schedule
Chạy theo lịch cố định: hourly, daily, weekdays, weekly. Hỗ trợ custom cron expression qua CLI với /schedule update. Minimum interval là 1 giờ.
API
Gọi routine qua HTTP POST đến một endpoint riêng của từng routine. Request body có thể truyền context qua field text — ví dụ alert body, failing log. Response trả về session_id và URL để theo dõi run. Dùng để tích hợp vào alerting systems, deploy pipelines, hay internal tools.
GitHub Event
Trigger tự động khi có sự kiện trên repository. Hỗ trợ nhiều loại event:
| Event | Kích hoạt khi |
|---|---|
| Pull request | PR mở, đóng, update, gán label |
| Push | Commit được push lên branch |
| Issues | Issue mở, đóng, comment |
| Workflow run | GitHub Actions workflow hoàn thành |
| Release | Release được publish |
Hỗ trợ filter theo author, base/head branch, labels, draft status.
Use Cases thực tế
Backlog maintenance — Schedule trigger chạy mỗi tối: đọc issues mới, gán labels và assignees, post summary lên Slack cho team.
Alert triage — Monitoring tool gọi API trigger khi lỗi vượt ngưỡng. Claude pull stack trace, tìm commit liên quan, tạo draft PR fix.
Code review tự động — GitHub trigger khi PR mở: Claude apply checklist review của team, để lại inline comments, post summary.
Deploy verification — CD pipeline gọi routine sau mỗi deploy: Claude chạy smoke checks, scan error logs, post go/no-go lên release channel.
Docs drift — Schedule trigger hàng tuần: scan merged PRs, flag docs tham chiếu APIs đã thay đổi, mở update PRs.
Tạo và Quản lý
Từ web: https://claude.ai/code/routines → New routine
Từ CLI: chạy /schedule hoặc /schedule daily PR review at 9am
Từ Desktop app: Schedule page → New task → New remote task
Mỗi run tạo ra một session riêng biệt — có thể xem lại toàn bộ actions của Claude, review changes, tạo PR.
Lưu ý quan trọng
- Routines chạy fully autonomous — không có approval prompt trong quá trình chạy
- Branch push mặc định bị giới hạn ở
claude/-prefixed branches - Commits và PRs hiển thị dưới tên tài khoản của bạn, không phải bot riêng
- Routine dùng chung subscription quota với interactive sessions
- Available trên Pro, Max, Team, và Enterprise plans với Claude Code on the web enabled