SpyBara
Go Premium

agent-sdk/plugins.md 2026-08-10 22:57 UTC to 2026-08-11 22:03 UTC

1 added, 32 removed.

2026
Wed 12 02:57 Tue 11 22:03 Mon 10 22:57 Sun 9 04:02 Sat 8 04:59 Fri 7 23:57 Thu 6 15:02 Wed 5 22:02 Tue 4 22:59 Mon 3 20:02 Sun 2 19:00

Plugins in the SDK

Load custom plugins to extend Claude Code with skills, agents, hooks, and MCP servers through the Agent SDK

Plugins allow you to extend Claude Code with custom functionality that can be shared across projects. Through the Agent SDK, you can programmatically load plugins from local directories to add skills, agents, hooks, and MCP servers to your agent sessions.

What are plugins?

Plugins are packages of Claude Code extensions that can include:

  • Skills: Model-invoked capabilities that Claude uses autonomously (can also be invoked with /skill-name)
  • Agents: Specialized subagents for specific tasks
  • Hooks: Event handlers that respond to tool use and other events
  • MCP servers: External tool integrations via Model Context Protocol

For complete information on plugin structure and how to create plugins, see Plugins.

Loading plugins

Load plugins by providing their local file system paths in your options configuration. The type field must be "local", the only value the SDK accepts. The SDK supports loading multiple plugins from different locations.

To use a plugin distributed through a marketplace or remote repository, download it first and provide the local directory path. For the directory layout a plugin needs, see the Plugin structure reference below.

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
}

Path specifications

Plugin paths can be:

  • Relative paths: Resolved relative to your current working directory (for example, "./plugins/my-plugin")
  • Absolute paths: Full file system paths (for example, "/home/user/plugins/my-plugin")

Verifying plugin installation

When plugins load successfully, they appear in the system initialization message. You can verify that your plugins are available:

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: "/absolute/path/to/my-plugin" }]

// Plugin skills appear with the plugin name as a prefix
console.log("Skills:", message.skills);
// Example: ["my-plugin:greet"]

// Plugin commands use the same prefix, and skills appear here too
console.log("Commands:", message.slash_commands);
// Example: ["compact", "context", "my-plugin:custom-command", "my-plugin:greet"]
}
}

Using plugin skills

Skills from plugins are automatically namespaced with the plugin name to avoid conflicts. To invoke one directly, send /plugin-name:skill-name as the prompt.

import { query } from "@anthropic-ai/claude-agent-sdk";

// Load a plugin with a custom /greet skill
for await (const message of query({
prompt: "/my-plugin:greet", // Use plugin skill with namespace
options: {
plugins: [{ type: "local", path: "./my-plugin" }]
}
})) {
// Claude executes the custom greeting skill from the plugin
if (message.type === "assistant") {
console.log(message.message.content);
}
}

Complete example

Here's a full example demonstrating plugin loading and usage:

import { query } from "@anthropic-ai/claude-agent-sdk";
import { fileURLToPath } from "node:url";

async function runWithPlugin() {
const pluginPath = fileURLToPath(new URL("./plugins/my-plugin", import.meta.url));

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 skills:", message.skills);
console.log("Available commands:", message.slash_commands);
}

if (message.type === "assistant") {
console.log("Assistant:", message.message.content);
}
}
}

runWithPlugin().catch(console.error);

Plugin structure reference

A plugin directory typically contains a .claude-plugin/plugin.json manifest file. The manifest is optional. When omitted, Claude Code auto-discovers components from the directory layout. The directory can include:

my-plugin/
├── .claude-plugin/
│   └── plugin.json          # Plugin manifest (optional, components auto-discovered without it)
├── skills/                   # Agent Skills (invoked autonomously or via /skill-name)
│   └── my-skill/
│       └── SKILL.md
├── commands/                 # Legacy: use skills/ instead
│   └── custom-cmd.md
├── agents/                   # Custom agents
│   └── specialist.md
├── hooks/                    # Event handlers
│   └── hooks.json
└── .mcp.json                # MCP server definitions

Multiple plugin sources

Combine plugins from different locations:

import * as os from "node:os";
import * as path from "node:path";

plugins: [
  { type: "local", path: "./local-plugin" },
  {
    type: "local",
    path: path.join(os.homedir(), ".claude", "custom-plugins", "shared-plugin")
  }
];

Troubleshooting

Plugin not loading

If your plugin doesn't appear in the init message:

  1. Check the path: ensure the path points to the plugin root directory, the parent of skills/, agents/, hooks/, commands/ (legacy), or .claude-plugin/
  2. Validate plugin.json: if your plugin includes a manifest, ensure it has valid JSON syntax
  3. Check file permissions: ensure the plugin directory is readable
  4. Confirm the directory exists: the SDK skips a nonexistent path, and the plugin doesn't appear in the init message's plugins list

Skills not appearing

If plugin skills don't work:

  1. Use the namespace: invoke plugin skills as /plugin-name:skill-name
  2. Check init message: verify the skill appears in the skills list with the correct namespace
  3. Validate skill files: ensure each skill has a SKILL.md file in its own subdirectory under skills/, for example skills/my-skill/SKILL.md

See also