Cơ chế Skill — 4 Lớp cấu trúc
ClaudeKit được xây dựng từ 4 lớp (layers), mỗi lớp có vai trò riêng. Hiểu cơ chế này giúp bạn tùy chỉnh và mở rộng skills theo nhu cầu.Tổng quan 4 Lớp
Luồng hoạt động: Người dùng gõ command (Layer 2) → command gọi skill (Layer 1) → skill có thể delegate cho agent (Layer 3) → hooks (Layer 4) tự động chạy trước/sau events.
Luồng hoạt động chi tiết
Khi bạn gõ/cook "add auth", đây là những gì diễn ra qua 4 layers:
Layer 2 — Command nhận input
File
.claude/commands/cook.md nhận $ARGUMENTS = “add auth”.
Command chứa instructions gọi skill + workflow logic.Layer 1 — Skill xử lý logic chính
File
.claude/skills/cook/SKILL.md được kích hoạt.
Skill đọc instructions, detect mode, bắt đầu workflow 7 bước.
Skill có thể đọc thêm references/*.md (lazy-load khi cần).Layer 3 — Agents được delegate tasks
Skill spawn agents qua Task tool:
researcher→ tìm hiểu codebase (chạy song song)planner→ tạo plancoder→ viết codetester→ viết + chạy testscode-reviewer→ review code Mỗi agent có.claude/agents/ten-agent.mdđịnh nghĩa role + tools.
Layer 1: SKILL.md — Bộ não của skill
File chính định nghĩa logic của skill. Đường dẫn thực tế:Cấu trúc file SKILL.md
Đặc điểm quan trọng
| Thành phần | Vai trò |
|---|---|
| Frontmatter | Metadata: name, description, version, argument-hint |
| Body | Instructions chi tiết — Claude đọc và làm theo |
| HARD-GATE | Điều kiện bắt buộc: không code nếu chưa plan |
| Process Flow | Mermaid diagram là workflow chính thức |
| References | Lazy-load files bổ sung khi cần |
Ví dụ cấu trúc thư mục skill
Layer 2: Commands — Giao diện người dùng
Định nghĩa slash commands mà người dùng gõ trực tiếp. Đường dẫn thực tế:Quy tắc đặt tên — rất quan trọng
- Thư mục = nhóm lệnh (ví dụ:
qa-full/,fix/) - File = tên lệnh (ví dụ:
verify-issue.md,fast.md) - Slash command =
/{thư-mục}:{file}(ví dụ:/qa-full:verify-issue) - Thư mục lồng = sub-group (ví dụ:
ckm/seo/→/ckm:seo:*)
Layer 3: Agents — AI Workers chuyên biệt
Định nghĩa agents chuyên biệt. Đường dẫn thực tế:Cách agents phối hợp
Đặc điểm:- Agents có thể chạy song song (researchers) hoặc tuần tự (coder → tester)
- Mỗi agent có tool access riêng (coder có write, tester có bash)
- Agent có thể delegate cho agent khác (nesting)
- project-manager tổng hợp kết quả cuối cùng
Agents trong ClaudeKit Engineer
| Agent | Vai trò | Chạy khi |
|---|---|---|
planner | Lập kế hoạch | /plan, /cook |
researcher | Tìm hiểu codebase (chạy parallel) | /plan, /plan:hard |
coder | Viết code production | /cook, /code |
fullstack-developer | Full-stack (FE + BE) | /cook:auto:parallel |
tester | Viết & chạy tests | /cook, /test |
qa-engineer | QA chuyên biệt | /qa-full:* |
code-reviewer | Review code quality | /code-review, /review |
docs-manager | Cập nhật tài liệu | /cook (auto) |
project-manager | Tổng hợp kết quả | /cook (auto) |
Layer 4: Hooks — Tự động hóa
Tự động chạy trước/sau các events. Đường dẫn thực tế:Cấu hình trong settings.json
Sơ đồ thời điểm Hook chạy
Các event phổ biến
| Event | Thời điểm | Use case |
|---|---|---|
PreToolUse | Trước khi dùng tool | Validate input, check permissions |
PostToolUse | Sau khi dùng tool | Log, notify, auto-format |
Notification | Khi có notification | Gửi Lark message, email |
Cách skill gọi skill (Skill Chaining)
Skill có thể gọi skills khác để tạo workflow phức tạp:Khi instruction nói “Invoke Skill” → PHẢI gọi skill bằng Skill tool. KHÔNG tự làm thay. Đây là quy tắc nghiêm ngặt.
Ví dụ skill chaining phức tạp
Ví dụ skill chaining trong QA
Tùy chỉnh & mở rộng
Thêm skill mới
Cập nhật skill hiện có
Tối ưu skill
Thêm reference files cho skill
Best practices khi tạo skill:
- Mỗi skill làm 1 việc rõ ràng (Single Responsibility)
- Viết instructions cụ thể, không mơ hồ
- Thêm ví dụ input/output trong SKILL.md
- Dùng skill chaining thay vì tạo skill quá lớn
- Luôn test skill trước khi share cho team
- Dùng
references/folder cho lazy-load content