Claude Code — Senior Code Reviewer sub-agent
ระบบ system prompt สำหรับ sub-agent ตรวจสอบโค้ดระดับ Senior ที่คัดกรองเฉพาะปัญหาสำคัญจริงๆ ไม่รายงานเรื่องเล็กน้อย พร้อมตัวอย่างผลลัพธ์และคำแนะนำการใช้งานกับเครื่องมือ CI/CD ต่างๆ
ของ lazyyy เอง · อัปเดต 9 ส.ค. 2569
ส่วนประกอบ
Senior Code Reviewer (sub-agent)
คำอธิบาย: system prompt สำหรับ sub-agent ที่ทำหน้าที่ตรวจสอบโค้ดแบบ senior engineer โดยรายงานเฉพาะปัญหาที่มีนัยสำคัญและสมควรให้มนุษย์ทบทวน กรองเรื่องไม่สำคัญออกไป
System Prompt
ใช้ข้อความนี้เป็น system prompt ของ review sub-agent:
You are a meticulous staff engineer reviewing a diff. Report ONLY:
- Correctness bugs (wrong output, off-by-one, race conditions, null/undefined)
- Security issues (injection, authz gaps, secret leakage, SSRF)
- Data-loss or migration hazards
- Public API / contract breaks
For each finding output:
file:line — <one-line problem> — <concrete fix>
Rules:
- No style/formatting/naming nits. A linter handles those.
- If you are <80% sure it's a real defect, DROP it.
- Prefer 3 real bugs over 20 maybes. Empty output is a valid result.
ทำไมถึงได้ผล
- กรองความมั่นใจ (
<80% → drop): ตัดเรื่องที่ "ดูเหมือนจะผิด" แต่ไม่แน่ใจออกไป - บังคับให้ระบุ
file:line + fix: ทำให้ทุกข้อสรุปนำไปแก้ไขได้ทันที
ตัวอย่างผลลัพธ์
Input (git diff):
+ const userId = req.query.id;
+ const user = await db.query(`SELECT * FROM users WHERE id = ${userId}`);
Output จาก sub-agent:
auth.js:42 — SQL injection via unsanitized req.query.id — Use parameterized query: db.query('SELECT * FROM users WHERE id = ?', [userId])
การใช้งาน
ขั้นตอน
- สร้าง review sub-agent และวาง prompt ข้างต้นเป็น system prompt
- ป้อน
git diff origin/main...HEADเข้าไป - ตรวจสอบรายการที่ได้ (มักจะสั้นและตรงประเด็น)
Platform/Tool ที่แนะนำ
- GitHub Actions: ใช้กับ workflow PR review (Claude API + Actions)
- GitLab CI/CD: เรียก Claude API ใน
.gitlab-ci.yml - Pre-commit hooks: ตรวจก่อน push (ต้องมี API key)
- IDE plugins: VSCode, JetBrains ที่รองรับ Claude
ภาษาโปรแกรมที่รองรับ
Prompt นี้ออกแบบให้ครอบคลุมทุกภาษา โดยมุ่งเน้นปัญหาหลักการที่เหมือนกัน:
- ✅ ได้ผลดีกับ: JavaScript/TypeScript, Python, Go, Java, Rust, Ruby, PHP
- ✅ ตรวจจับ: logic bugs, SQL injection, XSS, race conditions, API breaking changes
- ⚠️ ประสิทธิภาพขึ้นกับ: ความรู้ของโมเดล Claude ในภาษานั้นๆ (ภาษายอดนิยมจะแม่นยำกว่า)
Tips
- ถ้า output ว่างเปล่า = โค้ดผ่านการตรวจสอบ (ไม่ใช่ error)
- ใช้ร่วมกับ linter/formatter เพื่อจัดการเรื่อง style
- ปรับ threshold
80%ได้ตามความเข้มงวดที่ต้องการ