Plugin memungkinkan Anda memperluas Claude Code dengan fungsionalitas khusus yang dapat dibagikan di seluruh proyek. Melalui Agent SDK, Anda dapat secara terprogram memuat plugin dari direktori lokal untuk menambahkan perintah garis miring khusus, agen, keterampilan, hook, dan server MCP ke sesi agen Anda.
Plugin adalah paket ekstensi Claude Code yang dapat mencakup:
Untuk informasi lengkap tentang struktur plugin dan cara membuat plugin, lihat Plugin.
Muat plugin dengan menyediakan jalur sistem file lokal mereka dalam konfigurasi opsi Anda. SDK mendukung pemuatan beberapa plugin dari lokasi berbeda.
import { query } from "@anthropic-ai/claude-agent-sdk";
for await (const message of query({
prompt: "Hello",
options: {
plugins: [
{ type: "local", path: "./my-plugin" },
{ type: "local", path: "/absolute/path/to/another-plugin" }
]
}
})) {
// Plugin commands, agents, and other features are now available
}Jalur plugin dapat berupa:
"./plugins/my-plugin")"/home/user/plugins/my-plugin")Jalur harus menunjuk ke direktori root plugin (direktori yang berisi .claude-plugin/plugin.json).
Ketika plugin dimuat dengan berhasil, mereka muncul dalam pesan inisialisasi sistem. Anda dapat memverifikasi bahwa plugin Anda tersedia:
Perintah dari plugin secara otomatis diberi namespace dengan nama plugin untuk menghindari konflik. Formatnya adalah plugin-name:command-name.
Jika Anda memasang plugin melalui CLI (misalnya, /plugin install my-plugin@marketplace), Anda masih dapat menggunakannya di SDK dengan menyediakan jalur instalasinya. Periksa ~/.claude/plugins/ untuk plugin yang dipasang CLI.
Berikut adalah contoh lengkap yang mendemonstrasikan pemuatan dan penggunaan plugin:
Direktori plugin harus berisi file manifes .claude-plugin/plugin.json. Secara opsional dapat mencakup:
my-plugin/
├── .claude-plugin/
│ └── plugin.json # Required: plugin manifest
├── commands/ # Custom slash commands
│ └── custom-cmd.md
├── agents/ # Custom agents
│ └── specialist.md
├── skills/ # Agent Skills
│ └── my-skill/
│ └── SKILL.md
├── hooks/ # Event handlers
│ └── hooks.json
└── .mcp.json # MCP server definitionsUntuk informasi terperinci tentang membuat plugin, lihat:
Muat plugin selama pengembangan tanpa memasangnya secara global:
plugins: [
{ type: "local", path: "./dev-plugins/my-plugin" }
]Sertakan plugin di repositori proyek Anda untuk konsistensi di seluruh tim:
plugins: [
{ type: "local", path: "./project-plugins/team-workflows" }
]Gabungkan plugin dari lokasi berbeda:
plugins: [
{ type: "local", path: "./local-plugin" },
{ type: "local", path: "~/.claude/custom-plugins/shared-plugin" }
]Jika plugin Anda tidak muncul dalam pesan init:
.claude-plugin/)Jika perintah plugin tidak berfungsi:
plugin-name:command-nameslash_commands dengan namespace yang benarcommands/Jika jalur relatif tidak berfungsi:
import { query } from "@anthropic-ai/claude-agent-sdk";
for await (const message of query({
prompt: "Hello",
options: {
plugins: [{ type: "local", path: "./my-plugin" }]
}
})) {
if (message.type === "system" && message.subtype === "init") {
// Check loaded plugins
console.log("Plugins:", message.plugins);
// Example: [{ name: "my-plugin", path: "./my-plugin" }]
// Check available commands from plugins
console.log("Commands:", message.slash_commands);
// Example: ["/help", "/compact", "my-plugin:custom-command"]
}
}import { query } from "@anthropic-ai/claude-agent-sdk";
// Load a plugin with a custom /greet command
for await (const message of query({
prompt: "/my-plugin:greet", // Use plugin command with namespace
options: {
plugins: [{ type: "local", path: "./my-plugin" }]
}
})) {
// Claude executes the custom greeting command from the plugin
if (message.type === "assistant") {
console.log(message.content);
}
}import { query } from "@anthropic-ai/claude-agent-sdk";
import * as path from "path";
async function runWithPlugin() {
const pluginPath = path.join(__dirname, "plugins", "my-plugin");
console.log("Loading plugin from:", pluginPath);
for await (const message of query({
prompt: "What custom commands do you have available?",
options: {
plugins: [
{ type: "local", path: pluginPath }
],
maxTurns: 3
}
})) {
if (message.type === "system" && message.subtype === "init") {
console.log("Loaded plugins:", message.plugins);
console.log("Available commands:", message.slash_commands);
}
if (message.type === "assistant") {
console.log("Assistant:", message.content);
}
}
}
runWithPlugin().catch(console.error);