01 — ภาพรวมRoutine คืออะไร?
Routine คือ Claude Code configuration ที่บันทึกไว้ ประกอบด้วย prompt, repository หนึ่งอันหรือมากกว่า และชุด connectors ที่แพ็กเกจไว้ครั้งเดียวแล้วรันอัตโนมัติ
Routines ทำงานบน cloud infrastructure ของ Anthropic ดังนั้นจึงทำงานต่อเนื่องแม้แล็ปท็อปจะปิดอยู่ — ไม่ต้องเปิดคอมพิวเตอร์ทิ้งไว้ ไม่ต้องดูแล server เอง
Routines ใช้ได้กับแผน Pro, Max, Team และ Enterprise ที่เปิดใช้ Claude Code on the web สร้างและจัดการได้ที่ claude.ai/code/routines หรือจาก CLI ด้วยคำสั่ง /schedule
02 — Trigger Typesประเภทของ Trigger
แต่ละ routine สามารถมี trigger ได้หลายแบบพร้อมกัน เช่น routine รีวิว PR สามารถรันทุกคืน, ทริกเกอร์จาก deploy script และตอบสนองต่อ PR ใหม่ได้พร้อมกัน
03 — Use Casesตัวอย่างการใช้งาน
งานที่เหมาะกับ routines คืองานที่ทำซ้ำ, ไม่ต้องนั่งรอ, และมีผลลัพธ์ที่ชัดเจน
04 — Getting Startedวิธีสร้าง Routine
สร้าง routine ได้จาก 3 ช่องทาง ทั้งหมดเขียนไปยัง cloud account เดียวกัน:
สร้างจาก Web (แนะนำ)
-
1เปิดฟอร์มสร้าง
ไปที่
claude.ai/code/routinesแล้วคลิก New routine -
2ตั้งชื่อและเขียน Prompt
Prompt คือส่วนที่สำคัญที่สุด เพราะ routine รันแบบ autonomous — ต้องครบถ้วนและระบุชัดเจนว่าต้องทำอะไร และผลลัพธ์ที่ดีเป็นอย่างไร
-
3เลือก Repositories
เพิ่ม GitHub repository ที่ Claude จะทำงานใน แต่ละ repo จะถูก clone ตอนเริ่มรัน Claude สร้าง branch ที่มีคำนำหน้า
claude/สำหรับ changes ของตัวเอง -
4เลือก Environment
ควบคุม network access, environment variables (API keys, tokens) และ setup script สำหรับติดตั้ง dependencies
-
5เลือก Trigger
เลือก trigger เดียวหรือรวมหลายแบบ — schedule, GitHub event หรือ API
-
6ตรวจสอบ Connectors & สร้าง
Connectors ทั้งหมดที่เชื่อมต่อไว้จะถูกรวมตามค่าเริ่มต้น ลบที่ไม่ต้องการออก แล้วคลิก Create
สร้างจาก CLI
รัน /schedule ใน session ใดก็ได้ หรือใส่ description โดยตรง เช่น /schedule daily PR review at 9am
/schedule ใน CLI สร้างได้เฉพาะ scheduled routines หากต้องการเพิ่ม API หรือ GitHub trigger ให้แก้ไขที่ claude.ai/code/routines
05 — API Triggerการใช้ API Trigger
API trigger ให้ routine มี HTTP endpoint เฉพาะ — ใช้เชื่อมต่อกับ alerting systems, deploy pipelines, internal tools หรือที่ใดก็ตามที่ส่ง HTTP request ได้
ขั้นตอนตั้งค่า
-
1เปิด routine เพื่อแก้ไข
ไปที่
claude.ai/code/routinesคลิก routine แล้วคลิกไอคอนดินสอ -
2เพิ่ม API trigger
เลื่อนไปยัง Select a trigger, คลิก Add another trigger, เลือก API
-
3Copy URL และ Generate Token
Token จะแสดงเพียงครั้งเดียว — เก็บไว้ใน secret store ให้ดี ไม่สามารถดึงกลับมาได้ในภายหลัง
ตัวอย่างการเรียก Endpoint
curl -X POST https://api.anthropic.com/v1/claude_code/routines/trig_01ABCDEF.../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."}'
Response เมื่อสำเร็จ
{
"type": "routine_fire",
"claude_code_session_id": "session_01HJKLMNOPQRSTUVWXYZ",
"claude_code_session_url": "https://claude.ai/code/session_01HJKLMNOPQRSTUVWXYZ"
}
เปิด claude_code_session_url ในเบราว์เซอร์เพื่อดูการรันแบบ real-time, review changes หรือสนทนาต่อด้วยตนเอง
experimental-cc-routine-2026-04-01 ซึ่งอาจเปลี่ยนแปลงได้ในช่วง research preview
06 — GitHub Triggerการใช้ GitHub Trigger
GitHub trigger เริ่ม session ใหม่อัตโนมัติเมื่อมี event ตรงกันใน repository — แต่ละ event ที่ตรงกันจะเริ่ม session ของตัวเอง
Events ที่รองรับ
| Event | ทริกเกอร์เมื่อ |
|---|---|
pull_request | มีการเปิด, ปิด, assign, label, sync หรืออัปเดต PR |
release | มีการสร้าง, publish, แก้ไข หรือลบ release |
Filter Pull Requests
ใช้ filter เพื่อจำกัดว่า PR ไหนถึงจะเริ่ม session ใหม่ ทุก filter ต้องตรงกันพร้อมกัน
| Filter | ตรงกับ |
|---|---|
Author | GitHub username ของผู้สร้าง PR |
Title | ข้อความในชื่อ PR |
Body | ข้อความในคำอธิบาย PR |
Base branch | Branch เป้าหมายของ PR |
Head branch | Branch ต้นทางของ PR |
Labels | Labels ที่ติดกับ PR |
Is draft | PR อยู่ในสถานะ draft หรือไม่ |
Is merged | PR ถูก merge แล้วหรือไม่ |
From fork | PR มาจาก fork หรือไม่ |
matches regex ทดสอบค่าทั้งหมด ไม่ใช่แค่ substring
หากต้องการจับชื่อที่มีคำว่า hotfix ต้องเขียน .*hotfix.* ไม่ใช่แค่ hotfix
07 — Managementจัดการและตั้งค่า
Branch Permissions
ตามค่าเริ่มต้น Claude push ได้เฉพาะ branch ที่มีคำนำหน้า claude/ เพื่อป้องกันการแก้ไข branch สำคัญโดยไม่ตั้งใจ หากต้องการยกเลิกข้อจำกัดนี้ ให้เปิด Allow unrestricted branch pushes สำหรับ repository นั้น
Connectors
Routines ใช้ MCP connectors เพื่ออ่านและเขียนไปยัง external services ในแต่ละรัน เช่น Slack, Linear, Google Drive ตามค่าเริ่มต้น connectors ทั้งหมดจะถูกรวมไว้ — ลบที่ไม่ต้องการออกเพื่อจำกัด tools ที่ Claude เข้าถึงได้
การควบคุม Routine
- Run now — เริ่มรันทันทีโดยไม่ต้องรอ schedule ถัดไป
- Pause / Resume — ใช้ toggle ใน Repeats section เพื่อหยุดชั่วคราว
- แก้ไข — คลิกไอคอนดินสอเพื่อเปลี่ยน prompt, repos, environment, triggers
- ลบ — ลบ routine (sessions ที่ผ่านมายังคงอยู่ใน session list)
08 — UsageUsage & Limits
Routines ใช้ subscription usage เช่นเดียวกับ interactive sessions นอกจากนี้ยังมี daily cap สำหรับจำนวนรันต่อวันต่อ account
ดู consumption ปัจจุบันได้ที่ claude.ai/code/routines หรือ claude.ai/settings/usage