SpyBara
Go Premium

agent-sdk/plugins.md 2026-05-14 17:02 UTC to 2026-05-15 22:58 UTC

16 added, 10 removed.

2026
Sun 31 06:39 Sat 30 06:23 Fri 29 06:38 Thu 28 06:37 Wed 27 06:42 Tue 26 06:33 Sun 24 06:25 Sat 23 06:18 Fri 22 06:33 Thu 21 06:36 Wed 20 06:35 Tue 19 06:34 Mon 18 23:59 Sun 17 01:01 Fri 15 22:58 Thu 14 17:02 Wed 13 23:01 Tue 12 22:57 Mon 11 23:00 Sun 10 23:03 Sat 9 04:57 Fri 8 22:00 Thu 7 22:59 Tue 5 23:00 Mon 4 22:58 Sat 2 18:14 Fri 1 18:19

SDK のプラグイン

Agent SDK を通じてカスタムプラグインを読み込み、コマンド、エージェント、スキル、フックで Claude Code を拡張します

プラグインを使用すると、Claude Code をカスタム機能で拡張でき、プロジェクト全体で共有できます。Agent SDK を通じて、ローカルディレクトリからプログラムでプラグインを読み込み、カスタムスラッシュコマンド、エージェント、スキル、フック、MCP サーバーをエージェントセッションに追加できます。

プラグインとは何ですか?

プラグインは Claude Code 拡張機能のパッケージであり、以下を含めることができます:

  • Skills: Claude が自律的に使用するモデル呼び出し機能(/skill-name で呼び出すこともできます)
  • Agents: 特定のタスク用の専門的なサブエージェント
  • Hooks: ツール使用およびその他のイベントに応答するイベントハンドラー
  • MCP servers: Model Context Protocol 経由の外部ツール統合

プラグイン構造とプラグインの作成方法に関する完全な情報については、Plugins を参照してください。

プラグインの読み込み

オプション設定でローカルファイルシステムパスを指定してプラグインを読み込みます。type フィールドは "local" である必要があります。これは SDK が受け入れる唯一の値です。マーケットプレイスまたはリモートリポジトリを通じて配布されているプラグインを使用するには、まずダウンロードしてローカルディレクトリパスを指定してください。SDK は複数の場所から複数のプラグインを読み込むことをサポートしています。

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
}

パス指定

プラグインパスは以下のいずれかです:

  • 相対パス: 現在の作業ディレクトリを基準に解決されます(例:"./plugins/my-plugin"
  • 絶対パス: 完全なファイルシステムパス(例:"/home/user/plugins/my-plugin"

プラグインインストールの確認

プラグインが正常に読み込まれると、システム初期化メッセージに表示されます。プラグインが利用可能であることを確認できます:

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"]
}
}

プラグインスキルの使用

プラグインのスキルは競合を避けるためにプラグイン名で自動的に名前空間化されます。スラッシュコマンドとして呼び出される場合、形式は plugin-name:skill-name です。

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);
}
}

完全な例

プラグインの読み込みと使用を示す完全な例を以下に示します:

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.message.content);
}
}
}

runWithPlugin().catch(console.error);

プラグイン構造リファレンス

プラグインディレクトリには .claude-plugin/plugin.json マニフェストファイルが含まれている必要があります。オプションで以下を含めることができます:

my-plugin/
├── .claude-plugin/
│   └── plugin.json          # Required: plugin manifest
├── 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

プラグイン作成の詳細については、以下を参照してください:

一般的なユースケース

開発とテスト

グローバルにインストールせずに開発中にプラグインを読み込みます:

plugins: [{ type: "local", path: "./dev-plugins/my-plugin" }];

プロジェクト固有の拡張機能

チーム全体の一貫性のためにプラグインをプロジェクトリポジトリに含めます:

plugins: [{ type: "local", path: "./project-plugins/team-workflows" }];

複数のプラグインソース

異なる場所からプラグインを組み合わせます:

plugins: [
  { type: "local", path: "./local-plugin" },
  { type: "local", path: "~/.claude/custom-plugins/shared-plugin" }
];

トラブルシューティング

プラグインが読み込まれない

プラグインが初期化メッセージに表示されない場合:

  1. パスを確認する: パスがプラグインルートディレクトリ(.claude-plugin/ を含む)を指していることを確認してください
  2. plugin.json を検証する: マニフェストファイルが有効な JSON 構文を持っていることを確認してください
  3. ファイルパーミッションを確認する: プラグインディレクトリが読み取り可能であることを確認してください

スキルが表示されない

プラグインスキルが機能しない場合:

  1. 名前空間を使用する: プラグインスキルはスラッシュコマンドとして呼び出される場合、plugin-name:skill-name 形式が必要です
  2. 初期化メッセージを確認する: スキルが正しい名前空間で slash_commands に表示されることを確認してください
  3. スキルファイルを検証する: 各スキルが skills/ の下の独自のサブディレクトリに SKILL.md ファイルを持っていることを確認してください(例:skills/my-skill/SKILL.md

パス解決の問題

相対パスが機能しない場合:

  1. 作業ディレクトリを確認する: 相対パスは現在の作業ディレクトリから解決されます
  2. 絶対パスを使用する: 信頼性のために、絶対パスの使用を検討してください
  3. パスを正規化する: パスユーティリティを使用してパスを正しく構築してください

関連項目