Tag: SKILL.md

  • Claude Code Skill คืออะไร? วิธีสร้างและใช้งาน Skill อย่างมีประสิทธิภาพ

    Claude Code Skill คืออะไร? วิธีสร้างและใช้งาน Skill อย่างมีประสิทธิภาพ

    Claude Code เป็น AI coding assistant ที่ทำงานกับไฟล์บนเครื่องของเราได้โดยตรง ช่วยลดเวลาในการเปลี่ยนหน้าจอในการทำงาน และทุ่นแรงในการเขียนและรีวิว code ได้

    จุดเด่นหนึ่งของ Claude คือ skill ซึ่งช่วยให้ Claude ปรับตัวและทำงานที่มีความซับซ้อนและหลากหลายได้

    ในบทความนี้ ผมจะพาทุกคนไปรู้จักกับ skill ตั้งแต่ skill คืออะไร ใช้ยังไง ไปจนถึงเคล็ดลับในการใช้ skill อย่างมีประสิทธิภาพ

    ถ้าพร้อมแล้ว ไปเริ่มกันเลย



    🤨 Skill ใน Claude Code คืออะไร? ใช้เพื่ออะไร?

    Skill เป็นไฟล์ markdown ที่เก็บคำชี้แจง script และข้อมูลต่าง ๆ ที่ Claude เรียกใช้ได้เมื่อจำเป็น

    Skill ใช้แก้ปัญหา 2 อย่าง:

    1. ลดการพูดซ้ำ
    2. ใช้ทำงานย่อย ๆ หรืองานเฉพาะกิจ

    งานย่อย ๆ หรือสิ่งที่เรามักต้องพูดซ้ำกับ Claude (เช่น รีวิว code ยังไง, แก้ bug ยังไง, deploy บน production ยังไง) ให้เราสร้างเป็น skill เพื่อให้ Claude รู้ว่าต้องทำอะไรโดยที่เราไม่ต้องสั่งอีก


    🕰️ Skill จะใช้เมื่อไร?

    Claude จะเรียกใช้งาน skill โดยอัตโนมัติเมื่อ skill มีความเกี่ยวข้องกับงานตรงหน้า หรือเมื่อเราเรียกใช้งานเอง

    ตัวอย่างการเรียกใช้งานแบบอัตโนมัติ:

    รีวิว code ใน app.py ให้หน่อย

    ถ้า Claude มี skill สำหรับรีวิว code (เช่น code-review) Claude จะเรียกใช้งาน skill นี้โดยที่เราไม่ต้องบอกแต่แรก

    ตัวอย่างการเรียกใช้งานเอง:

    ใช้ /code-review รีวิว code ใน app.py ให้หน่อย

    ในกรณีนี้ Claude จะค้นหา skill ชื่อ code-review และเอามาใช้รีวิว code ตามคำสั่ง


    📎 สร้าง Skill ยังไง?

    เราสร้าง skill ได้ 3 วิธี:

    1. สั่งให้ Claude สร้างให้ (แนะนำ)
    2. เขียนเอง
    3. โหลด skill ที่มีคนสร้างไว้แล้ว

    ตัวอย่างการสั่งให้ Claude สร้างให้:

    สร้าง skill สำหรับรีวิว code ให้หน่อย

    📑 Skill หน้าตาเป็นยังไง?

    Skill จะถูกเก็บไว้ใน SKILL.md ซึ่งประกอบไปด้วย 5 ส่วน:

    1. name
    2. description
    3. allowed-tools (optional)
    4. model (optional)
    5. Instruction

    ตัวอย่าง SKILL.md:

    ---
    name: code-review
    description: Reviews code changes for bugs, style issues, and best practices. Use when the user asks for a code review, wants feedback on a diff or pull request, or asks "does this look right?" about recent changes.
    allowed-tools: Read, Grep, Glob, Bash(git diff:*)
    model: sonnet
    ---
    # Code Review
    Review the code changes in the current diff or specified files.
    ## Steps
    1. Run `git diff` (or read the specified files) to see what changed
    2. Check for:
    - Logic errors or edge cases the code doesn't handle
    - Inconsistent style with the rest of the codebase
    - Missing error handling
    - Unclear naming or missing comments where logic is non-obvious
    - Potential security issues (unsanitized input, hardcoded secrets)
    3. Skip nitpicks on formatting if a linter/formatter is already configured
    ## Output Format
    - Group feedback by file
    - Mark each issue as **Blocking**, **Suggestion**, or **Nit**
    - Keep comments specific — point to the line and explain *why*, not just *what*
    - End with a one-line summary verdict (e.g. "Ready to merge" / "Needs changes")

    .

    👉 ส่วนที่ 1. name

    ตัวอย่าง:

    name: code-review

    ใช้ระบุ skill และควรตั้งให้มีความเจาะจงเพื่อไม่ให้ซ้ำกัน เช่น:

    • code-review-for-security
    • code-review-for-rendering
    • code-review-for-general-functions

    .

    👉 ส่วนที่ 2. description

    ตัวอย่าง:

    description: Reviews code changes for bugs, style issues, and best practices. Use when the user asks for a code review, wants feedback on a diff or pull request, or asks "does this look right?" about recent changes.

    ใช้บอก Claude 2 อย่าง:

    1. What: skill นี้ทำอะไร
    2. When: เมื่อไรถึงจะเรียกใช้ skill นี้

    อย่างในตัวอย่างบอก Claude ว่า:

    1. What: ใช้รีวิว code เพื่อหา bug และแนะนำวิธีแก้
    2. When: ใช้เมื่อ user ต้องการรีวิว code หรือถามเกี่ยวกับ code

    .

    👉 ส่วนที่ 3. allowed-tools

    ตัวอย่าง:

    allowed-tools: Read, Grep, Glob, Bash(git diff:*)

    ใช้ระบุ action ที่ skill นี้ทำได้

    อย่างในตัวอย่าง เราเลือก:

    • Read: อ่านไฟล์
    • Grep: ค้นหาเนื้อหาในไฟล์
    • Glob: ค้นหาไฟล์
    • Bash: รัน shell command

    Note:

    • ดูตัวเลือก action ทั้งหมดได้ที่ Tools reference
    • เราสามารถเลือกไม่ระบุได้ โดย Claude จะเลือกใช้ค่า default ของระบบ

    .

    👉 ส่วนที่ 4. model

    ตัวอย่าง:

    model: sonnet

    ระบุ model ที่จะใช้งาน ซึ่งมี 3 ตัวเลือก:

    1. Haiku: เหมาะกับงานที่เน้นความเร็ว
    2. Opus: เหมาะกับงานที่เน้นการคิดวิเคราะห์
    3. Sonnet: งานที่เน้นความสมดุลระหว่างความเร็วและการวิเคราะห์

    เราเลือกที่จะไม่กำหนด model ได้ โดยในกรณีนั้น Claude จะใช้ model ที่ใช้งานอยู่ใน session นั้น ๆ

    .

    👉 ส่วนที่ 5. Instruction

    ตัวอย่าง:

    # Code Review
    Review the code changes in the current diff or specified files.
    ## Steps
    1. Run `git diff` (or read the specified files) to see what changed
    2. Check for:
    - Logic errors or edge cases the code doesn't handle
    - Inconsistent style with the rest of the codebase
    - Missing error handling
    - Unclear naming or missing comments where logic is non-obvious
    - Potential security issues (unsanitized input, hardcoded secrets)
    3. Skip nitpicks on formatting if a linter/formatter is already configured
    ## Output Format
    - Group feedback by file
    - Mark each issue as **Blocking**, **Suggestion**, or **Nit**
    - Keep comments specific — point to the line and explain *why*, not just *what*
    - End with a one-line summary verdict (e.g. "Ready to merge" / "Needs changes")

    เป็นคำชี้แจงในการทำงานให้กับ Claude

    อย่างในตัวอย่าง เราระบุ:

    1. ขั้นตอนการรีวิว code
    2. สิ่งที่จะต้องส่งกลับมา

    ✌️ ระดับและการจัดลำดับ Skill

    Skill แบ่งได้เป็น 4 ระดับ:

    1. Enterprise: skill ที่ใช้ร่วมกันทั้งองค์กร (เก็บอยู่ใน managed-settings.json)
    2. Personal: skill ที่ใช้ร่วมกันทุก project ที่เราทำงาน (เก็บอยู่ใน ~/.claude/skills)
    3. Project: skill ที่ใช้เฉพาะ project (เก็บอยู่ใน <project_folder>/.claude/skills)
    4. Plugin: skill ที่มาพร้อม plugin (เก็บอยู่ใน <project_folder>/.claude-plugins/skills)

    ในกรณีที่ skill มีชื่อซ้ำกันหรือทำงานเหมือนกัน Claude จะเลือกใช้ skill ตามลำดับนี้:

    Enterprise > Personal > Project > Plugin

    ตัวอย่าง:

    เรามี skill ชื่อ code-review ใน root directory (ระดับ Personal) ซึ่งซ้ำกับ code-review ใน managed-settings.json (ระดับ Enterprise) Claude จะเลือกใช้ code-review ใน managed-settings.json ก่อน


    🤫 เคล็ดลับการใช้ Skill

    .

    1️⃣ ข้อที่ 1. เขียน name และ description ให้ดี

    Claude เลือกใช้ skill โดยอ่านจาก name และ description

    ถ้าทั้ง name และ description ไม่สื่อความหมายที่เกี่ยวข้องกับงานตรงหน้า Claude จะไม่เรียกมาใช้งาน แม้ว่าเราต้องการให้ใช้ก็ตาม

    วิธีแก้ คือ เขียน name และ description ให้ดี:

    1. name ควรมีความเฉพาะเจาะจง ไม่ธรรมดาจนเกินไป
    2. description ควรบอกว่า skill ทำอะไร และควรใช้เมื่อไร

    .

    2️⃣ ข้อที่ 2. เขียน Instruction ให้กระชับ

    เมื่อ Claude เลือกใช้ skill ก็จะโหลด instruction ใน SKILL.md เข้ามาอ่าน ซึ่งจะทำให้ Claude มี context หรือความจำในการทำงานน้อยลง

    ดังนั้น เราควรเขียน instruction กระชับเพื่อประหยัดการใช้ context ของ Claude โดย SKILL.md ไม่ควรยาวเกิน 500 บรรทัด

    ในกรณีที่ instruction ยาว เราสามารถตัดแบ่งบางส่วนไปใส่ในไฟล์อื่น และเขียนอ้างอิงไว้ใน SKILL.md แทนได้

    ตัวอย่าง:

    ---
    name: api-integration
    description: Build and debug integrations with our internal API. Use when the user asks to add an endpoint, authenticate a request, or troubleshoot API errors.
    ---
    # API Integration
    This skill covers our internal API conventions. Keep this file as your starting point — don't guess at details covered in the linked files below; open them when the task needs that level of detail.
    ## Quick Reference
    - Base URL: `https://api.internal.example.com/v1`
    - Auth: Bearer token in `Authorization` header
    - All responses are JSON with a `data` and `error` envelope
    ## When You Need More Detail
    - **Authentication flows** (OAuth, token refresh, service accounts) → see [auth.md](auth.md)
    - **Full endpoint list and request/response schemas** → see [endpoints.md](endpoints.md)
    - **Error codes and retry behavior** → see [errors.md](errors.md)
    - **Example requests in curl, Python, and JS** → see [examples.md](examples.md)
    Only read the file(s) relevant to the current task. Don't load all of them upfront.

    เมื่อทำอย่างนี้ Claude จะโหลดข้อมูลจากไฟล์ที่เราอ้างอิงใน SKILL.md เมื่อจำเป็นเท่านั้น ทำให้เราประหยัดพื้นที่ใน context ไปได้

    .

    3️⃣ ข้อที่ 3. ใช้ Skill ใน Subagent

    Subagent เป็น agent ที่ Claude เรียกใช้งานเพื่อทำงานเฉพาะทางบางอย่างได้

    Subagent จะไม่สามารถใช้ skill ได้เองจนกว่าเราจะบอกว่าใช้ได้ โดยกำหนด skill ใน skills ในไฟล์ markdown ของ subagent

    ตัวอย่าง:

    ---
    name: api-developer
    description: Implement API endpoints following team conventions
    tools: Read, Write, Edit, Grep, Glob, Bash
    skills:
    - api-conventions
    - error-handling-patterns
    ---
    You are an API developer. Implement endpoints following the conventions
    and patterns from the preloaded skills above.

    เมื่อกำหนดแล้ว subagent จะเรียกใช้งาน skill ทุกครั้งที่ตัวเองถูกใช้งาน ซึ่งต่างจาก main agent ที่เลือกใช้ skill ได้ตามหน้างาน


    🫵 Your Turn

    หลังอ่านบทความนี้แล้ว ลองใช้มา Claude Code กันดูนะครับ:


    📃 References