- 10
- มีนาคม
ใน EP 1 เราอธิบายแล้วว่า Claude Code Review คืออะไร และทำงานอย่างไรด้วยสถาปัตยกรรม Multi-Agent — ใน EP 2 นี้เราจะมาลงมือจริงกัน ตั้งแต่ ติดตั้ง GitHub App, ตั้งค่า Trigger Mode, สร้าง CLAUDE.md สำหรับ Review Rules ไปจนถึง อ่านผล Review และ ปรับแต่งกฎเฉพาะโปรเจกต์
สรุปสั้นๆ — EP 2 ครอบคลุมอะไรบ้าง?
คู่มือ Step-by-Step ติดตั้งและตั้งค่า Claude Code Review ครบจบในบทความเดียว — ตั้งแต่ Prerequisites, ติดตั้ง GitHub App, เลือก Trigger Mode, สร้าง CLAUDE.md + REVIEW.md สำหรับกำหนดกฎ Review, อ่านผลและตอบกลับ Comment, ไปจนถึง Best Practices สำหรับทีมพัฒนา
Prerequisites — สิ่งที่ต้องมีก่อนเริ่ม
ก่อนเปิดใช้งาน Claude Code Review ต้องเตรียมสิ่งต่อไปนี้:
| ลำดับ | รายการ | รายละเอียด |
|---|---|---|
| 1 | Anthropic Plan | Claude for Teams (Premium — $150/คน/เดือน) หรือ Claude for Enterprise |
| 2 | GitHub Organization | ต้องมี Organization บน GitHub (ไม่ใช่แค่ Personal Account) |
| 3 | Repository Admin | ต้องมีสิทธิ์ Admin ของ Repository ที่จะเปิดใช้งาน |
| 4 | Claude Code CLI | ติดตั้งแล้วและ Login ผ่าน claude.ai OAuth (สำหรับ CLI Mode) |
หมายเหตุ: ขณะนี้ Claude Code Review รองรับเฉพาะ GitHub เท่านั้น ยังไม่รองรับ GitLab หรือ Bitbucket — Anthropic อาจเพิ่มในอนาคต
ขั้นตอนที่ 1 — เปิดใช้งาน Code Review จาก Admin Settings
สิ่งแรกที่ต้องทำคือเปิดฟีเจอร์จากหน้า Admin ของ Anthropic:
- ไปที่ claude.ai/admin-settings/claude-code
- เลื่อนลงมาที่ส่วน "Code Review"
- คลิก "Setup" เพื่อเริ่มกระบวนการติดตั้ง GitHub App
ระบบจะพาไปที่หน้า GitHub เพื่อติดตั้ง Claude GitHub App ต่อไป
ขั้นตอนที่ 2 — ติดตั้ง Claude GitHub App
Claude Code Review ทำงานผ่าน GitHub App ชื่อ "Claude" — ต้องติดตั้งเข้า Organization ก่อน:
- เข้า github.com/apps/claude
- คลิก "Install"
- เลือก Organization ที่ต้องการ
- เลือก Repository — สามารถเลือก "All repositories" หรือเลือกเฉพาะบาง Repository ก็ได้
- ตรวจสอบ Permissions ที่ App ขอ:
| Permission | ระดับ | ทำไมถึงต้องใช้ |
|---|---|---|
| Contents | Read & Write | อ่านโค้ดเพื่อวิเคราะห์ + เสนอ Fix |
| Issues | Read & Write | เชื่อมโยงผล Review กับ Issue ที่เกี่ยวข้อง |
| Pull Requests | Read & Write | อ่าน Diff + Post Comment บน PR |
- คลิก "Install & Authorize"
วิธีอื่น: ถ้าคุณใช้ Claude Code CLI อยู่แล้ว สามารถรัน /install-github-app ใน Terminal เพื่อเริ่ม Guided Flow ได้โดยไม่ต้องเข้า Admin Settings
ขั้นตอนที่ 3 — เลือก Trigger Mode
หลังติดตั้ง GitHub App แล้ว ต้องเลือกว่าจะให้ Claude Review ตอนไหน:
| Trigger Mode | วิธีทำงาน | เหมาะกับ | ข้อดี |
|---|---|---|---|
| PR Creation Only (ค่าเริ่มต้น) | Review ครั้งเดียวตอนสร้าง PR | ทีมเล็ก, งบจำกัด | ประหยัดค่าใช้จ่าย |
| After Every Push | Review ซ้ำทุกครั้งที่ Push ใหม่ | ทีมใหญ่, โปรเจกต์ซับซ้อน | จับปัญหาใหม่ + Auto-resolve เมื่อแก้แล้ว |
| CLI Manual | รัน /code-review ด้วยตัวเอง |
นักพัฒนาที่ต้องการ Review เฉพาะบาง PR | ควบคุมได้เต็มที่ |
แนะนำ: เริ่มจาก "PR Creation Only" ก่อน — แล้วค่อยเปลี่ยนเป็น "After Every Push" เมื่อเห็นว่าผล Review มีประโยชน์จริง
ขั้นตอนที่ 4 — สร้าง CLAUDE.md สำหรับ Review Rules
จุดเด่นของ Claude Code Review คือสามารถ กำหนดกฎ Review ด้วยภาษาธรรมชาติ ผ่านไฟล์ CLAUDE.md — ไม่ต้องเขียน YAML หรือ Regex
CLAUDE.md คืออะไร?
CLAUDE.md คือไฟล์ที่วางไว้ที่ Root ของ Repository เพื่อบอก Claude ว่า:
- โปรเจกต์นี้ใช้ Coding Standard อะไร
- มี Architecture Decisions อะไรบ้างที่ต้องรักษา
- มี กฎเฉพาะ ที่ต้องตรวจเสมอ (เช่น "ห้าม commit secrets")
ตัวอย่าง CLAUDE.md
# Project: E-Commerce Backend ## Tech Stack - Python 3.12, FastAPI, PostgreSQL - ORM: SQLAlchemy 2.0 (async) - Testing: pytest + httpx ## Coding Standards - ใช้ Type Hints ทุก function - ห้าม print() ใน production code — ใช้ logging module - ทุก API Endpoint ต้องมี Pydantic schema - Database queries ต้องใช้ parameterized query เสมอ ## Security Rules - ห้าม hardcode API keys, passwords, tokens - Input validation ทุก endpoint - Rate limiting สำหรับ public endpoints ## Architecture - Clean Architecture: Controller → Service → Repository - ห้าม import Repository layer ตรงจาก Controller
REVIEW.md — กฎเฉพาะสำหรับ Review
นอกจาก CLAUDE.md แล้ว ยังสามารถสร้างไฟล์ REVIEW.md (หรือ .claude/review.md) เพื่อกำหนดกฎที่ใช้เฉพาะตอน Code Review เพิ่มเติม:
ตัวอย่าง REVIEW.md
# Review Rules ## Always Check - SQL Injection vulnerabilities - Functions longer than 100 lines - Missing error handling in async operations - N+1 query patterns ## Ignore - Formatting/style issues (handled by black + isort) - Type annotation completeness (handled by mypy) - Import ordering (handled by isort) ## Severity - Security issues → always flag as Critical - Missing tests for new endpoints → flag as High
.claude/rules/ — กฎแบบ Modular
สำหรับโปรเจกต์ขนาดใหญ่ สามารถสร้าง Rules เป็นไฟล์ .md แยกใน .claude/rules/ — Claude จะโหลดทุกไฟล์อัตโนมัติ เทียบเท่ากับ CLAUDE.md
| ไฟล์ | ขอบเขต | ตัวอย่างการใช้งาน |
|---|---|---|
CLAUDE.md |
ใช้ทุกครั้ง (Code Review + Code Gen) | Coding Standard, Architecture |
REVIEW.md |
ใช้เฉพาะ Code Review | กฎที่ต้องตรวจเสมอ, สิ่งที่ไม่ต้องสนใจ |
.claude/rules/*.md |
ใช้ทุกครั้ง (เหมือน CLAUDE.md) | แยกกฎตาม Module เช่น security.md, api.md |
ขั้นตอนที่ 5 — ทดสอบ Review แรก
เมื่อตั้งค่าครบแล้ว ให้ทดสอบด้วยการเปิด PR:
- สร้าง Branch ใหม่จากโค้ดที่มีอยู่
- แก้ไขโค้ดบางส่วน (ลองแก้ให้มีปัญหาเล็กน้อย เช่น ลบ error handling)
- Push Branch แล้วเปิด Pull Request
- รอ ~20 นาที — จะเห็น Check Run "Claude Code Review" ปรากฏขึ้น
- เมื่อ Review เสร็จ จะเห็น:
| ผลลัพธ์ | รายละเอียด |
|---|---|
| Summary Comment | Comment รวมที่สรุปทุกปัญหาที่พบ จัดลำดับตามความรุนแรง |
| Inline Comments | Comment บนบรรทัดโค้ดที่มีปัญหาโดยเฉพาะ พร้อมคำอธิบายและ Suggested Fix |
| Severity Labels | ทุก Finding มี Severity (Critical, High, Medium) เพื่อจัดลำดับความสำคัญ |
ถ้าไม่เห็น Check Run? ตรวจสอบ: (1) Claude GitHub App ติดตั้งและเลือก Repository ถูกต้อง (2) บัญชี Anthropic เป็น Teams Premium หรือ Enterprise (3) Repository ตรงกับที่ตั้งค่าใน Admin Settings
ขั้นตอนที่ 6 — อ่านและตอบกลับผล Review
เมื่อ Claude Code Review ทำงานเสร็จ จะมี Comment ปรากฏบน PR — วิธีจัดการ:
การอ่าน Review Comment
- Summary Comment — อ่านภาพรวมก่อน ดูว่ามีปัญหากี่รายการ ระดับไหนบ้าง
- Inline Comment — คลิกดูแต่ละ Finding บนบรรทัดโค้ดที่มีปัญหา
- Suggested Fix — บาง Finding จะมีโค้ดที่แก้แล้วให้ดู
การตอบกลับ
| สถานการณ์ | วิธีจัดการ |
|---|---|
| เห็นด้วยกับ Finding | แก้โค้ดตาม Suggestion → Push ใหม่ → ถ้าเปิด "After Every Push" ระบบจะ Auto-resolve Thread |
| ไม่เห็นด้วย | Reply อธิบายเหตุผล → Resolve Thread ด้วยตัวเอง (เหมือน Human Review ปกติ) |
| ต้องการข้อมูลเพิ่ม | Reply ถาม Claude → แต่ปัจจุบันยังไม่สามารถตอบกลับได้ (ไม่ใช่ Chat) |
สำคัญ: Claude Code Review จะไม่ Approve PR — มันจะแค่แสดงปัญหาที่พบ การ Approve ยังคงเป็นหน้าที่ของ Human Reviewer เสมอ
ขั้นตอนที่ 7 — ใช้ CLI Mode สำหรับ Local Review
นอกจากการ Review อัตโนมัติผ่าน GitHub App แล้ว ยังสามารถรัน Review จาก Claude Code CLI ได้โดยตรง:
รัน Code Review จาก CLI
# Review PR ปัจจุบัน (แสดงผลใน Terminal) /code-review # Review PR แล้ว Post Comment ลง GitHub /code-review --comment # Review PR เฉพาะหมายเลข /code-review --pr 123
ข้อดีของ CLI Mode:
- ดู Review ก่อน Push ได้ — ไม่ต้องรอเปิด PR
- เลือก Review เฉพาะ PR ที่สนใจ — ไม่ต้อง Review ทุก PR
- ใช้ร่วมกับ
--commentเพื่อ Post ผลขึ้น GitHub ได้ทันที
Best Practices — ใช้ Claude Code Review ให้ได้ผลสูงสุด
| ลำดับ | Best Practice | เหตุผล |
|---|---|---|
| 1 | เขียน CLAUDE.md ให้ละเอียด | ยิ่ง Claude รู้ Context มาก ยิ่ง Review ตรงจุด |
| 2 | ใช้ REVIEW.md กำหนดสิ่งที่ไม่ต้อง Review | ลดเสียงรบกวนจากเรื่องที่ Linter จัดการแล้ว |
| 3 | PR ขนาดเล็ก (<500 บรรทัด) | Review เร็วขึ้น + ค่าใช้จ่ายต่ำลง + ผลแม่นยำกว่า |
| 4 | อย่าเพิกเฉย Critical Findings | Claude reject <1% — ถ้ามันบอกว่า Critical มักจะจริง |
| 5 | ใช้ร่วมกับ Security Scan อื่นๆ | Claude เก่งเรื่อง Logic + Context แต่ควรมี SAST/DAST ด้วย |
| 6 | Review ผล Review — ปรับ Rules ต่อเนื่อง | ถ้าพบ False Positive ซ้ำ → เพิ่มใน REVIEW.md ส่วน "Ignore" |
GitHub Actions — ตั้งค่า Workflow แบบ Advanced
สำหรับทีมที่ต้องการควบคุมมากขึ้น สามารถใช้ GitHub Actions แทน GitHub App ได้:
ตัวอย่าง .github/workflows/claude-review.yml
name: Claude Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run Claude Code Review
uses: anthropics/claude-code-review@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
confidence_threshold: 80
การตั้งค่า API Key:
- ไปที่ Repository → Settings → Secrets and variables → Actions
- คลิก "New repository secret"
- ตั้งชื่อ ANTHROPIC_API_KEY
- วาง API Key จาก console.anthropic.com
GitHub App vs GitHub Actions
- GitHub App: ง่ายกว่า ไม่ต้องจัดการ API Key เอง — Anthropic จัดการให้
- GitHub Actions: ยืดหยุ่นกว่า ปรับ Workflow ได้ตามใจ — แต่ต้องจัดการ API Key เอง
Confidence Threshold — ปรับความเข้มงวด
Confidence Threshold คือตัวเลข 0-100 ที่กำหนดว่า Claude ต้องมั่นใจแค่ไหนถึงจะรายงาน Issue:
| Threshold | ผลลัพธ์ | เหมาะกับ |
|---|---|---|
| 60 | แจ้งเยอะ — มี False Positive มากขึ้น | โปรเจกต์ที่ต้องการตรวจละเอียดสุดๆ (เช่น ระบบ Security-Critical) |
| 80 (ค่าเริ่มต้น) | สมดุล — แจ้งเฉพาะที่มั่นใจสูง | ทีมส่วนใหญ่ |
| 95 | แจ้งน้อย — เฉพาะปัญหาร้ายแรงจริงๆ | ทีมที่ต้องการลด Noise ให้ต่ำสุด |
สถิติจากการใช้งานจริงของ Anthropic
Anthropic ใช้ Claude Code Review กับทุก PR ภายในบริษัทตัวเอง — ผลลัพธ์:
| ตัวชี้วัด | ก่อนใช้ | หลังใช้ |
|---|---|---|
| PR ที่ได้ Substantive Comment | 16% | 54% (+238%) |
| PR ใหญ่ (>1,000 บรรทัด) ที่พบปัญหา | — | 84% (เฉลี่ย 7.5 issues) |
| PR เล็ก (<50 บรรทัด) ที่พบปัญหา | — | 31% (เฉลี่ย 0.5 issues) |
| อัตรา Rejection | — | <1% |
ตัวเลขเหล่านี้แสดงว่า Claude Code Review ช่วยเพิ่มคุณภาพการ Review อย่างมีนัยสำคัญ — โดยเฉพาะ PR ขนาดใหญ่ที่คนมักไม่มีเวลา Review ละเอียด
Claude Code Review ในบริบทองค์กรไทย
สำหรับองค์กรไทยที่มีทีมพัฒนาซอฟต์แวร์ Claude Code Review สามารถช่วยได้ในหลายสถานการณ์:
- ทีมเล็กไม่มี Senior Review — ใช้ Claude เป็น "Senior Developer คนที่สอง" ตรวจโค้ดให้
- โปรเจกต์ ERP ที่มีโค้ดเยอะ — ระบบ ERP มักมีหลายร้อย Module ตรวจด้วยคนอย่างเดียวไม่ทัน
- การปฏิบัติตาม มาตรฐานความปลอดภัย — กำหนดใน CLAUDE.md ว่าต้องตรวจอะไรบ้าง เช่น SQL Injection, 2FA
- Outsource หรือ AI เขียนโค้ด — ตรวจสอบคุณภาพโค้ดจากภายนอกก่อน Merge
สรุป — Checklist ตั้งค่า Claude Code Review
| ขั้นตอน | รายการ | สถานะ |
|---|---|---|
| 1 | มี Claude for Teams Premium หรือ Enterprise | |
| 2 | เปิดใช้ Code Review จาก Admin Settings | |
| 3 | ติดตั้ง Claude GitHub App + เลือก Repository | |
| 4 | เลือก Trigger Mode (PR Creation / Every Push / CLI) | |
| 5 | สร้าง CLAUDE.md + REVIEW.md | |
| 6 | ทดสอบด้วย PR แรก + ตรวจว่า Check Run ปรากฏ | |
| 7 | ปรับ Confidence Threshold ตามความเหมาะสม |
Claude Code Review ไม่ได้มาแทน Human Reviewer — แต่มาเป็น "สายตาคู่ที่สอง" ที่ไม่เคยเหนื่อย ไม่เคยลืม และไม่เคยอ่านโค้ดผ่านๆ — สิ่งที่ทีมต้องทำคือ "บอกมันว่าต้องดูอะไร" ผ่าน CLAUDE.md
- ทีมงาน Saeree ERP
อ่านต่อ — EP 1 และ EP 3
- EP 1: Claude Code Review คืออะไร? — ระบบ Multi-Agent ตรวจโค้ดอัตโนมัติ
- EP 3: เปรียบเทียบ Claude Code Review vs คู่แข่ง + ราคาและความคุ้มค่า
แหล่งอ้างอิง
- Claude Code Official Docs — Code Review
- Claude Code Official Docs — GitHub Actions
- TechCrunch — Anthropic launches code review tool
- The New Stack — Anthropic launches multi-agent code review
หากองค์กรของคุณกำลังมองหาระบบ ERP ที่พัฒนาด้วยมาตรฐานสูงและให้ความสำคัญกับคุณภาพซอฟต์แวร์ สามารถนัดหมาย Demo หรือติดต่อทีมที่ปรึกษาเพื่อพูดคุยเพิ่มเติม
