อ้างอิง 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"
}
}
}
ฟิลด์ที่จำเป็น:
| ฟิลด์ | คำอธิบาย |
|---|---|
command | LSP binary ที่รัน (ต้องอยู่ใน PATH) |
extensionToLanguage | Map extension ไฟล์ไปยัง language identifier |
ฟิลด์ที่ไม่จำเป็น:
| ฟิลด์ | คำอธิบาย |
|---|---|
args | Command-line arguments สำหรับ LSP server |
transport | Transport การสื่อสาร: stdio (ค่าเริ่มต้น) หรือ socket |
env | Environment variable ที่ตั้งค่าเมื่อเริ่ม server |
diagnostics | ว่าจะ push diagnostics เข้าสู่ context ของ Claude หลังแก้ไขหรือไม่ (ค่าเริ่มต้น true) |
LSP plugin ที่มีอยู่:
| Plugin | Language server | คำสั่งติดตั้ง |
|---|---|---|
pyright-lsp | Pyright (Python) | pip install pyright หรือ npm install -g pyright |
typescript-lsp | TypeScript Language Server | npm install -g typescript-language-server typescript |
rust-analyzer-lsp | rust-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 รองรับฟิลด์เหล่านี้:
| ฟิลด์ | ประเภท | คำอธิบาย |
|---|---|---|
name | string | จำเป็น. ตัวระบุที่ไม่ซ้ำกันและ skill namespace |
description | string | คำอธิบาย plugin สั้น ๆ |
version | string | เวอร์ชัน plugin |
author | object | ข้อมูลผู้เขียน plugin |
homepage | string | URL หน้าแรกหรือเอกสาร plugin |
repository | string | URL repository ซอร์สโค้ด |
license | string | SPDX license identifier |
skills | string|array | Path แบบกำหนดเองไปยัง skill directory |
agents | string|array | Path แบบกำหนดเองไปยัง agent file |
hooks | string|object | การกำหนดค่า hooks หรือ path ไปยังไฟล์ hooks |
mcpServers | string|object | การกำหนดค่า MCP server |
lspServers | string|object | การกำหนดค่า LSP server |
defaultEnabled | boolean | ว่า 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 ไม่ทำงานตามที่คาดหวัง:
- ตรวจสอบโครงสร้าง: ให้แน่ใจว่า directory อยู่ที่ plugin root ไม่ใช่ภายใน
.claude-plugin/ - ทดสอบ component แต่ละอย่าง: ตรวจสอบแต่ละ skill, agent และ hook แยกกัน
- ดู tab Errors ของ Plugin: ใน
/plugininterface สำหรับ 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 หรือใหม่กว่า