Slash Commands ขั้นสูง — ใส่ frontmatter ให้ทรงพลัง
ผมเอา command พื้นฐานมาเสริมด้วย frontmatter — บังคับ model, จำกัด tools, รับ argument — ทำงานได้ปลอดภัยและเร็วกว่าเดิม
ในระดับปริญญาตรี ผมสร้าง custom slash command พื้นฐานไว้แล้ว — แค่ไฟล์ .md ที่ใส่ prompt
ในบทนี้ผมจะแสดงให้เห็นว่ากล่องเดียวกันทำได้มากกว่านั้นอีกเยอะ ถ้าใส่ frontmatter เป็น
ผลคือ command ของผมตอนนี้
- ใช้ model haiku สำหรับงานง่ายๆ ประหยัดได้ครึ่งหนึ่งของค่าใช้จ่าย
- จำกัดสิทธิ์ไม่ให้แก้ไฟล์สำคัญผ่าน command นั้น
- รับ argument มาใช้ในเทมเพลต
โครงเต็มของ Slash Command
ไฟล์ .claude/commands/weekly-report.md
---
description: สรุปงานสัปดาห์จากไฟล์ CSV
argument-hint: "[ไฟล์ CSV ยอดงาน]"
allowed-tools: ["Read", "Write", "Bash(ls:*)"]
model: haiku
---
อ่านไฟล์ $ARGUMENTS (CSV ยอดงานรายวัน)
วิเคราะห์และสร้างรายงาน:
1. ยอดรวมสัปดาห์นี้เทียบสัปดาห์ก่อน
2. Top 5 โครงการ
3. Top 3 ลูกค้า
4. 3 actionable insight
Save เป็น reports/weekly-$(date +%Y-%W).md
Format: Markdown ภาษาไทย
Frontmatter ทั้งหมดที่ใช้ได้
| Field | ใช้ทำ | ตัวอย่าง |
|---|---|---|
description | คำอธิบายสั้น | "สรุปยอดงาน" |
argument-hint | บอกว่าใส่อะไรหลัง / | "[file.csv]" |
allowed-tools | จำกัด tool ที่ใช้ได้ | ["Read", "Bash(git:*)"] |
disallowed-tools | ห้ามใช้ tool | ["Bash(rm:*)"] |
model | บังคับใช้ model | haiku / sonnet / opus |
$ARGUMENTS
ทุกอย่างที่ user พิมพ์หลังชื่อ command อยู่ใน $ARGUMENTS
ผู้ใช้พิมพ์: /weekly-report sales-2026-04.csv
$ARGUMENTS = "sales-2026-04.csv"
ใช้แทรกในเทมเพลตได้เลย
ตัวอย่าง command ขั้นสูง
1) บังคับ model ถูกๆ สำหรับงาน bulk
---
description: แปลข้อความเป็น caption IG 5 ภาษา
argument-hint: "[ข้อความไทย]"
model: haiku
---
แปล $ARGUMENTS เป็น caption IG สั้นๆ 5 ภาษา
- ไทย (เดิม)
- English
- 中文
- 日本語
- 한국어
รูปแบบ emoji + text + hashtag
ผมใช้ haiku กับงานนี้ ราคาประมาณ $0.005/req แทน sonnet $0.03/req — ถูกลง 6 เท่า
2) จำกัด tool — งาน audit security
---
description: ตรวจ security ของโปรเจค
allowed-tools: ["Read(*)", "Bash(npm audit:*)", "Bash(git log:*)"]
disallowed-tools: ["Write", "Edit"]
---
ทำ security audit
1. npm audit
2. ดู .env ถ้ามี ว่าปลอดภัยไหม
3. ดู git log ว่ามี secret leak ไหม
4. สรุปเป็น report
ห้ามแก้ไฟล์ใดๆ — รายงานอย่างเดียว
ปลอดภัย — Claude audit ได้แต่แก้ไฟล์ไม่ได้
3) Workflow เป็นขั้น
---
description: Deploy pipeline ครบ
allowed-tools: ["Bash(npm run:*)", "Bash(git push:*)", "Bash(gh pr:*)"]
model: sonnet
---
Deploy pipeline ครบ
Step 1: npm run typecheck — ต้องผ่าน
Step 2: npm run test — ผ่าน + coverage > 80%
Step 3: npm run build — ผ่าน
Step 4: Commit ทั้งหมด ถ้ามี changes
Step 5: Push
Step 6: Create PR ผ่าน gh
Step 7: แสดง URL ของ PR
ถ้า step ไหนล้ม หยุดและแจ้ง
4) Customer service พร้อม self-review
---
description: ร่างตอบลูกค้าและตรวจโทนให้
argument-hint: "[สถานการณ์ของลูกค้า]"
model: sonnet
---
สถานการณ์ — $ARGUMENTS
ร่างตอบลูกค้า 3 แบบ
1. friendly
2. professional
3. empathetic
แต่ละแบบ
- ไม่เกิน 3 ประโยค
- ไม่ใช้ภาษาทางการเกิน
- ปิดด้วยการเชิญถามต่อ
- ห้ามสัญญาเกินจริง
หลังร่างเสร็จ self-review
- มีคำที่อาจทำให้ลูกค้าไม่พอใจไหม
- ถ้ามี highlight และเสนอแก้
จัดเป็น folder
ผมแยก command เป็นหมวดเพื่อหาใช้ง่าย
.claude/commands/
customer-service/
reply.md
complaint.md
refund.md
reports/
weekly.md
monthly.md
customer-segment.md
git/
smart-commit.md
create-pr.md
เรียก /customer-service/reply หรือ /reports/weekly ได้เลย
Global vs Project
~/.claude/commands/ใช้ได้ทุกโปรเจค ผมเก็บอันที่ใช้ทั่วไป (translate, summarize)[project]/.claude/commands/เฉพาะโปรเจคนั้น เก็บที่เฉพาะของบริษัท
เคล็ด — Command เรียก Command อื่นได้
.claude/commands/morning-routine.md
---
description: ทำงานต้นวันให้ครบทุกอย่าง
---
ทำตามลำดับ
1. /weekly-report
2. /inventory-check
3. /customer-pending
แล้วสรุปรวม 3 อันเป็น 1 bullet list
ผมพิมพ์ /morning-routine ตอนเช้า ได้ dashboard ครบในคำสั่งเดียว
ลองทำดู: ภารกิจ: Refactor command ของคุณ
บทนี้มีประโยชน์กับคุณมั้ยครับ?
ผมอ่าน feedback เองทุกอันแล้วเอาไปปรับเนื้อหา