Mục tiêu học tập

Sau bài này, bạn sẽ có thể:
  • ✅ So sánh skill với 4 cơ chế còn lại trong Claude Code: CLAUDE.md, subagent, hook, MCP server
  • ✅ Chọn đúng công cụ cho mỗi use case qua decision tree rõ ràng
  • ✅ Thiết kế setup kết hợp nhiều cơ chế — không force mọi thứ vào skill
  • ✅ Nhận diện 3 anti-pattern phổ biến khi dev lẫn lộn các cơ chế

Mở đầu: “Tôi đã có CLAUDE.md, tôi cần skill làm gì?”

Đây là câu hỏi nhận được mỗi khi giới thiệu skill với team đã quen Claude Code. Họ có CLAUDE.md, có slash command, một số team tiến xa hơn có subagent, hook, MCP server. Ôi thôi, thêm skill nữa à? Câu trả lời ngắn: Không. Bạn không thêm skill. Bạn dùng đúng công cụ cho đúng việc. Skill không thay thế những cơ chế kia — nó fill in cái gap mà chúng không giải quyết tốt. Otto (Anthropic) đưa ra công thức ngắn gọn nhất:
“Your CLAUDE.md file sets the foundation, MCP servers connect the data, subagents specialize in their roles, and Skills bring the expertise — making every piece smarter and more capable.”
Foundation. Data. Roles. Expertise. Mỗi thứ có vai trò riêng, không overlap. Bài này sẽ:
  • So sánh skill với từng cơ chế riêng biệt
  • Đưa decision tree để bạn quyết định nhanh
  • Cho case study setup đầy đủ kết hợp cả 5 cơ chế

5 cơ chế customize Claude Code — overview

Mental model: Claude Code như một layered system

Bạn không chọn 1 trong 5. Setup thực tế dùng nhiều cơ chế cùng lúc, mỗi cái một vai trò.

Skill vs CLAUDE.md — Load khi nào?

CLAUDE.md: Always-on

File này load vào system prompt mọi conversation. Luôn có mặt. Claude luôn biết “dự án này là Next.js”.

Skill: On-demand

Skill pr-review chỉ load khi bạn nói “review PR này”. Còn lại, nó ngủ.

Khi nào dùng cái nào?

Ví dụ thực tế — quyết định 5 trường hợp

Anti-pattern: CLAUDE.md phình to

Sai lầm: Nhồi mọi instruction vào CLAUDE.md — review checklist, email template, report format, debug procedure… Hậu quả: Mỗi conversation ăn 40% context cho content có thể chỉ cần 5%. Cách đúng: CLAUDE.md chỉ giữ thứ luôn áp dụng. Còn lại → skill. Otto hỏi ngược: “Look at your current CLAUDE.md file. Is there anything in it that would work better as a skill (loaded only when relevant)?” Answer cho hầu hết team: có.

Skill vs Subagent — Cùng context vs isolated

Skill: Join current context

Khi skill pr-review trigger, nó thêm instructions vào cuộc hội thoại đang chạy. Context hiện tại (code bạn đang xem, conversation history) vẫn ở đó. Skill làm Claude thông minh hơn trong context hiện tại.

Subagent: Separate context

Subagent là Claude khác chạy trong context riêng, isolated. Bạn delegate task cho nó, nó làm xong, trả result về bạn. Nó không thấy conversation history của bạn, không share context.

Khi nào dùng cái nào?

Dùng Skill khi:
  • Bạn muốn cùng conversation smarter về task
  • Expertise apply throughout remaining conversation
  • Ví dụ: activate PR review skill → mọi review tiếp theo trong session vẫn có expertise đó
Dùng Subagent khi:
  • Bạn muốn task độc lập — không pollute main context
  • Cần tool access khác main conversation (ví dụ subagent có quyền Bash mà main không có)
  • Parallelize: chạy 5 subagent concurrent cho 5 file khác nhau
  • Ví dụ: delegate “phân tích 10 file log” cho subagent — kết quả về main, không bloat main context

Skill ↔ Subagent: Hoạt động cùng nhau

Đây là điểm quan trọng dễ miss: Subagent có thể dùng skill. Otto giải thích:
“Your front-end developer subagent can use a component pattern skill. Your UI reviewer subagent can use a design system skill, but both can load and use the same accessibility standard skill.”
Skill là portable expertise — share được giữa subagent. Bạn không build lại expertise cho mỗi subagent. Setup mẫu:
Chi tiết config subagent với skill ở Bài 15.5. ⚠️ Gotcha quan trọng Built-in agent (Explorer, Plan, Verify) không access skill. Otto: “Built-in agents can’t access skills at all. Only custom subagents you define can use them and only when you explicitly list them.” Skill load khi subagent start, không on-demand như main conversation. Nên chỉ list skill luôn relevant cho purpose của subagent.

