20%

3.2 Custom Slash Commands and Skills

Custom Slash Commands คืออะไร

Custom Slash Commands คือ shortcut ที่เราสร้างเอง — พิมพ์ /mycommand แล้ว Claude จะรับ instructions จากไฟล์ที่กำหนด ช่วยให้ไม่ต้องพิมพ์ prompt ยาวๆ ซ้ำทุกครั้ง เหมาะสำหรับ workflows ที่ทำประจำ

Creating Slash Commands

สร้างไฟล์ใน .claude/commands/:

.claude/commands/
├── review.md        → /review
├── test.md          → /test
├── deploy.md        → /deploy
└── fix-lint.md      → /fix-lint

ตัวอย่าง: /review command

<!-- .claude/commands/review.md -->
Review the current git diff for:
1. Bugs or logic errors
2. Security vulnerabilities
3. Performance issues
4. Code style violations

For each issue found, explain the problem and suggest a fix.
Focus on the diff only — don't review unchanged code.

Parameterized Commands

ใช้ $ARGUMENTS เพื่อรับ parameter:

<!-- .claude/commands/explain.md -->
Explain the following code/concept in Thai, suitable for a junior developer:

$ARGUMENTS

Usage: /explain React useEffect cleanup function

Skills

Skills เป็น advanced version ของ commands — มี frontmatter สำหรับ metadata:

---
name: deploy
description: Deploy current branch to staging
---

1. Run `pnpm build` to verify build passes
2. Run `pnpm test` to verify tests pass
3. If both pass, run `./scripts/deploy-staging.sh`
4. Report the deployment URL

Skill Composition

Skills สามารถเรียก skills อื่นได้:

<!-- .claude/commands/ship.md -->
Execute these steps in order:
1. Run /review on the current changes
2. Run /test
3. If both pass, run /deploy
4. Create a PR with the changes

Key Concepts

  • Location.claude/commands/ ใน project root
  • Naming — ชื่อไฟล์ = ชื่อ command (ลบ .md)
  • $ARGUMENTS — placeholder สำหรับ user input หลัง command name
  • Skill tool — Claude เรียก Skill tool เพื่อ invoke skill programmatically

Exam Tips

  • Slash commands อยู่ใน .claude/commands/*.md
  • $ARGUMENTS คือ placeholder สำหรับ parameters ที่ user พิมพ์ต่อท้าย
  • Commands เป็น project-specific (อยู่ใน repo) — แชร์กับ team ได้
  • Skills มี frontmatter (name, description) — commands ไม่มี
  • ข้อสอบอาจถามว่า command file ต้องอยู่ที่ไหนและ format เป็นอย่างไร