Skip to main content

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

  1. ติดตั้ง Claude GitHub app ให้กับ repository: https://github.com/apps/claude
  2. เพิ่ม ANTHROPIC_API_KEY ให้กับ repository secrets
  3. คัดลอก 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_promptprompt
override_promptprompt กับ GitHub variables
custom_instructionsclaude_args: --append-system-prompt
max_turnsclaude_args: --max-turns
modelclaude_args: --model
allowed_toolsclaude_args: --allowedTools
disallowed_toolsclaude_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

  1. Google Cloud Project ที่เปิดใช้ Vertex AI
  2. Workload Identity Federation ที่กำหนดค่าสำหรับ GitHub Actions
  3. Service account พร้อมสิทธิ์ที่จำเป็น

ข้อกำหนดเบื้องต้นสำหรับ Amazon Bedrock

  1. บัญชี AWS ที่เปิดใช้ Amazon Bedrock
  2. GitHub OIDC Identity Provider ที่กำหนดค่าใน AWS
  3. 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_argsCLI arguments ที่ส่งไปยัง Claude Codeไม่
plugin_marketplacesรายการ URL ของ plugin marketplace Gitไม่
pluginsรายการชื่อ plugin ที่ติดตั้งก่อนรันไม่
anthropic_api_keyClaude API keyใช่**
github_tokenGitHub token สำหรับเข้าถึง APIไม่
trigger_phraseTrigger 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