Best Practices — Hướng dẫn thực hành

Tổng hợp kinh nghiệm sử dụng Claude Code skills hiệu quả — từ nguyên tắc cơ bản đến workflow nâng cao cho team.
Trang này là reference chính cho team mới onboarding và team hiện tại cải thiện workflow. Bookmark lại!

1. Nguyên tắc vàng

4 nguyên tắc bất di bất dịch khi dùng Claude Code:
#Nguyên tắcLý do
1Luôn plan trước khi codePlan mất 30 giây, skip plan mất 30 phút debug
2Diagnose trước khi fixFix triệu chứng → bug quay lại. Fix root cause → xong hẳn
3Test trước khi shipCode không có test = code chưa xong
4Review trước khi mergeThêm 1 đôi mắt = bớt 10 bugs trên production
Không có ngoại lệ cho 4 nguyên tắc trên — kể cả “hotfix gấp” hay “task nhỏ xíu”.

2. Anti-patterns — Sai lầm phổ biến

Bảng suy nghĩ sai → thực tế

Suy nghĩ saiThực tế
”Task đơn giản, khỏi plan”Task đơn giản ẩn complexity. Plan mất 30 giây, tiết kiệm rất nhiều token
”Biết rồi, code luôn”Biết ≠ plan. Viết ra thì mới thấy thiếu sót
”Để code xong rồi plan sau”Đó không phải planning, đó là hy vọng
”Fix thử cái này xem”Đoán không bằng chẩn đoán. Dùng /ck-debug
”Thử fix lần nữa” (lần thứ 3+)3 lần fail = sai approach. Dừng lại, bàn lại
”Skip test cho nhanh”Nhanh hôm nay, chậm cả tuần khi bug lên production

Sai lầm theo từng nhóm lệnh

Sai:
  • Dùng /plan:fast cho feature phức tạp → thiếu research, plan sai
  • Plan quá rộng (8+ files trong 1 phase) → khó review, dễ conflict
  • Skip /plan:validate → assumptions sai, phải rewrite
Đúng:
  • /plan:hard cho feature mới, /plan:fast cho task đã rõ requirements
  • Mỗi phase nên dưới 5 files
  • Luôn validate plan trước khi cook

3. Skill Combos — Workflow hiệu quả

Workflow theo tình huống

Chi tiết từng workflow

1

Feature mới (phức tạp)

/plan:hard "mô tả feature"     # Research + plan chi tiết
/plan:validate                   # Validate assumptions
/cook                           # Implement (auto: plan, code, test, review)
/ship                           # Merge, push, tạo PR
2

Feature mới (đơn giản)

/cook "mô tả ngắn"             # Plan + implement luôn
# Hoặc:
/cook:auto:fast "task nhỏ"     # Nhanh nhất cho task rõ ràng
3

Fix bug

/scout "tìm file liên quan"     # Tìm code liên quan
/ck-debug "mô tả bug"          # Chẩn đoán root cause
/fix "mô tả fix"               # Fix với regression test
/qa-full:regression src/file.ts # Verify không break gì
4

Trước release

/qa-full:full                   # Full QA: unit + E2E + security + a11y
/deploy-checklist               # Checklist trước deploy
# Merge staging → main
/health-check                   # Verify sau deploy

4. Quy tắc an toàn

Khi nào dùng --auto vs --interactive

Tình huốngModeLý do
Feature mới, phức tạp--interactiveCần review gates ở mỗi bước
Bug fix đơn giản--interactive (default)Vẫn cần verify root cause
Task nhỏ, rõ ràng, low-risk--auto hoặc --fastOK skip review nếu confident
Refactoring lớn--interactiveCần approval trước khi thay đổi nhiều
Production hotfix--interactiveHotfix cần extra careful

Hard Gates — Không skip được

GateÝ nghĩa
Plan → CodeKhông có plan thì không được code
Test → ShipTests phải PASS 100% mới được ship
Review → MergeCode phải qua review mới merge
Security → DeploySecurity scan phải clean trước deploy

Rollback Strategy

Khi có vấn đề sau deploy:
  1. Nếu biết nguyên nhân: Hotfix branch → fix → test → deploy
  2. Nếu chưa rõ: Revert commit → deploy lại version cũ → investigate
  3. Nếu data bị ảnh hưởng: Rollback migration (nếu có) → notify stakeholders

5. Team Adoption — Áp dụng cho team

Onboarding checklist cho thành viên mới

1

Cài đặt Claude Code CLI

npm install -g @anthropic-ai/claude-code
claude                          # Verify installation
2

Đọc tài liệu

3

Thực hành với task nhỏ

/plan:fast "task đầu tiên"      # Thử plan
/cook                           # Thử implement
/test                           # Thử chạy tests
4

Tham gia sprint

Làm việc theo Sprint Workflow. Hỏi team khi unsure.

Sprint workflow integration

Thời điểmDev dùngQC dùngPM dùng
Sprint planning/plan cho assigned features/qa-full:audit health check/sprint-plan
Hàng ngày/cook, /fix/qa-full:verify-issue/daily-standup
Code xong/test, /code-review/qa-full:check, /qa-full:acceptReview demo
Trước release/ship/qa-full:full, securityRelease approval

Cross-team handoff

