Agent Skills — Taxonomy ฉบับสมบูรณ์ของ Claude Code
ตอนใช้ Claude Code ครั้งแรก — เรามักเข้าใจว่า "ทุกอย่างอยู่ใน CLAUDE.md"
แต่พอใช้ไปสักพัก — เราเริ่มเจอของแปลก: /deploy ทำงานได้เอง, มี hook ตรวจจับตอนเซฟไฟล์, มี subagent ที่ spawn ไปทำงานแล้วกลับมาบอกผล
"นี่มันไปเอาคำสั่งพวกนี้มาจากไหน?"
Claude Code มีระบบ instruction ที่เป็น ชั้น ๆ (layers) — ไม่ใช่แค่ CLAUDE.md ไฟล์เดียว — แต่มันคือ 4 กลุ่มใหญ่ 20+ กลไก ที่ทำงานใน persistence model ต่างกัน
4 Persistence Models — ไม่ใช่แค่ One-Shot กับ Persistent
| Model | หลักการ | ตัวอย่าง |
|---|---|---|
| 🔒 Persistent | ตั้งครั้งเดียว อยู่ทุก session | CLAUDE.md, settings, skills |
| 🔄 Context-Triggered | โหลดเมื่อบริบทตรงเงื่อนไข | Path-scoped rules, nested CLAUDE.md |
| ⚡ Event-Driven | ทำงานอัตโนมัติเมื่อเหตุการณ์เกิด | Hooks (30+ event types) |
| 🎯 Session-Bound | อยู่แค่ session นี้ | CLI flags, env vars, conversation |
🔒 กลุ่มที่ 1: Persistent — ตั้งครั้งเดียว อยู่ทุก Session
นี่คือ "กระดูกสันหลัง" ของ Claude Code — โหลดทุก session โดยคุณไม่ต้องทำอะไร
CLAUDE.md — 4 ระดับ
| ลำดับ | ตำแหน่ง | Scope | ใช้สำหรับ |
|---|---|---|---|
| 1 |
/etc/claude-code/CLAUDE.md (Linux) |
ทั้งองค์กร | นโยบายความปลอดภัย, มาตรฐานบริษัท |
| 2 | ~/.claude/CLAUDE.md |
ส่วนตัว | ความชอบ, ทางลัดเครื่องมือ |
| 3 | ./CLAUDE.md |
โปรเจกต์ | สถาปัตยกรรม, มาตรฐานโค้ด |
| 4 | ./CLAUDE.local.md |
ส่วนตัว+โปรเจกต์ | ข้อมูลทดสอบ, URL sandbox |
หลักการ: โหลดจาก scope กว้าง → แคบ — คำสั่งโปรเจกต์ override คำสั่งผู้ใช้
# ./CLAUDE.md
## Stack: Go 1.22+, PostgreSQL, chi router
## Rules:
- Interface at consumer
- Error: %w wrapping
- Test: table-driven + httptest
Skills — คลังคำสั่งที่เรียกใช้เมื่อต้องการ
.claude/skills/<name>/SKILL.md
---
description: "Generate database migration files"
model: claude-haiku-4-5 # ใช้ model ถูกเพื่องานง่าย
tools: [read_file, write_file]
---
1. Ask for table name and fields
2. Create timestamped SQL file in db/migrations/
3. Include both UP and DOWN migration
เรียกใช้ด้วย /migration — หรือ Claude auto-detect จาก context
Auto Memory — Claude เขียนบันทึกเอง
คุณแค่บอกว่า "จำไว้ว่าใช้ go test -race เสมอ" — Claude เขียนลง ~/.claude/projects/<name>/memory/ — ครั้งหน้ามันจะจำได้
CLAUDE.md: คุณเขียน | Auto Memory: Claude เขียน
CLAUDE.md: กฎและมาตรฐาน | Auto Memory: สิ่งที่เรียนรู้
Settings — ควบคุมพฤติกรรม
| ไฟล์ | Scope |
|---|---|
~/.claude/settings.json |
ผู้ใช้ (ทุกโปรเจกต์) |
.claude/settings.json |
โปรเจกต์ |
.claude/settings.local.json |
โปรเจกต์ (ส่วนตัว) |
{
"permissions": {
"allow": ["Bash(npm test:*)", "Read(~/*)"],
"deny": ["Bash(rm:*)", "Write(/etc/*)"]
}
}
🔄 กลุ่มที่ 2: Context-Triggered — โหลดเฉพาะเมื่อจำเป็น
นี่คือ skills ที่ "ฉลาด" — ไม่โหลดเข้าทุก session — แต่โหลดเมื่อบริบทตรงเงื่อนไข
Path-Scoped Rules
.claude/rules/api-design.md
.claude/rules/css-styling.md
Claude จะโหลด api-design.md เมื่อทำงานกับไฟล์ใน src/api/ — และไม่โหลด css-styling.md ถ้าคุณไม่ได้แตะ CSS
# .claude/rules/api-design.md
## When: working in src/api/**/*.go
- Always return JSON with `{data, error}` envelope
- Rate limit: 100 req/min per user
- Use `context.Context` for cancellation
Nested CLAUDE.md
project/
├── CLAUDE.md ← โหลดเสมอ
├── backend/
│ └── CLAUDE.md ← โหลดเมื่อเข้าถึง backend/
└── frontend/
└── CLAUDE.md ← โหลดเมื่อเข้าถึง frontend/
ใช้สำหรับ monorepo — แต่ละ sub-project มี context ของตัวเอง
Skill Content — โหลดเมื่อเรียกใช้
Skills metadata (ชื่อ + description) อยู่ใน context ตลอด — แต่เนื้อหาเต็มของ skill โหลดเฉพาะตอน /skill หรือตอน Claude auto-detect
⚡ กลุ่มที่ 3: Event-Driven — ทำงานอัตโนมัติเมื่อเหตุการณ์เกิด
นี่คือ layer ที่ทรงพลังที่สุด — และคนส่วนใหญ่ไม่รู้ว่ามี
Hooks — 30+ Event Types
| กลุ่ม | Events |
|---|---|
| 🔵 Session | SessionStart, Setup, PreCompact, PostCompact, SessionEnd |
| 🟢 User | UserPromptSubmit, MessageDisplay |
| 🟡 Tool | PreToolUse, PostToolUse, PostToolUseFailure, PermissionRequest |
| 🟠 Subagent | SubagentStart, SubagentStop |
| 🔴 System | Notification, ConfigChange, FileChanged |
ตัวอย่าง Hook: "ก่อน Claude จะรัน git push — รัน test ก่อนเสมอ"
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash(git push:*)",
"command": "npm test && npm run build"
}
]
}
}
5 ประเภท Handler:
| Handler | ใช้เมื่อ |
|---|---|
| Command | Shell script (รับ JSON stdin) |
| HTTP | เรียก API ภายนอก |
| Prompt-based | ใช้ LLM ตรวจสอบ semantic |
| Agent-based | งานซับซ้อนหลายขั้นตอน |
| MCP tool | เชื่อมต่อเครื่องมือ MCP |
Subagents — ตัวแทนย่อย
.claude/agents/reviewer.md
.claude/agents/tester.md
---
description: "Code reviewer — checks Go idioms and naming"
model: claude-haiku-4-5
tools: [read_file, grep, glob]
---
You review Go code for:
- Interface at consumer, not producer
- Error wrapping with %w
- Table-driven tests
Claude จะ spawn subagent ไปทำงาน — ผลลัพธ์ไม่เข้า context window ของ parent — ประหยัด token
🎯 กลุ่มที่ 4: Session-Bound — อยู่แค่ Session นี้
| กลไก | ตัวอย่าง |
|---|---|
| CLI Flags |
--model claude-opus-4-8, --permission-mode plan
|
| Env Vars |
ANTHROPIC_API_KEY, CLAUDE_CODE_MODEL
|
| Output Styles |
/config → เลือก Default/Proactive/Explanatory/Learning |
| Inline Memory |
/memory → แก้ไขระหว่าง session |
| Conversation | การสนทนาทั้งหมดใน session นี้ |
📊 ลำดับการโหลด — เกิดอะไรขึ้นตอน Claude Code เริ่มทำงาน
1. SYSTEM PROMPT (built-in)
└── Output style ปรับแต่ง
2. CLAUDE.MD (เรียงลำดับ)
└── Managed → User → Project → Local
3. AUTO MEMORY
└── 200 บรรทัดแรก
4. SKILLS METADATA
└── ชื่อ + description
5. MCP TOOLS
└── Tool definitions
6. HOOKS FIRE
└── SessionStart → Setup → InstructionsLoaded
7. USER PROMPT
└── ข้อความแรกจากคุณ
📦 ติดตั้ง Skills จากข้างนอก — เราได้อะไรมาบ้าง?
คำสั่งยอดนิยมที่เห็นใน community:
npx skills@latest add mattpocock/skills
หรือจาก marketplace อื่น:
claude plugin install <name>@<marketplace>
ได้อะไรมาบ้าง? — มันไม่ใช่แค่ "skill" ธรรมดา
mattpocock/skills (157K ⭐ บน GitHub) คือ Claude Code Plugin — ไม่ใช่แค่ไฟล์ skill เดียว — แต่มันคือ package ที่รวมทุก layer ใน taxonomy พร้อมกัน:
| สิ่งที่ได้ | อยู่ในโฟลเดอร์ | คือ layer ไหน |
|---|---|---|
Skills (/review, /test, /plan) |
.claude-plugin/ → skills |
Persistent |
| Subagents (code-reviewer, tester) | .agents/ |
Event-Driven |
| Hooks (auto-format, lint on save) |
.claude-plugin/ → hooks |
Event-Driven |
| Commands |
.claude-plugin/ → commands |
Persistent |
สรุป: การ install ครั้งเดียว — ได้ทั้ง skills, subagents, hooks, commands — ครบทุก layer
ตรวจสอบว่าได้อะไรมาบ้าง
# 1. ดู skills ทั้งหมดที่มี (รวมที่ติดตั้งจาก plugin)
ls .claude/skills/
ls ~/.claude/skills/
# 2. ดู plugin ที่ติดตั้ง
claude plugin list
# หรือ
ls ~/.claude/plugins/
# 3. ใน Claude Code — ลองเรียก
/skill-name # เรียกใช้ skill โดยตรง
# 4. ดูว่า subagent ใหม่มีอะไรบ้าง
ls .claude/agents/
ls ~/.claude/agents/
# 5. ดู hooks ที่เพิ่มมา
cat .claude/settings.json | grep -A 20 hooks
ติดตั้งแล้วอยู่ตรงไหน?
mattpocock/skills (GitHub repo)
│
▼ npx skills@latest add
│
~/.claude/plugins/<name>/
│
├── skills/ → ปรากฏเป็น /skill-name
├── agents/ → ปรากฏเป็น subagent
├── hooks/ → ปรากฏใน settings hooks
└── commands/ → ปรากฏเป็น /command
ระวังอะไรบ้าง
-
Plugin อาจ override settings ของคุณ — ตรวจสอบว่ามันแก้
settings.jsonหรือไม่ - ดู source ก่อน install — plugin มีสิทธิ์รัน shell commands ผ่าน hooks
- ลองใน project test ก่อน — อย่าเพิ่งลงใน project production
-
อัปเดตเรื่อย ๆ —
@latestดึงเวอร์ชันล่าสุด
สรุป — เลือกใช้ Layer ให้ถูก
| อยากทำ... | ใช้... | เพราะ... |
|---|---|---|
| บอก Claude ว่า project ใช้ Go | ./CLAUDE.md |
โหลดทุก session |
| เพิ่มกฎเฉพาะ API | .claude/rules/api.md |
โหลดเมื่อแตะ API |
| ตรวจสอบก่อน push | Hook PreToolUse
|
ทำงานอัตโนมัติ |
| สร้าง migration file |
/migration skill |
เรียกเมื่อต้องการ |
| ให้ Claude จำ pattern | Auto Memory | Claude เขียนเอง |
บล็อก rm -rf
|
settings.json |
deny rule ถาวร |
| ใช้ model ถูกเพื่องาน review | Subagent + model: field |
แยก context |
📚 อ่านต่อ:
📅 เขียนเมื่อ: กรกฎาคม 2026 | Claude Code v1.x
⚠️ ข้อมูลอ้างอิงจากเอกสารทางการของ Anthropic — features อาจมีการเปลี่ยนแปลง
Top comments (0)