สร้าง Plugins
สร้าง plugin แบบกำหนดเองเพื่อขยาย Claude Code ด้วย skills, agents, hooks และ MCP servers
Plugin ช่วยให้คุณขยาย Claude Code ด้วยฟังก์ชันแบบกำหนดเองที่สามารถแชร์กับโปรเจกต์และทีม
กำลังติดตั้ง plugin ที่มีอยู่? ดู Discover and install plugins สำหรับข้อกำหนดทางเทคนิคทั้งหมด ดู Plugins reference
เมื่อไรควรใช้ Plugins กับการกำหนดค่า Standalone
| วิธีการ | ชื่อ Skill | เหมาะที่สุดสำหรับ |
|---|---|---|
Standalone (directory .claude/) | /hello | Workflow ส่วนตัว การปรับแต่งเฉพาะโปรเจกต์ การทดลอง |
| Plugins (directory ที่มีตัวเอง) | /plugin-name:hello | แชร์กับเพื่อนร่วมทีม แจกจ่ายให้ชุมชน ใช้ซ้ำข้ามโปรเจกต์ |
ใช้การกำหนดค่า standalone เมื่อ:
- กำหนดแต่งให้โปรเจกต์เดียว
- การกำหนดค่าเป็นส่วนตัวและไม่ต้องแชร์
- ทดลองใช้ skills หรือ hooks ก่อน package
ใช้ plugins เมื่อ:
- ต้องการแชร์ฟังก์ชันกับทีมหรือชุมชน
- ต้องการ skills/agents เดิมข้ามหลายโปรเจกต์
- แจกจ่ายผ่าน marketplace
Quickstart
ขั้นตอนที่ 1: สร้าง plugin directory
mkdir my-first-plugin
ขั้นตอนที่ 2: สร้าง plugin manifest
สร้าง .claude-plugin directory ภายใน plugin folder:
mkdir my-first-plugin/.claude-plugin
สร้าง my-first-plugin/.claude-plugin/plugin.json:
{
"name": "my-first-plugin",
"description": "A greeting plugin to learn the basics",
"version": "1.0.0",
"author": {
"name": "Your Name"
}
}
| ฟิลด์ | วัตถุประสงค์ |
|---|---|
name | ตัวระบุที่ไม่ซ้ำกันและ skill namespace Skill มี prefix นี้ (เช่น /my-first-plugin:hello) |
description | แสดงใน plugin manager เมื่อ browse หรือติดตั้ง plugin |
version | ถ้าตั้งค่า ผู้ใช้จะได้รับอัปเดตเฉพาะเมื่อคุณ bump ฟิลด์นี้ |
author | ช่วยในการระบุแหล่งที่มา |
ขั้นตอนที่ 3: เพิ่ม skill
mkdir -p my-first-plugin/skills/hello
สร้าง my-first-plugin/skills/hello/SKILL.md:
---
description: Greet the user with a friendly message
disable-model-invocation: true
---
Greet the user warmly and ask how you can help them today.
ขั้นตอนที่ 4: ทดสอบ plugin
claude --plugin-dir ./my-first-plugin
เมื่อ Claude Code เริ่ม ลอง skill ใหม่:
/my-first-plugin:hello
ขั้นตอนที่ 5: เพิ่ม skill arguments
อัปเดตไฟล์ SKILL.md:
---
description: Greet the user with a personalized message
---
# Hello Skill
Greet the user named "$ARGUMENTS" warmly and ask how you can help them today.
รัน /reload-plugins เพื่อรับการเปลี่ยนแปลง แล้วลองด้วยชื่อของคุณ:
/my-first-plugin:hello Alex
พัฒนา Plugin ใน Skills Directory
แทนที่จะส่ง --plugin-dir ทุกครั้งที่เปิด คุณสามารถเก็บ plugin ใน skills directory และให้ Claude Code โหลดอัตโนมัติ:
claude plugin init my-tool
สร้าง ~/.claude/skills/my-tool/ พร้อม .claude-plugin/plugin.json manifest และ starter SKILL.md
โครงสร้าง Plugin
| Directory | ตำแหน่ง | วัตถุประสงค์ |
|---|---|---|
.claude-plugin/ | Plugin root | มี plugin.json manifest |
skills/ | Plugin root | Skills เป็น <name>/SKILL.md directories |
commands/ | Plugin root | Skills เป็นไฟล์ Markdown แบบเรียบ |
agents/ | Plugin root | Custom agent definitions |
hooks/ | Plugin root | Event handlers ใน hooks.json |
.mcp.json | Plugin root | MCP server configurations |
.lsp.json | Plugin root | LSP server configurations |
monitors/ | Plugin root | Background monitor configurations |
bin/ | Plugin root | Executable ที่เพิ่มใน PATH ของ Bash tool |
settings.json | Plugin root | Settings เริ่มต้นที่ใช้เมื่อเปิด plugin |
คำเตือน: อย่าวาง
commands/,agents/,skills/หรือhooks/ภายใน directory.claude-plugin/มีเฉพาะplugin.jsonอยู่ใน.claude-plugin/directory ต่าง ๆ ต้องอยู่ที่ plugin root
พัฒนา Plugin ที่ซับซ้อนขึ้น
เพิ่ม Skills ให้ Plugin
---
description: Reviews code for best practices and potential issues. Use when reviewing code, checking PRs, or analyzing code quality.
---
When reviewing code, check for:
1. Code organization and structure
2. Error handling
3. Security concerns
4. Test coverage
เพิ่ม LSP Servers
{
"go": {
"command": "gopls",
"args": ["serve"],
"extensionToLanguage": {
".go": "go"
}
}
}
เพิ่ม Background Monitors
[
{
"name": "error-log",
"command": "tail -F ./logs/error.log",
"description": "Application error log"
}
]
Ship Default Settings กับ Plugin
{
"agent": "security-reviewer"
}
ทดสอบ Plugin ของคุณ
claude --plugin-dir ./my-plugin
Flag นี้ยังรับ .zip archive ของ plugin directory ด้วย (ต้องการ Claude Code v2.1.128 หรือใหม่กว่า):
claude --plugin-dir ./my-plugin.zip
โหลด plugin หลายตัวพร้อมกัน:
claude --plugin-dir ./plugin-one --plugin-dir ./plugin-two
Convert การกำหนดค่าที่มีอยู่เป็น Plugins
ขั้นตอนการ migrate
- สร้างโครงสร้าง plugin:
mkdir -p my-plugin/.claude-plugin
สร้าง my-plugin/.claude-plugin/plugin.json:
{
"name": "my-plugin",
"description": "Migrated from standalone configuration",
"version": "1.0.0"
}
- คัดลอกไฟล์ที่มีอยู่:
# คัดลอก commands
cp -r .claude/commands my-plugin/
# คัดลอก agents (ถ้ามี)
cp -r .claude/agents my-plugin/
# คัดลอก skills (ถ้ามี)
cp -r .claude/skills my-plugin/
- Migrate hooks:
สร้าง my-plugin/hooks/hooks.json:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [{ "type": "command", "command": "jq -r '.tool_input.file_path' | xargs npm run lint:fix" }]
}
]
}
}
- ทดสอบ plugin ที่ migrate:
claude --plugin-dir ./my-plugin
สิ่งที่เปลี่ยนแปลงเมื่อ migrate
Standalone (.claude/) | Plugin |
|---|---|
| มีเฉพาะในโปรเจกต์เดียว | สามารถแชร์ผ่าน marketplace |
ไฟล์ใน .claude/commands/ | ไฟล์ใน plugin-name/commands/ |
Hooks ใน settings.json | Hooks ใน hooks/hooks.json |
ส่ง Plugin ไปยัง Community Marketplace
Anthropic ดูแล marketplace สาธารณะสองแห่ง:
claude-plugins-official: Plugin ที่ดูแลโดย Anthropicclaude-community: Community marketplace สาธารณะ ผู้ใช้เพิ่มด้วย/plugin marketplace add anthropics/claude-plugins-community
ก่อน submit รัน claude plugin validate ในเครื่อง