เจาะลึก Claude Code (ตอนจบ)

เจาะลึก Claude Code (ตอนจบ)

บทความนี้เจาะลึกการใช้งาน Claude Code โดยแนะนำทริคการใช้งานขั้นสูง พร้อมสรุป Command List แบบครบถ้วน

สวัสดีครับ

สวัสดีครับ ผมชื่อ Nakamura(nokomoro3) จากทีม Data Business Headquarters – Machine Learning

ในครั้งนี้จะมาเจาะลึก Claude Code กันครับ

เกี่ยวกับบทความนี้

เดิมทีผมใช้ Cursor อยู่แล้ว ก็เลยยังครึ่งๆ กลางๆ อยู่ว่า Claude Code จำเป็นจริงหรือเปล่า แต่พอลองใช้ดูรู้สึกว่า behavior ของ agent ค่อนข้างเป็นไปตามที่คาดหวังทีเดียวครับ จริงๆ แล้วใน Cursor ผมใช้หลักๆ แค่ code completion กับ Cmd + K เป็นหลัก ส่วนการทำงานเชิง agent แบบนี้ผมเริ่มแยกมาใช้ Claude Code แทนในช่วงหลังๆ นี้

เนื่องจากประสบการณ์การใช้งานเป็นเรื่องที่ค่อนข้างขึ้นอยู่กับมุมมองส่วนบุคคล ทำให้สื่อสารผ่านตัวอักษรได้ยาก แต่เพื่อให้ทุกคนได้รู้จัก Claude Code มากขึ้นและมีคนลองใช้งานให้มากที่สุด ผมจึงได้เขียนบทความนี้ขึ้นมาเพื่ออธิบายวิธีการใช้งานแบบครบถ้วนครับ

ด้านล่างนี้คือเนื้อหาที่ได้เขียนไว้ ซึ่งมีเนื้อหาค่อนข้างหลากหลาย

  • อธิบายวิธีการตั้งค่า Claude Code พื้นฐาน
  • อธิบายวิธีการใช้งานตั้งแต่พื้นฐานไปจนถึงการประยุกต์ใช้ (เช่น Permission, GitHub Integration เป็นต้น)
  • อธิบาย Command List แบบครบถ้วน

สำหรับเวอร์ชัน Bedrock มีบทความที่อธิบายไว้แล้ว จึงไม่ได้ทำการทดลองในครั้งนี้ ให้ดูที่ลิงก์บทความด้านล่างนี้แทน
https://dev.classmethod.jp/articles/claude-code-aws-bedrock-ec2-vscode-remote-ssh-th/

  • ไม่ทำการอธิบาย Bedrock version

ทั้งนี้เนื่องจากบทความมีจำนวนค่อนข้างมาก จึงได้แบ่งออกเป็น 2 ตอน โดยสามารถดูเนื้อหาตอนแรกได้ที่ลิงก์นี้
https://dev.classmethod.jp/articles/get-started-claude-code-1-th/

วิธีการใช้งาน (ขั้นสูง)

การเพิ่ม MCP Server

วิธีการเพิ่ม MCP Server มีอธิบายไว้ในลิงก์ด้านล่างนี้

Slash command /mcp ใช้สำหรับตรวจสอบสถานะการเชื่อมต่อของ MCP Server เท่านั้น ดังนั้นการเพิ่ม MCP Server จำเป็นต้องเพิ่มด้วย CLI command ที่ชื่อว่า claude mcp

ต่อไปจะลองเพิ่ม MCP Server ของ AWS Document

claude mcp add my-server \
    --scope project \
    -e FASTMCP_LOG_LEVEL=ERROR \
    -e AWS_DOCUMENTATION_PARTITION=aws \
    -- uvx awslabs.aws-documentation-mcp-server@latest
# Added stdio MCP server my-server with command: uvx awslabs.aws-documentation-mcp-server@latest to project config

claude mcp list
# my-server: uvx awslabs.aws-documentation-mcp-server@latest

จากนั้นการตั้งค่า MCP Server จะถูกเขียนลงในไฟล์ชื่อ ./.mcp.json เหมือนตัวอย่างด้านล่างนี้

