Skip to main content

Routines ของ Claude Code

Automated routines, triggers (schedule, API, GitHub) และการจัดการ routines

ภาพรวม

Routines คืองานที่กำหนดไว้ล่วงหน้าซึ่ง Claude Code สามารถรันได้โดยอัตโนมัติตาม triggers ต่าง ๆ เช่น กำหนดเวลา, API calls หรือ GitHub events

ประเภทของ Routines

Scheduled Routines

รัน routines ตามกำหนดเวลา:

{
"routines": [
{
"name": "daily-review",
"trigger": {
"type": "schedule",
"cron": "0 9 * * 1-5"
},
"task": "ตรวจสอบ open PRs และ summarize ที่ต้องการการตรวจสอบ",
"outputFile": "daily-review.md"
}
]
}

API-triggered Routines

เปิดใช้งาน routine ผ่าน HTTP API:

{
"routines": [
{
"name": "on-demand-analysis",
"trigger": {
"type": "api",
"endpoint": "/trigger/analysis"
},
"task": "วิเคราะห์ performance ของ codebase"
}
]
}

เรียกใช้ผ่าน:

curl -X POST http://localhost:3000/trigger/analysis \
-H "Authorization: Bearer $CLAUDE_ROUTINE_TOKEN"

GitHub-triggered Routines

ตอบสนองต่อ GitHub events:

{
"routines": [
{
"name": "pr-review",
"trigger": {
"type": "github",
"event": "pull_request",
"action": "opened"
},
"task": "ตรวจสอบ PR นี้และ comment ข้อเสนอแนะ"
}
]
}

การตั้งค่า Routines

ตำแหน่งไฟล์

.claude/
└── routines.json

โครงสร้าง Routine

{
"name": "routine-name",
"description": "อธิบายสิ่งที่ routine นี้ทำ",
"trigger": {
"type": "schedule|api|github",
...
},
"task": "prompt หรือ task description",
"outputFile": "ไฟล์ที่จะบันทึก output (optional)",
"permissions": {
"mode": "auto"
}
}

Cron Syntax

สำหรับ scheduled routines ใช้ cron syntax มาตรฐาน:

┌────────── นาที (0-59)
│ ┌──────── ชั่วโมง (0-23)
│ │ ┌────── วันของเดือน (1-31)
│ │ │ ┌──── เดือน (1-12)
│ │ │ │ ┌── วันของสัปดาห์ (0-7, 0 และ 7 คือวันอาทิตย์)
│ │ │ │ │
* * * * *

ตัวอย่าง:

Expressionความหมาย
0 9 * * 1-5ทุกวันทำการเวลา 9 โมงเช้า
0 */2 * * *ทุก 2 ชั่วโมง
0 0 * * 1ทุกวันจันทร์เที่ยงคืน
*/30 * * * *ทุก 30 นาที

การจัดการ Routines

ดูรายการ Routines

claude routines list

รัน Routine ด้วยตนเอง

claude routines run daily-review

หยุด Routine

claude routines disable daily-review

ดู Routine History

claude routines history daily-review

ตัวอย่างการใช้งาน

Daily Standup Summary

{
"name": "standup-summary",
"trigger": {
"type": "schedule",
"cron": "0 9 * * 1-5"
},
"task": "ดู git log จากเมื่อวาน สร้างสรุปสั้น ๆ ว่าทำอะไรไปแล้วและ outstanding issues อะไรที่ต้องทำ",
"outputFile": "standup-$(date +%Y-%m-%d).md"
}

Auto-format Code

{
"name": "format-on-commit",
"trigger": {
"type": "github",
"event": "push",
"branch": "main"
},
"task": "รัน code formatter บนไฟล์ที่เปลี่ยนแปลงใน commit ล่าสุด"
}

ดูสิ่งที่เกี่ยวข้อง