Claude Code GitHub Actions
เรียนรู้การผสานรวม Claude Code เข้ากับ workflow การพัฒนาของคุณด้วย Claude Code GitHub Actions
Claude Code GitHub Actions นำ AI automation มาสู่ GitHub workflow ของคุณ ด้วยการ mention @claude ใน PR หรือ issue ใด ๆ Claude สามารถวิเคราะห์โค้ดของคุณ สร้าง pull request ใช้งานฟีเจอร์ และแก้ไขบั๊ก ทั้งหมดนี้ตามมาตรฐานของโปรเจกต์คุณ
ทำไมต้องใช้ Claude Code GitHub Actions?
- สร้าง PR ได้ทันที: อธิบายสิ่งที่ต้องการ และ Claude จะสร้าง PR ที่สมบูรณ์พร้อมการเปลี่ยนแปลงที่จำเป็นทั้งหมด
- นำไปใช้งานโค้ดอัตโนมัติ: เปลี่ยน issue เป็นโค้ดที่ใช้งานได้ด้วยคำสั่งเดียว
- ทำตามมาตรฐานของคุณ: Claude เคารพแนวทาง
CLAUDE.mdและ code pattern ที่มีอยู่ - ตั้งค่าง่าย: เริ่มต้นได้ภายในไม่กี่นาทีด้วย installer และ API key
- ปลอดภัยโดยค่าเริ่มต้น: โค้ดของคุณอยู่บน runner ของ GitHub
การตั้งค่า
Quick setup
วิธีง่ายที่สุดในการตั้งค่าคือผ่าน Claude Code ใน terminal เพียงเปิด claude และรัน /install-github-app
หมายเหตุ: คุณต้องเป็นผู้ดูแล repository เพื่อติดตั้ง GitHub app และเพิ่ม secrets
Manual setup
- ติดตั้ง Claude GitHub app ให้กับ repository: https://github.com/apps/claude
- เพิ่ม ANTHROPIC_API_KEY ให้กับ repository secrets
- คัดลอก workflow file จาก examples/claude.yml ไปยัง
.github/workflows/ของ repository คุณ
อัปเกรดจาก Beta
คำเตือน: Claude Code GitHub Actions v1.0 นำเสนอ breaking changes ที่ต้องอัปเดต workflow file
การเปลี่ยนแปลงที่จำเป็น
| Beta Input เดิม | v1.0 Input ใหม่ |
|---|---|
mode | (ลบออก - ตรวจจับอัตโนมัติ) |
direct_prompt | prompt |
override_prompt | prompt กับ GitHub variables |
custom_instructions | claude_args: --append-system-prompt |
max_turns | claude_args: --max-turns |
model | claude_args: --model |
allowed_tools | claude_args: --allowedTools |
disallowed_tools | claude_args: --disallowedTools |
ตัวอย่างก่อนและหลัง
เวอร์ชัน Beta:
- uses: anthropics/claude-code-action@beta
with:
mode: "tag"
direct_prompt: "Review this PR for security issues"
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
custom_instructions: "Follow our coding standards"
max_turns: "10"
model: "claude-sonnet-4-6"
เวอร์ชัน GA (v1.0):
- uses: anthropics/claude-code-action@v1
with:
prompt: "Review this PR for security issues"
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
claude_args: |
--append-system-prompt "Follow our coding standards"
--max-turns 10
--model claude-sonnet-4-6
ตัวอย่างการใช้งาน
Basic workflow
name: Claude Code
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
jobs:
claude:
runs-on: ubuntu-latest
steps:
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
# ตอบสนองต่อการ mention @claude ในความคิดเห็น
การใช้ Skills
input prompt รับ skill invocation รวมถึงข้อความธรรมดา:
name: Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
plugin_marketplaces: "https://github.com/anthropics/claude-code.git"
plugins: "code-review@claude-code-plugins"
prompt: "/code-review:code-review ${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
Automation แบบกำหนดเอง
name: Daily Report
on:
schedule:
- cron: "0 9 * * *"
jobs:
report:
runs-on: ubuntu-latest
steps:
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
prompt: "Generate a summary of yesterday's commits and open issues"
claude_args: "--model opus"
กรณีใช้งานทั่วไป
ใน issue หรือ PR comment:
@claude implement this feature based on the issue description
@claude how should I implement user authentication for this endpoint?
@claude fix the TypeError in the user dashboard component
Best Practices
การกำหนดค่า CLAUDE.md
สร้างไฟล์ CLAUDE.md ใน root ของ repository เพื่อกำหนด code style guidelines, review criteria, กฎเฉพาะโปรเจกต์ และ pattern ที่ต้องการ ไฟล์นี้ช่วยให้ Claude เข้าใจมาตรฐานโปรเจกต์ของคุณ
ข้อพิจารณาด้านความปลอดภัย
คำเตือน: อย่า commit API keys โดยตรงไปยัง repository เด็ดขาด
ใช้ GitHub Secrets สำหรับ API keys เสมอ:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
การใช้กับ Amazon Bedrock & Google Vertex AI
สำหรับสภาพแวดล้อม enterprise คุณสามารถใช้ Claude Code GitHub Actions กับ cloud infrastructure ของคุณเอง
ข้อกำหนดเบื้องต้นสำหรับ Google Cloud Vertex AI
- Google Cloud Project ที่เปิดใช้ Vertex AI
- Workload Identity Federation ที่กำหนดค่าสำหรับ GitHub Actions
- Service account พร้อมสิทธิ์ที่จำเป็น
ข้อกำหนดเบื้องต้นสำหรับ Amazon Bedrock
- บัญชี AWS ที่เปิดใช้ Amazon Bedrock
- GitHub OIDC Identity Provider ที่กำหนดค่าใน AWS
- IAM role พร้อมสิทธิ์ Bedrock
ตัวอย่าง Amazon Bedrock workflow
name: Claude PR Action
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
on:
issue_comment:
types: [created]
jobs:
claude-pr:
if: |
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude'))
runs-on: ubuntu-latest
env:
AWS_REGION: us-west-2
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Configure AWS Credentials (OIDC)
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: us-west-2
- uses: anthropics/claude-code-action@v1
with:
github_token: ${{ steps.app-token.outputs.token }}
use_bedrock: "true"
claude_args: '--model us.anthropic.claude-sonnet-4-6 --max-turns 10'
พารามิเตอร์ Action
| พารามิเตอร์ | คำอธิบาย | จำเป็น |
|---|---|---|
prompt | คำแนะนำสำหรับ Claude (ข้อความธรรมดาหรือชื่อ skill) | ไม่* |
claude_args | CLI arguments ที่ส่งไปยัง Claude Code | ไม่ |
plugin_marketplaces | รายการ URL ของ plugin marketplace Git | ไม่ |
plugins | รายการชื่อ plugin ที่ติดตั้งก่อนรัน | ไม่ |
anthropic_api_key | Claude API key | ใช่** |
github_token | GitHub token สำหรับเข้าถึง API | ไม่ |
trigger_phrase | Trigger phrase แบบกำหนดเอง (ค่าเริ่มต้น: "@claude") | ไม่ |
use_bedrock | ใช้ Amazon Bedrock แทน Claude API | ไม่ |
use_vertex | ใช้ Google Vertex AI แทน Claude API | ไม่ |
*Prompt เป็นตัวเลือก - เมื่อไม่ระบุสำหรับ issue/PR comment Claude จะตอบสนองต่อ trigger phrase
**จำเป็นสำหรับ Claude API โดยตรง ไม่ใช่สำหรับ Bedrock/Vertex
การแก้ปัญหา
Claude ไม่ตอบสนองต่อคำสั่ง @claude: ตรวจสอบว่า GitHub App ติดตั้งถูกต้อง workflow เปิดใช้งาน API key ตั้งค่าใน repository secrets และ comment มี @claude (ไม่ใช่ /claude)
การยืนยันตัวตนผิดพลาด: ยืนยันว่า API key ถูกต้องและมีสิทธิ์เพียงพอ สำหรับ Bedrock/Vertex ตรวจสอบการกำหนดค่า credentials