HandoffTừĐếnCách làm
Feature specPMDevPM: /prd → Dev nhận issue từ GitHub
Code completeDevQCDev: push to staging → QC: /qa-full:verify-issue
QA passQCDevQC: label “QA-passed” → Dev: /ship
Bug foundQCDevQC: /bug-report → Dev: /fix
ReleaseDevDevOpsDev: PR staging→main → DevOps: /deploy-checklist

6. Troubleshooting — Xử lý sự cố

Khi context hết giữa chừng

# Tình huống: Claude Code hết context window giữa task
# Giải pháp:
/watzup                            # Xem tóm tắt đã làm gì
# Sau đó:
/clear                             # Clear context
/cook plans/path/to/plan.md       # Resume từ plan (plan giữ state)

Khi skill output không như mong đợi

Vấn đềGiải pháp
Plan quá phức tạpChia nhỏ: /plan:fast cho từng phần
Cook không follow planKiểm tra plan file, /cook path/to/plan.md explicit
Fix không tìm root causeDùng /ck-debug trước /fix
Test coverage thấp/qa-full:check để identify gaps
Code review quá strictĐiều chỉnh scope, fix critical issues trước

Khi tests flaky

# 1. Identify flaky tests
/test                              # Chạy nhiều lần, note failing tests

# 2. Investigate
/ck-debug "test X flaky — fails intermittently"

# 3. Common causes:
# - Timing issues → thêm waitFor/retry
# - Shared state → isolate tests
# - External dependencies → mock external calls
# - Race conditions → ensure proper async/await

Khi deploy bị lỗi

/incident-response                 # Kích hoạt quy trình xử lý sự cố
# Hoặc nếu biết nguyên nhân:
/fix:ci                           # Fix CI/CD issues
Quy tắc vàng khi troubleshoot: Đọc error message kỹ TRƯỚC khi hỏi Claude. 80% câu trả lời nằm trong error message.

7. Giới hạn cần biết

Hiểu giới hạn để tránh bẫy — skills KHÔNG phải magic.

Claude có thể skip instructions

Skills là markdown text. Claude đọc nhưng có thể không làm (~20% skip rate). Cách giảm thiểu:
  • Dùng markers MANDATORY, KHÔNG SKIP trong instructions
  • Check output xem có đủ bước không
  • Nếu skip → gõ lại lệnh, nhắc cụ thể bước bị thiếu

Skill gọi skill khác → hay bị skip

Khi skill A gọi /ck:scenario bên trong, Claude hay dùng Agent tool thay vì Skill tool → skill không chạy đúng. Giải pháp: Luôn gõ TRỰC TIẾP mỗi skill:
# SAI: Để qa-full tự gọi ck:scenario bên trong
/qa-full:full "feature"

# ĐÚNG: Gọi riêng từng bước
/ck:scenario "feature"              # Bước 1: USER gõ trực tiếp
/qa-full:full "feature"             # Bước 2: USER gõ trực tiếp

Context window dilution

Plan lớn (4 sprints) → output ít chi tiết hơn per-sprint. Giải pháp:
  • Dùng --sprint N cho per-sprint output
  • Scout TRƯỚC rồi mới spawn agents (truyền context)
  • KHÔNG dùng /clear giữa chừng (mất context)
  • Nếu context gần hết → /watzup để save state → /clear → resume với plan path

8. Checklists thực hành

Trước khi bắt đầu feature mới

  • cd vào đúng project folder
  • Đang dùng Claude Code CLI (không phải web/desktop)
  • Đã chạy /scout hiểu codebase
  • Đã có plan/PRD hoặc description rõ ràng
  • Branch đúng convention (feat/FXX-YY-*)

Trước khi /cook

  • Có plan file (plans/*.md) đã review
  • PRD, QA, UI specs đã link trong plan
  • Database migration sẵn sàng (nếu schema change)

Trước khi /qa-full

  • Đã chạy /ck:scenario "feature" TRỰC TIẾP
  • Code pass lint + typecheck
  • Unit tests đã viết
  • PRD path sẵn sàng (cho :accept)

Trước khi /ship

  • Đã chạy /code-review
  • CI pass (lint + typecheck + test)
  • Test trên staging OK
  • PR title đúng Conventional Commits
  • No secrets in code

Trước khi Design handoff → Dev

  • Figma link có đầy đủ screens + states
  • Component specs (spacing, colors, typography)
  • Responsive breakpoints defined
  • Error/empty/loading states có
  • PM đã review + approve design

9. So sánh skills hay nhầm lẫn

So sánhSkill ASkill BKhác biệt chính
Plan vs PRD/plan "task"/docs-project:prdPlan = how to build, PRD = what to build. PRD trước, plan sau
Predict vs Validate/ck:predict/plan:validatePredict = AI tự hỏi AI (5 personas). Validate = AI hỏi USER
QA Full vs QA vs Test/qa-full:full/qa (GStack)/test chạy tests. /qa quick check. /qa-full:full = 6 bước toàn diện + security
Cook vs Code/cook/codeCook đọc plan + viết tests + review. Code = quick implementation
Fix vs Debug/fix "bug"/debug "error"Fix = auto fix. Debug = chỉ diagnose, không sửa
Code Review vs Review/code-review (CK)/review (GStack)CK = sâu, có agents. GStack = nhanh, structured
Scout vs Understand/scout/understandScout = tìm files nhanh. Understand = build knowledge graph