Skill vs Hook — Request-driven vs Event-driven

Hook: Fire on event

Hook là automation chạy khi có event xảy ra:
  • File save → run linter
  • Before bash call → validate input
  • After Edit tool → auto-format
Hook không cần Claude “decide”. Nó fire automatically khi event match.

Skill: Fire on request

Skill trigger khi user hỏi điều match với description. Claude làm trung gian.

Khi nào dùng cái nào?

Rule of thumb

  • Hook = “operation chạy không cần Claude suy nghĩ” — tự động, deterministic
  • Skill = “knowledge để Claude dùng khi reasoning” — Claude vẫn là người quyết định

Case: Lint workflow

Cách tệ (dùng skill):
Problem: Skill chỉ trigger khi user nói “commit”. Nếu user quên → không lint. Cách đúng (dùng hook):
Hook fire luôn luôn khi có bash command match git commit. Không dựa vào user.

Skill vs MCP Server — Expertise vs Data connection

Đây là phần gây confuse nhất. Vì cả skill và MCP đều “extend Claude”.

MCP (Model Context Protocol): Connection tới external world

MCP là open protocol cho phép Claude truy cập data/service bên ngoài:
  • MCP server cho GitHub → Claude đọc/write issue, PR, code
  • MCP server cho Postgres → Claude query database
  • MCP server cho Slack → Claude đọc tin nhắn
MCP server expose tools để Claude gọi. Ví dụ:
Claude dùng các tool này khi cần data đó.

Skill: Expertise về cách làm gì với data

Skill không fetch data. Skill chứa instructions.

Otto’s killer one-liner

“MCP connects to data, Skills teach Claude what to do with it.”
Clean nhất trong tất cả explanation. Memorize đi.

Ví dụ cụ thể — MCP + Skill hoạt động cùng nhau

Setup:
User: “Review PR #142” Claude:
  • Match skill pr-review → load instructions
  • Instructions nói: gh pr view 142 hoặc dùng MCP github.get_pr(142) lấy diff
  • Instructions nói: check X, Y, Z theo checklist
  • Instructions nói: comment review qua MCP github.comment_pr(142, ...)
MCP cho access tới GitHub. Skill dạy Claude quy trình review. Không cái nào đủ một mình:
  • Chỉ MCP không skill → Claude có thể đọc PR nhưng review không theo style team
  • Chỉ skill không MCP → Claude biết cách review nhưng không access được PR

Setup cho team thực tế

Litton (AI University) cho workflow mẫu:
“Skills can call MCP servers. That means Claude can connect with Gmail, Slack, Telegram and even your CRM.”
Skill orchestrate. MCP cung cấp tool. 2 thứ complement, không compete.

Decision

Decision Tree — Chọn cơ chế nào?

Flowchart dạng checklist

  • Cần fetch data từ GitHub/Slack/DB/API? → MCP server
  • Cần side-effect tự động khi save/call tool? → Hook
  • Instruction luôn luôn áp dụng trong mọi conversation của project? → CLAUDE.md
  • Muốn task chạy isolated, không pollute main context? → Subagent
  • Instruction chỉ áp dụng khi user hỏi về task đó, Claude tự nhận? → Skill

Setup hoàn chỉnh: Case study team engineering

Để thấy 5 cơ chế sống chung thế nào, hãy xem setup của 1 team engineering giả lập nhưng realistic: Team 12 người, làm SaaS trên Next.js 14 + TypeScript + Postgres. Ship code hàng tuần. Yêu cầu: code quality, security, consistency.

Tầng 1: CLAUDE.md — Foundation

Vai trò: Foundation context. Claude luôn biết stack + constraint.

Tầng 2: MCP servers — Data connections

Vai trò: Access external data. Skill gọi MCP tool khi cần.

Tầng 3: Skills — Expertise

Vai trò: Task-specific expertise. Trigger on-demand khi team member làm task đó.

Tầng 4: Subagents — Specialized roles

Vai trò: Isolated task delegation. Khi tech lead gõ “ask frontend-reviewer to check PR #142” → subagent chạy riêng.

Tầng 5: Hooks — Automation

Vai trò: Auto-format sau mỗi edit, chạy lint+test trước push.

Kết quả

Workflow điển hình của 1 dev:
  • Dev mở task “thêm API endpoint”. CLAUDE.md đã cho Claude biết stack + convention.
  • Dev gõ “tạo API route cho POST /api/users”. Skill api-route-generator trigger (đúng convention team).
  • Claude generate code qua MCP file system + pnpm tool.
  • Dev edit code → Hook prettier --write auto format.
  • Dev commit. Skill commit-format trigger khi nói “viết commit message”.
  • Dev push → Hook pnpm lint && pnpm test chạy.
  • Dev mở PR qua MCP GitHub. Skill pr-review bảo subagent backend-reviewer review → subagent dùng skills pr-review, api-conventions, sql-perf-check cho review toàn diện.
