Skip to main content

อ้างอิง Plugins

อ้างอิงทางเทคนิคสมบูรณ์สำหรับระบบ plugin ของ Claude Code รวมถึง schema, CLI command และข้อกำหนด component

กำลังติดตั้ง plugin? ดู Discover and install plugins สำหรับการสร้าง plugin ดู Plugins สำหรับการแจกจ่าย plugin ดู Plugin marketplaces

Plugin คือ directory ที่มีตัวเองของ component ที่ขยาย Claude Code ด้วยฟังก์ชันแบบกำหนดเอง Plugin component ได้แก่ skills, agents, hooks, MCP servers, LSP servers และ monitors

อ้างอิง Plugin Components

Skills

Plugin เพิ่ม skill ให้ Claude Code สร้างทางลัด /name ที่คุณหรือ Claude สามารถเรียกใช้

ตำแหน่ง: directory skills/ หรือ commands/ ใน plugin root หรือไฟล์ SKILL.md เดียวที่ plugin root

โครงสร้าง Skill:

skills/
├── pdf-processor/
│ ├── SKILL.md
│ ├── reference.md (optional)
│ └── scripts/ (optional)
└── code-reviewer/
└── SKILL.md

Agents

Plugin สามารถให้ subagent เฉพาะทางสำหรับ task เฉพาะ

ตำแหน่ง: directory agents/ ใน plugin root

โครงสร้าง:

---
name: agent-name
description: What this agent specializes in and when Claude should invoke it
model: sonnet
effort: medium
maxTurns: 20
disallowedTools: Write, Edit
---

Detailed system prompt for the agent describing its role, expertise, and behavior.

Plugin agent รองรับฟิลด์ frontmatter: name, description, model, effort, maxTurns, tools, disallowedTools, skills, memory, background และ isolation ด้วยเหตุผลด้านความปลอดภัย hooks, mcpServers และ permissionMode ไม่รองรับสำหรับ agent ที่มากับ plugin

Hooks

Plugin สามารถให้ event handler ที่ตอบสนองต่อ Claude Code events อัตโนมัติ

ตำแหน่ง: hooks/hooks.json ใน plugin root หรือ inline ใน plugin.json

การกำหนดค่า Hook:

{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "\"${CLAUDE_PLUGIN_ROOT}\"/scripts/format-code.sh"
}
]
}
]
}
}

Plugin hook ตอบสนองต่อ lifecycle event เดียวกันกับ user-defined hooks:

Eventเมื่อทำงาน
SessionStartเมื่อเซสชันเริ่มหรือ resume
UserPromptSubmitเมื่อคุณ submit prompt ก่อนที่ Claude จะประมวลผล
PreToolUseก่อน tool call รัน
PostToolUseหลัง tool call สำเร็จ
Stopเมื่อ Claude ตอบสนองเสร็จ
SessionEndเมื่อเซสชันสิ้นสุด
FileChangedเมื่อไฟล์ที่ watch เปลี่ยน

MCP Servers

Plugin สามารถ bundle MCP server เพื่อเชื่อมต่อ Claude Code กับ tool และบริการภายนอก

ตำแหน่ง: .mcp.json ใน plugin root หรือ inline ใน plugin.json

การกำหนดค่า MCP server:

{
"mcpServers": {
"plugin-database": {
"command": "${CLAUDE_PLUGIN_ROOT}/servers/db-server",
"args": ["--config", "${CLAUDE_PLUGIN_ROOT}/config.json"],
"env": {
"DB_PATH": "${CLAUDE_PLUGIN_ROOT}/data"
}
}
}
}

LSP Servers

กำลังใช้ LSP plugin? ติดตั้งจาก official marketplace: ค้นหา "lsp" ใน tab Discover ของ /plugin

ตำแหน่ง: .lsp.json ใน plugin root หรือ inline ใน plugin.json

Format ไฟล์ .lsp.json:

{
"go": {
"command": "gopls",
"args": ["serve"],
"extensionToLanguage": {
".go": "go"
}
}
}

ฟิลด์ที่จำเป็น:

ฟิลด์คำอธิบาย
commandLSP binary ที่รัน (ต้องอยู่ใน PATH)
extensionToLanguageMap extension ไฟล์ไปยัง language identifier

ฟิลด์ที่ไม่จำเป็น:

ฟิลด์คำอธิบาย
argsCommand-line arguments สำหรับ LSP server
transportTransport การสื่อสาร: stdio (ค่าเริ่มต้น) หรือ socket
envEnvironment variable ที่ตั้งค่าเมื่อเริ่ม server
diagnosticsว่าจะ push diagnostics เข้าสู่ context ของ Claude หลังแก้ไขหรือไม่ (ค่าเริ่มต้น true)