./.mcp.json
{
  "mcpServers": {
    "my-server": {
      "type": "stdio",
      "command": "uvx",
      "args": [
        "awslabs.aws-documentation-mcp-server@latest"
      ],
      "env": {
        "FASTMCP_LOG_LEVEL": "ERROR",
        "AWS_DOCUMENTATION_PARTITION": "aws"
      }
    }
  }
}

เมื่อเริ่มต้น Claude Code ในสถานะนี้ ระบบจะถามว่าต้องการโหลดการตั้งค่า MCP Server หรือไม่ เหมือนตัวอย่างด้านล่างนี้

╭──────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                              │
│ New MCP server found in .mcp.json: my-server                                                 │
│                                                                                              │
│ MCP servers may execute code or access system resources. All tool calls require approval.    │
│ Learn more in the MCP documentation (​https://docs.anthropic.com/s/claude-code-mcp​).        │
│                                                                                              │
│ ❯ 1. Use this and all future MCP servers in this project                                     │
│   2. Use this MCP server                                                                     │
│   3. Continue without using this MCP server                                                  │
│                                                                                              │
╰──────────────────────────────────────────────────────────────────────────────────────────────╯
   Enter to confirm · Esc to reject

หลังจากเลือกให้ใช้งานแล้ว สามารถตรวจสอบสถานะการเชื่อมต่อได้ด้วยคำสั่ง /mcp

> /mcp

╭──────────────────────────────────────────────────────────────────────────────────────────────╮
│ Manage MCP servers                                                                           │
│                                                                                              │
│ ❯ 1. my-server  ✔ connected · Enter to view details                                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────╯

เมื่อเลือกแล้ว จะสามารถตรวจสอบรายละเอียดของ MCP Server เพิ่มเติมได้

╭──────────────────────────────────────────────────────────────────────────────────────────────╮
│ My-server MCP Server                                                                         │
│                                                                                              │
│ Status: ✔ connected                                                                          │
│ Command: uvx                                                                                 │
│ Args: awslabs.aws-documentation-mcp-server@latest                                            │
│ Capabilities: tools                                                                          │
│ Tools: 3 tools                                                                               │
│                                                                                              │
│ ❯ 1. View tools                                                                              │
╰──────────────────────────────────────────────────────────────────────────────────────────────╯

สามารถตรวจสอบรายการ Tools ที่ MCP Server มีอยู่ได้เช่นกัน

╭──────────────────────────────────────────────────────────────────────────────────────────────╮
│ Tools for my-server (3 tools)                                                                │
│                                                                                              │
│ ❯ 1. read_documentation                                                                      │
│   2. search_documentation                                                                    │
│   3. recommend                                                                               │
╰──────────────────────────────────────────────────────────────────────────────────────────────╯

ลองสอบถามเกี่ยวกับ AWS update ล่าสุดกันดู
(ระหว่างการทำงาน ระบบจะขออนุญาตใช้ Tools ของ MCP Server จาก User แล้วให้กด Accept)

> SageMaker Unified Studio ในการอัปเดตล่าสุด ได้รองรับการอัปเกรดจาก DataZone ไปยัง SageMaker Domain แล้วหรือยัง?

● my-server:search_documentation (MCP)(search_phrase: "SageMaker Unified Studio DataZone
                                      upgrade domain")
  ⎿ {
      "rank_order": 1,
      "url": "https://docs.aws.amazon.com/sagemaker-unified-studio/latest/adminguide/upgrad
    e-domain.html",
      "title": "Upgrade Amazon DataZone domains to Amazon SageMaker unified domains -
    Amazon SageMaker Unified Studio",
      "context": "Before upgrading your Amazon DataZone domain to an Amazon SageMaker
    unified domain, review these important considerations to ensure a smooth upgrade
    process. The upgrade process is available only through the AWS management console.
    Currently, no API support is offered for upgrading your domain. You can initialize the
    upgrade process from the domain details page of your Amazon DataZone domain."
    }
  ⎿ {
      "rank_order": 2,
      "url": "https://docs.aws.amazon.com/datazone/latest/userguide/upgrade-domain.html",
      "title": "Upgrade Amazon DataZone domains to Amazon SageMaker unified domains -
    Amazon DataZone",
      "context": "Before upgrading your Amazon DataZone domain to an Amazon SageMaker
    unified domain, review these important considerations to ensure a smooth upgrade
    process. The upgrade process is available only through the AWS management console.
    Currently, no API support is offered for upgrading your domain. You can initialize the
    upgrade process from the domain details page of your Amazon DataZone domain."
    }
  ⎿ {
      "rank_order": 3,
      "url": "https://docs.aws.amazon.com/sagemaker-unified-studio/latest/adminguide/create
    -domain-datazone.html",
      "title": "Create an Amazon DataZone domain - Amazon SageMaker Unified Studio",
      "context": "Complete the following procedure to create a Amazon SageMaker Unified
    Studio domain with the quick setup option."
    }
  ⎿ {
      "rank_order": 4,
      "url": "https://docs.aws.amazon.com/sagemaker-unified-studio/latest/adminguide/workin
    g-with-domains.html",
      "title": "Domains in Amazon SageMaker Unified Studio - Amazon SageMaker Unified
    Studio",
      "context": "Learn about working with domains in Amazon SageMaker Unified Studio."
    }
  ⎿ {
      "rank_order": 5,
      "url": "https://docs.aws.amazon.com/sagemaker-unified-studio/latest/adminguide/create
    -domain-sagemaker-unified-studio-manual.html",
      "title": "Create a Amazon SageMaker Unified Studio domain - manual setup - Amazon
    SageMaker Unified Studio",
      "context": "Complete the following procedure to create a Amazon SageMaker Unified
    Studio domain with the quick setup option."
    }
  ⎿ {
      "rank_order": 6,
      "url": "https://docs.aws.amazon.com/sagemaker-unified-studio/latest/adminguide/domain
    -units.html",
      "title": "Domain units and authorization policies in Amazon SageMaker Unified Studio
    - Amazon SageMaker Unified Studio",
      "context": "Working with domain units and authorization policies in Amazon SageMaker
    Unified Studio"
    }
  ⎿  {
       "rank_order": 7,
       "url":
     "https://docs.aws.amazon.com/sagemaker-unified-studio/latest/userguide/domain.html",
       "title": "Domain - Amazon SageMaker Unified Studio",
       "context": "Domain can be initialized using the following command."
     }
  ⎿ {
      "rank_order": 8,
      "url": "https://docs.aws.amazon.com/sagemaker-unified-studio/latest/adminguide/delete
    -domain.html",
      "title": "Delete domains - Amazon SageMaker Unified Studio",
      "context": "When deleting a domain, note that the act of deleting a domain is final.
    Another important note to remember is that not all items created by Amazon SageMaker
    Unified Studio are deleted. The following items can only be deleted in their service
    consoles:"
    }
  ⎿ {
      "rank_order": 9,
      "url": "https://docs.aws.amazon.com/sagemaker/latest/dg/studio-notebooks-and-internet
    -access.html",
      "title": "Connect Studio notebooks in a VPC to external resources - Amazon SageMaker
    AI",
      "context": "The following topic gives information about how to connect Studio
    Notebooks in a VPC to external resources."
    }
  ⎿ {
      "rank_order": 10,
      "url": "https://docs.aws.amazon.com/sagemaker-unified-studio/latest/adminguide/associ
    ated-accounts.html",
      "title": "Associated accounts in Amazon SageMaker Unified Studio - Amazon SageMaker
    Unified Studio",
      "context": "Learn about associated accounts in Amazon SageMaker Unified Studio."
    }

● my-server:read_documentation (MCP)(url: "https://docs.aws.amazon.com/sagemaker-unified-st
                                    udio/latest/adminguide/upgrade-domain.html")
  ⎿ AWS Documentation from https://docs.aws.amazon.com/sagemaker-unified-studio/latest/admi
    nguide/upgrade-domain.html:

    # Upgrade Amazon DataZone domains to Amazon SageMaker unified domains

    … +67 lines (ctrl+r to expand)

● ใช่แล้ว SageMaker Unified Studio ในการอัปเดตล่าสุด ได้รองรับการอัปเกรดจาก DataZone ไปยัง SageMaker Domain แล้ว

  คุณลักษณะของฟังก์ชันการอัปเกรด:
  - สามารถทำงานได้จาก AWS Console (ยังไม่รองรับ API)
  - การตั้งค่าและโปรเจกต์ที่มีอยู่สามารถถูกสืบทอดต่อได้
  - สามารถใช้งานได้ทั้ง DataZone Portal และ Unified Studio
  - เวอร์ชันของ Domain เปลี่ยนจาก V1 เป็น V2

จะพบว่า MCP Server สามารถใช้งานได้อย่างถูกต้อง

claude mcp ยังมีคำสั่งอื่นๆ เตรียมไว้ให้ด้วย โปรดตรวจสอบและนำไปใช้งานได้ตามต้องการ

claude mcp --help

# Usage: claude mcp [options] [command]
# 
# Configure and manage MCP servers
# 
# Options:
#   -h, --help                                     Display help for command
# 
# Commands:
#   serve [options]                                Start the Claude Code MCP server
#   add [options] <name> <commandOrUrl> [args...]  Add a server
#   remove [options] <name>                        Remove an MCP server
#   list                                           List configured MCP servers
#   get <name>                                     Get details about an MCP server
#   add-json [options] <name> <json>               Add an MCP server (stdio or SSE) with a JSON
#                                                  string
#   add-from-claude-desktop [options]              Import MCP servers from Claude Desktop (Mac
#                                                  and WSL only)
#   reset-project-choices                          Reset all approved and rejected project-scoped
#                                                  (.mcp.json) servers within this project
#   help [command]                                 display help for command

อย่างเช่นคำสั่ง claude mcp add-json สามารถโหลดจากไฟล์การตั้งค่า MCP ที่มีอยู่แล้วได้ด้วย ค่อนข้างสะดวกเลยทีเดียว

เกี่ยวกับ Permission

ใน Permission สามารถกำหนดสิทธิ์ที่กว้างขึ้นให้กับ Claude Code ได้ เช่น การอนุญาตให้รันคำสั่ง

รายละเอียดเกี่ยวกับ Permission มีอธิบายไว้ในลิงก์ด้านล่างนี้

โดยหลักๆ แล้วจะมี Allow rule และ Deny rule ดังนี้

  • Allow rule
    • อนุญาตให้ Claude Code ใช้ Tools ที่กำหนดไว้ได้ โดยไม่ต้องผ่านการอนุมัติจาก User ทุกครั้ง
  • Deny rule
    • ไม่อนุญาตให้ Claude Code ใช้ Tools ที่กำหนดไว้ โดยที่กฎ Deny จะมีความสำคัญมากกว่า Allow

กฎเหล่านี้สามารถกำหนดให้กับ Tools ต่างๆ ได้ดังต่อไปนี้

Tool Description Permission Required
Agent Runs a sub-agent to handle complex, multi-step tasks No
Bash Executes shell commands in your environment Yes
Edit Makes targeted edits to specific files Yes
Glob Finds files based on pattern matching No
Grep Searches for patterns in file contents No
LS Lists files and directories No
MultiEdit Performs multiple edits on a single file atomically Yes
NotebookEdit Modifies Jupyter notebook cells Yes
NotebookRead Reads and displays Jupyter notebook contents No
Read Reads the contents of files No
TodoRead Reads the current session’s task list No
TodoWrite Creates and manages structured task lists No
WebFetch Fetches content from a specified URL Yes
WebSearch Performs web searches with domain filtering Yes
Write Creates or overwrites files Yes

สำหรับ Tools ที่ Permission Required เป็น "No" จะสามารถให้ Claude Code รันได้โดยไม่จำเป็นต้องตั้งค่าเพิ่มเติมใดๆ

ในทางกลับกัน สำหรับ Tools ที่ Permission Required เป็น "Yes" จะต้องมีการกำหนด Allow rule อย่างชัดเจน

ในส่วนของ Tools ด้านล่างนี้ กรณีที่ "auto-accept" เปิดใช้งาน จะถือว่าได้รับสิทธิ์ไว้แล้ว

Tool Description Permission Required
Edit Makes targeted edits to specific files Yes
MultiEdit Performs multiple edits on a single file atomically Yes
NotebookEdit Modifies Jupyter notebook cells Yes
Write Creates or overwrites files Yes

รายการเหล่านี้สามารถอนุญาตได้ด้วยการกำหนด Allow rule แบบชัดเจนเช่นกัน

ส่วน Tools ด้านล่างนี้ หากไม่มีการกำหนด Allow rule อย่างชัดเจน จะต้องได้รับการอนุมัติแบบ manual

Tool Description Permission Required
Bash Executes shell commands in your environment Yes
WebFetch Fetches content from a specified URL Yes
WebSearch Performs web searches with domain filtering Yes

Allow rule สามารถกำหนดขอบเขตสิทธิ์ได้อย่างละเอียดมากขึ้น ตัวอย่างเช่น

  • Bash(git diff:*) : อนุญาตให้ใช้ Bash command ที่ขึ้นต้นด้วย git diff
  • Edit(docs/**) : อนุญาตให้แก้ไขไฟล์ในไดเรกทอรี docs ของโปรเจกต์
  • Read(~/.zshrc) : อนุญาตให้อ่านไฟล์ ~/.zshrc
  • WebFetch(domain:example.com) : อนุญาตให้ส่ง fetch request ไปยัง example.com

สิทธิ์ของ Read และ Edit สามารถเขียนได้ตามรูปแบบที่ใช้ใน gitignore

นอกจากนี้ แม้จะไม่ได้อยู่ในรายการ แต่สิทธิ์ของ MCP ก็สามารถเขียนได้เหมือนกับตัวอย่างด้านล่างนี้เช่นกัน

  • mcp__{ชื่อของ MCP Server}
  • mcp__{ชื่อของ MCP Server}__{ชื่อของ Tool}

วิธีการตั้งค่าคือ กรณีที่ตั้งค่าแบบถาวรให้ใช้ Slash command และกรณีที่ตั้งค่าแบบชั่วคราวให้ใช้ CLI ตอนเริ่มต้น Claude Code

  • Slash command (การตั้งค่าแบบถาวร)
    • สามารถตั้งค่าได้ด้วย /permission
  • CLI command (การตั้งค่าแบบชั่วคราวที่กำหนดขณะเริ่มต้น REPL)
    • เพิ่ม Allow rule ด้วย claude --allowedTools
    • เพิ่ม Deny rule ด้วย claude --disallowedTools
    • ให้สิทธิ์ทั้งหมดด้วย claude --dangerously-skip-permissions

เราจะมาอธิบายด้วยตัวอย่างการตั้งค่าด้วย Slash command กันดู จากนั้นรัน Slash command

> /permission

จากนั้นจะแสดงหน้าจอแบบนี้

╭──────────────────────────────────────────────────────────────────────────────────────────────╮
│ Permission rules:  Allow   Deny                                                              │
│                                                                                              │
│ Claude Code won't ask before using allowed tools.                                            │
│                                                                                              │
│ ❯ 1. Add a new rule…                                                                         │
│                                                                                              │
╰──────────────────────────────────────────────────────────────────────────────────────────────╯

เลือก "Add a new rule" จากนั้นจะแสดงหน้าจอแบบด้านล่างนี้ แล้วป้อนด้วยชื่อของ Tool หรือ Wildcard ก็ได้

╭──────────────────────────────────────────────────────────────────────────────────────────────╮
│ Add allow permission rule                                                                    │
│                                                                                              │
│ Permission rules are a tool name, optionally followed by a specifier in parentheses.         │
│ e.g., WebFetch or Bash(ls:*)                                                                 │
│                                                                                              │
│ ╭──────────────────────────────────────────────────────────────────────────────────────────╮ │
│ │ WebFetch                                                                                 │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                              │
╰──────────────────────────────────────────────────────────────────────────────────────────────╯

ระบบจะถามว่าจะเพิ่มไปที่ส่วนไหน ในครั้งนี้จะเลือก "Project settings"

╭──────────────────────────────────────────────────────────────────────────────────────────────╮
│ Add allow permission rule                                                                    │
│                                                                                              │
│   WebFetch                                                                                   │
│   Any use of the WebFetch tool                                                               │
│                                                                                              │
│ Where should this rule be saved?                                                             │
│   1. Project settings (local)  Saved in .claude/settings.local.json                          │
│ ❯ 2. Project settings          Checked in at .claude/settings.json                           │
│   3. User settings             Saved in at ~/.claude/settings.json                           │
│                                                                                              │
╰──────────────────────────────────────────────────────────────────────────────────────────────╯

ออกจากหน้าจอตั้งค่าโดยกดปุ่ม "Esc" ก็เป็นอันเสร็จสิ้น

จากนั้นการตั้งค่าจะถูกเก็บไว้ในไฟล์ .claude/settings.json ตามตัวอย่างด้านล่างนี้

.claude/settings.json
{
  "permissions": {
    "allow": [
      "WebFetch"
    ],
    "deny": []
  }
}

ลดจำนวน Token ที่ใช้งาน

สามารถลดปริมาณ Token ที่ใช้ได้โดยการลด Context

การรันคำสั่งด้านล่างนี้ จะสามารถสรุปสิ่งที่ได้โต้ตอบกันมาจนถึงตอนนี้ใน session ได้

/compact

นอกจากนี้ในกรณีที่ต้องการสรุปโดยโฟกัสที่เนื้อหาเฉพาะด้าน ก็สามารถออกคำสั่งได้เช่นกัน

/compact "โฟกัสไปที่ Code Sample และวิธีใช้ API"

กรณีที่ Claude มี context เกิน 95% ระบบจะรัน /compact ตามค่าเริ่มต้น เพื่อสรุปสิ่งที่ได้โต้ตอบกันมาจนถึงตอนนี้ใน session

สำหรับการเปลี่ยนการตั้งค่า สามารถปิด "Auto-compact" ด้วย /config ได้

นอกจากนี้ยังมีคำสั่ง /clear ซึ่งสามารถลบการโต้ตอบที่ผ่านมาทั้งหมดได้อย่างสมบูรณ์

การแบ่งไฟล์ memory(CLAUDE.md) ออกเป็นหลายไฟล์

วิธีการเขียนไฟล์ CLAUDE.md โดยแยกออกเป็นหลายไฟล์มีอธิบายไว้ในลิงก์ด้านล่างนี้

ไฟล์ CLAUDE.md สามารถ import ไฟล์อื่นได้โดยใช้ @path/to/import

CLAUDE.md
## แนวทางการพัฒนา

กรุณาอ้างอิง @docs/guideline.md

เมื่อเขียนตามนี้ docs/guideline.md ก็สามารถใช้เป็น memory ได้เช่นกัน

การ import เหล่านี้สามารถทำซ้อนแบบ recursive ได้สูงสุด 5 ชั้น และในการตรวจสอบ memory ที่ถูกโหลดอยู่ สามารถตรวจสอบได้โดยใช้คำสั่ง /memory

> /memory

Memory Files
 L project: CLAUDE.md
            L docs/guideline.md

เกี่ยวกับการคิดแบบขยาย (Extended thinking)

ฟีเจอร์นี้ไม่จำกัดแค่ Claude Code เท่านั้น แต่สามารถใช้ได้กับ Claude โดยรวม

ตัวอย่างเช่น ในกรณีที่กำลังตัดสินใจเกี่ยวกับสถาปัตยกรรมที่ซับซ้อน การแก้ไขบั๊กที่ยาก หรือการวางแผนการ implement แบบหลายขั้นตอนที่ต้องใช้การคิดเชิงลึก ระบบจะประมวลผลด้วยการคิดที่ซับซ้อนมากขึ้นได้

มีข้อมูลที่สามารถกระตุ้นให้ระบบคิดแบบขยายได้ โดยการรวม keyword เฉพาะลงใน query ("คิด" ⇒ "คิดเพิ่มเติม" ⇒ "คิดอย่างรอบคอบ")

ใน official documentation ยังไม่พบ keyword เหล่านี้ แต่ลองตรวจสอบดูก่อนเผื่อมีการอัปเดตในอนาคตครับ

Custom Slash Command

Slash Command สามารถสร้างแบบปรับแต่งเองได้ มีอธิบายไว้ในลิงก์ด้านล่างนี้

เมื่อใช้ Custom Slash Command จะสามารถกำหนด prompt ที่ใช้บ่อยให้เป็นไฟล์ Markdown และทำให้ Claude Code สามารถรันได้

คำสั่งสามารถสร้างได้ตาม scope (Project Specific หรือสำหรับส่วนตัว) ด้านล่างคือตัวอย่างการสร้างแบบ Project Specific

.claude/commands/custom-sample.md
โปรดหาผลรวมของตัวเลขที่กำหนดให้และส่งกลับมาเฉพาะตัวเลขเท่านั้น

ตัวเลขที่กำหนดไว้จะอยู่ใน $ARGUMENTS

สามารถเรียกออกมาได้ดังนี้

> /project:custom-sample is running… 1 2 3

● 6

สามารถกำหนด argument ได้แบบนี้ และสามารถอ้างอิงได้ด้วย $ARGUMENTS

อ้างอิง: การใช้งาน Claude Code บน Claude ของ Bedrock

ดูตัวอย่างได้ที่ลิงก์ด้านล่างนี้
https://dev.classmethod.jp/articles/claude-code-aws-bedrock-ec2-vscode-remote-ssh-th/

รายละเอียด

รายการของ Slash Command

ด้านล่างนี้เป็นรายการของ Slash Command ที่มีอยู่

คำสั่ง คำอธิบาย
/bug ส่ง Feedback เกี่ยวกับ Claude Code
/clear ลบประวัติการสนทนา และเคลียร์ Context
/compact ลบประวัติการสนทนา แต่เก็บสรุปไว้ใน Context ตัวเลือก: /compact [คำสั่งสำหรับการสรุป]
/config เปิด panel การตั้งค่า
/cost แสดงค่าใช้จ่ายรวมและระยะเวลาของ session ปัจจุบัน
/doctor ตรวจสอบสถานะการติดตั้งของ Claude Code
/exit ออกจาก REPL
/help แสดง Help และรายการ command ที่สามารถใช้ได้
/ide จัดการการเชื่อมต่อกับ IDE และแสดงสถานะ
/init สร้างไฟล์ CLAUDE.md ใหม่ที่รวม document ของ codebase
/install ตั้งค่า Claude GitHub Actions ไปยัง GitHub repository
/login ลงชื่อเข้าใช้ผ่านบัญชี Anthropic
/logout ออกจากระบบบัญชี Anthropic
/mcp แสดงสถานะการเชื่อมต่อกับ MCP server
/memory แก้ไขไฟล์ memory ของ Claude
/migrate ย้ายจากการติดตั้ง global npm installer ไปเป็น local install
/model ตั้งค่า AI model ของ Claude Code
/permissions จัดการ rules สำหรับอนุญาตหรือปฏิเสธการใช้ tools
/pr ดึง comment จาก GitHub pull request
/release แสดง release notes
/review ตรวจสอบ (review) pull request
/status แสดงสถานะของ Claude Code เช่น version, model, account, API connectivity, และ tool status
/terminal ติดตั้ง Shift+Enter keybind สำหรับการขึ้นบรรทัดใหม่
/upgrade อัปเกรดไปเป็น Max เพื่อใช้ rate limit ที่สูงกว่าและ Opus ที่มากขึ้น
/vim สลับไปมาระหว่างโหมดแก้ไขแบบ Vim และโหมดแก้ไขปกติ

ส่วนใหญ่ได้อธิบายมาจนถึงตอนนี้แล้ว แต่ผมคิดว่าถ้าเน้นจำในส่วนด้านล่างนี้จะสะดวกในการใช้งานมากกว่า

  • /model : สามารถสลับ Model ได้
  • /login : จำเป็นเมื่อจะ Login ใหม่ (เช่น กรณีเปลี่ยนเป็นแบบ Subscriptions รายเดือน จะต้องรันอีกครั้ง)
  • /logout : จำเป็นเมื่อจะ Login ใหม่ (เช่น กรณีเปลี่ยนเป็นแบบ Subscriptions รายเดือน จะต้องรันอีกครั้ง)

รายการ CLI Command

สำหรับการใช้งานใน CLI มีการแนะนำวิธีใช้ไว้ใน official documentation ดังตัวอย่างด้านล่าง

คำสั่ง คำอธิบาย ตัวอย่าง
claude เริ่มต้นการโต้ตอบแบบ REPL claude
claude "query" เริ่มต้น REPL โดยกำหนด prompt เริ่มต้น claude "อธิบาย Project นี้"
claude -p "query" รัน query แบบครั้งเดียวแล้วออก claude -p "อธิบาย Function นี้"
cat file | claude -p "query" ประมวลผลข้อมูลที่ส่งผ่าน pipe cat logs.txt | claude -p "อธิบาย"

เราสามารถกำหนด query ตอนเริ่มต้น แล้วรัน query แบบครั้งเดียวแล้วส่งต่อให้ command อื่น หรือรับ standard input ได้เช่นกัน

รายการ CLI ที่ตรวจสอบได้ด้วย claude --help มีดังนี้

Option คำอธิบาย
-d, --debug เปิดโหมด debug
--verbose เขียนทับการตั้งค่า verbose mode ใน config file
-p, --print แสดง output แล้วจบการทำงาน (เหมาะสำหรับการใช้ pipe)
--output-format <format> รูปแบบ output (เปิดใช้งานเฉพาะตอนที่ใช้ร่วมกับ --print เท่านั้น) เลือกได้จาก text (ค่าเริ่มต้น), json (ผลลัพธ์เดียว), stream-json (streaming แบบเรียลไทม์)
--input-format <format> รูปแบบ input (เปิดใช้งานเฉพาะตอนที่ใช้ร่วมกับ --print เท่านั้น) เลือกได้จาก text (ค่าเริ่มต้น), stream-json (streaming input แบบเรียลไทม์)
--mcp-debug 【Deprecated】 เปิดโหมด MCP Debug (ใช้การ --debug)
--dangerously-skip-permissions ข้ามการตรวจสอบ permission ทั้งหมด แนะนำใช้เฉพาะใน sandbox environment ที่ไม่มีการเชื่อมต่ออินเทอร์เน็ต
--allowedTools <tools...> ระบุรายการชื่อ tools ที่อนุญาตโดยคั่นด้วย comma หรือ space
--disallowedTools <tools...> ระบุรายการชื่อ tools ที่ปฏิเสธโดยคั่นด้วย comma หรือ space
--mcp-config <file or string> โหลด MCP server จากไฟล์ JSON หรือ string
-c, --continue ดำเนินการสนทนาล่าสุดต่อ
-r, --resume [sessionId] กลับไปยังการสนทนาก่อนหน้า, ระบุ Session ID หรือเลือกรูปแบบการโต้ตอบ
--model <model> ระบุ model ที่ใช้ใน session ปัจจุบัน
--add-dir <directories...> ระบุ directory เพิ่มเติมที่อนุญาตให้ tools เข้าถึง
-v, --version แสดง version number
-h, --help แสดง command help

ถึงแม้ใน official documentation จะมีรายการอยู่แล้ว แต่โปรดทราบว่าขณะนี้แสดงข้อมูลเพียงบางส่วนเท่านั้น

ข้อมูล Official

โดยพื้นฐานแล้วการอัปเดตของ npm จะมาก่อน แล้ว document ไม่ได้จัดทำขึ้นทันที และข้อมูลอาจไม่ครอบคลุม ดังนั้นควรใช้ด้วยความระมัดระวัง

เราสามารถรับข้อมูลล่าสุดได้โดยพิมพ์คำสั่ง help

CHANGELOG ก็ไม่ได้มีการบันทึกทุกเวอร์ชันเสมอไป และไม่ได้กล่าวถึงวิธีการใช้งาน จึงควรใช้เป็นเพียงข้อมูลอ้างอิงเท่านั้น
(คำสั่ง /release-notes ก็มีเนื้อหาเหมือนกับ CHANGELOG)

ใน official documentation จะแสดงแค่วันที่ ทำให้ไม่ชัดเจนว่าเป็น snapshot ของเวอร์ชันไหน ดังนั้นควรใช้เป็นแค่ข้อมูลอ้างอิง

ตรวจสอบ official tutorial ได้ที่ลิงก์ด้านล่างนี้

ลิงก์ด้านล่างนี้สามารถใช้เป็นข้อมูลอ้างอิงสำหรับ best practice ได้เช่นกัน

สรุป

เป็นยังไงกันบ้างครับ

หวังว่าบทความนี้จะเป็นประโยชน์สำหรับผู้ที่กำลังคิดจะเริ่มใช้งาน Claude Code ครับ

บทความต้นฉบับ

https://dev.classmethod.jp/articles/get-started-claude-code-2nd/

แปลโดย: POP (Tinnakorn Maneewong) จากบริษัท Classmethod (Thailand) ครับ !

この記事をシェアする

facebookのロゴhatenaのロゴtwitterのロゴ

© Classmethod, Inc. All rights reserved.