5 tầng, mỗi tầng 1 vai trò. Không cơ chế nào làm việc của cơ chế khác.

Anti-patterns — Khi dev lẫn lộn các cơ chế

❌ Anti-pattern 1: Nhồi review checklist vào CLAUDE.md

Triệu chứng: CLAUDE.md 800 dòng, nửa là review checklist không ai cần khi đang viết feature mới. Tại sao tệ: Overhead mỗi conversation. Claude confused (quá nhiều context). Cách đúng: Review checklist → skill pr-review. CLAUDE.md giữ foundation (stack, convention luôn áp dụng).

❌ Anti-pattern 2: Dùng skill thay cho hook

Triệu chứng: Skill auto-format-on-save description “Formats code after save. Use whenever editing.” Tại sao tệ: Skill chỉ fire khi user nói gì đó match. Save file không phải là “user request” → skill không trigger. Format không happen. Cách đúng: Hook PostToolUse fire on Edit tool. Skill dành cho “expertise Claude cần suy nghĩ để apply”, không phải automation mechanical.

❌ Anti-pattern 3: MCP cho mọi thứ

Triệu chứng: Build MCP server cho “team coding standards” — trả về rules. Tại sao tệ: MCP thiết kế cho data/service external. Coding standard là expertise, không phải data cần fetch. Overhead, slow, complex. Cách đúng: Coding standard → skill với instructions. Dùng MCP cho data thực sự ở external system.

❌ Anti-pattern 4: Subagent thay vì skill

Triệu chứng: Tạo subagent pr-reviewer thay vì skill pr-review. Tại sao tệ: Subagent chạy isolated context → mất context PR bạn đang xem. Phải pass lại toàn bộ context. Overhead. Cách đúng: Skill pr-review join main context, review với full context sẵn có. Chỉ dùng subagent khi cần isolation thực sự (parallelization, different tool access, large delegated task).

Áp dụng ngay

Bài tập 1: Audit CLAUDE.md của bạn (~10 phút)

Mở CLAUDE.md của project hiện tại. Đọc từng section, trả lời cho mỗi section: Ghi ra:
  • Section cần giữ ở CLAUDE.md: _____
  • Section cần move thành skill: _____
  • Ước tính % giảm size CLAUDE.md: _____

Bài tập 2: Thiết kế setup cho use case của bạn (~10 phút)

Pick 1 workflow bạn làm thường xuyên (ví dụ: “review PR”, “ship feature”, “on-call response”). Điền bảng: Nếu trả lời có 5 cơ chế khác nhau — bạn đã hiểu rồi.

Tóm tắt bài học

🎯 5 cơ chế, 5 vai trò. CLAUDE.md = foundation. MCP = external data. Subagent = isolated roles. Skill = on-demand expertise. Hook = event automation. 🎯 Otto’s one-liner: “MCP connects to data, Skills teach Claude what to do with it.” 🎯 Decision tree quick check: Cần external data? → MCP. Event-driven? → Hook. Luôn áp dụng? → CLAUDE.md. Isolated? → Subagent. On-demand task expertise? → Skill. 🎯 Combine, không compete. Setup hoàn chỉnh dùng cả 5 cơ chế. Skill gọi MCP, subagent dùng skill, hook complement skill. 🎯 Skill là đúng khi: (1) task-specific, (2) Claude tự nhận qua semantic, (3) join current context, (4) portable qua project (personal) hoặc share team (project).

Bài tiếp theo

Bạn đã có skill cá nhân. Nhưng skill chỉ thực sự có giá trị khi share cho team/tổ chức — team standardize review, new hire onboard nhanh, compliance consistent. Bài 15.5 đi sâu 3 cách share: commit vào repo (đơn giản nhất), qua plugin marketplace (cross-org), và enterprise managed settings (deploy toàn tổ chức với priority cao nhất). Plus: gotcha lớn về subagent + skill. ➡️ Bài tiếp theo: Bài 15.5: Chia sẻ skill với team & tổ chức

Tài liệu tham khảo

  • Anthropic Academy — “Skills vs. other Claude Code features”
  • Video — “Choosing the right feature”
  • Model Context Protocol — MCP spec
  • Otto, “Claude Agent Skills Explained” — quote sources
Bản quyền 2026 Anthropic. Phiên bản tiếng Việt tinh chế. Mọi quyền được bảo lưu.