LSP plugin ที่มีอยู่:

PluginLanguage serverคำสั่งติดตั้ง
pyright-lspPyright (Python)pip install pyright หรือ npm install -g pyright
typescript-lspTypeScript Language Servernpm install -g typescript-language-server typescript
rust-analyzer-lsprust-analyzerดู rust-analyzer installation

Monitors

Plugin สามารถประกาศ background monitor ที่ Claude Code เริ่มอัตโนมัติเมื่อ plugin active แต่ละ monitor รัน shell command ตลอด lifetime ของเซสชันและส่ง stdout line ทุกบรรทัดไปยัง Claude เป็น notification

หมายเหตุ: Plugin monitor ต้องการ Claude Code v2.1.105 หรือใหม่กว่า

ตำแหน่ง: monitors/monitors.json ใน plugin root หรือ inline ใน plugin.json

[
{
"name": "deploy-status",
"command": "\"${CLAUDE_PLUGIN_ROOT}\"/scripts/poll-deploy.sh ${user_config.api_endpoint}",
"description": "Deployment status changes"
},
{
"name": "error-log",
"command": "tail -F ./logs/error.log",
"description": "Application error log"
}
]

Plugin Manifest Schema

ไฟล์ plugin.json รองรับฟิลด์เหล่านี้:

ฟิลด์ประเภทคำอธิบาย
namestringจำเป็น. ตัวระบุที่ไม่ซ้ำกันและ skill namespace
descriptionstringคำอธิบาย plugin สั้น ๆ
versionstringเวอร์ชัน plugin
authorobjectข้อมูลผู้เขียน plugin
homepagestringURL หน้าแรกหรือเอกสาร plugin
repositorystringURL repository ซอร์สโค้ด
licensestringSPDX license identifier
skillsstring|arrayPath แบบกำหนดเองไปยัง skill directory
agentsstring|arrayPath แบบกำหนดเองไปยัง agent file
hooksstring|objectการกำหนดค่า hooks หรือ path ไปยังไฟล์ hooks
mcpServersstring|objectการกำหนดค่า MCP server
lspServersstring|objectการกำหนดค่า LSP server
defaultEnabledbooleanว่า plugin เปิดใช้งานหลังติดตั้งหรือไม่ (ค่าเริ่มต้น: true)

CLI Commands

# ตรวจสอบ plugin ก่อน submit
claude plugin validate

# สร้าง plugin ใหม่ใน skills directory
claude plugin init my-tool

# รัน Claude พร้อม plugin ชั่วคราว
claude --plugin-dir ./my-plugin

# โหลด plugin ที่โฮสต์ใน URL
claude --plugin-url https://example.com/my-plugin.zip

เครื่องมือ Debug และ Development

ถ้า plugin ไม่ทำงานตามที่คาดหวัง:

  1. ตรวจสอบโครงสร้าง: ให้แน่ใจว่า directory อยู่ที่ plugin root ไม่ใช่ภายใน .claude-plugin/
  2. ทดสอบ component แต่ละอย่าง: ตรวจสอบแต่ละ skill, agent และ hook แยกกัน
  3. ดู tab Errors ของ Plugin: ใน /plugin interface สำหรับ error message

Skills-Directory Plugins

Plugin ที่เก็บใน skills directory (~/.claude/skills/ หรือ .claude/skills/) โหลดอัตโนมัติโดยไม่ต้องติดตั้งจาก marketplace สร้างด้วย:

claude plugin init my-tool

Plugin นี้โหลดเป็น my-tool@skills-dir โดยไม่ต้องมี marketplace หรือขั้นตอนติดตั้ง

Plugin Caching และ File Resolution

เมื่อผู้ใช้ติดตั้ง plugin Claude Code คัดลอก plugin directory ไปยัง versioned plugin cache ที่ ~/.claude/plugins/cache ซึ่งหมายความว่า plugin ไม่สามารถอ้างอิงไฟล์นอก directory ของพวกมันได้

ถ้าต้องการแชร์ไฟล์ข้ามหลาย plugin ใช้ symlink

การจัดการเวอร์ชัน

ถ้า version ตั้งค่าใน plugin.json ผู้ใช้ได้รับอัปเดตเฉพาะเมื่อ field นั้นเปลี่ยน ถ้าไม่มี version และ plugin แจกจ่ายผ่าน git ทุก commit SHA นับเป็นเวอร์ชันใหม่

การเปิดใช้งานค่าเริ่มต้น

ตั้งค่า defaultEnabled: false เพื่อติดตั้ง plugin ในสถานะปิดใช้งานจนกว่าผู้ใช้จะ opt in ต้องการ Claude Code v2.1.154 หรือใหม่กว่า