agent-sdk/plugins.md +16 −10
46 46
47 ```python Python theme={null}47 ```python Python theme={null}
48 import asyncio48 import asyncio
4949 from claude_agent_sdk import query from claude_agent_sdk import query, ClaudeAgentOptions
50 50
51 51
52 async def main():52 async def main():
53 async for message in query(53 async for message in query(
54 prompt="Hello",54 prompt="Hello",
5555 options={ options=ClaudeAgentOptions(
5656 "plugins": [ plugins=[
57 {"type": "local", "path": "./my-plugin"},57 {"type": "local", "path": "./my-plugin"},
58 {"type": "local", "path": "/absolute/path/to/another-plugin"},58 {"type": "local", "path": "/absolute/path/to/another-plugin"},
59 ]59 ]
6060 }, ),
61 ):61 ):
62 # Plugin commands, agents, and other features are now available62 # Plugin commands, agents, and other features are now available
63 pass63 pass
106 106
107 ```python Python theme={null}107 ```python Python theme={null}
108 import asyncio108 import asyncio
109109 from claude_agent_sdk import query from claude_agent_sdk import query, ClaudeAgentOptions, SystemMessage
110 110
111 111
112 async def main():112 async def main():
113 async for message in query(113 async for message in query(
114114 prompt="Hello", options={"plugins": [{"type": "local", "path": "./my-plugin"}]} prompt="Hello",
115 options=ClaudeAgentOptions(
116 plugins=[{"type": "local", "path": "./my-plugin"}]
117 ),
115 ):118 ):
116119 if message.type == "system" and message.subtype == "init": if isinstance(message, SystemMessage) and message.subtype == "init":
117 # Check loaded plugins120 # Check loaded plugins
118 print("Plugins:", message.data.get("plugins"))121 print("Plugins:", message.data.get("plugins"))
119 # Example: [{"name": "my-plugin", "path": "./my-plugin"}]122 # Example: [{"name": "my-plugin", "path": "./my-plugin"}]
151 154
152 ```python Python theme={null}155 ```python Python theme={null}
153 import asyncio156 import asyncio
154157 from claude_agent_sdk import query, AssistantMessage, TextBlock from claude_agent_sdk import query, ClaudeAgentOptions, AssistantMessage, TextBlock
155 158
156 159
157 async def main():160 async def main():
158 # Load a plugin with a custom /greet skill161 # Load a plugin with a custom /greet skill
159 async for message in query(162 async for message in query(
160 prompt="/demo-plugin:greet", # Use plugin skill with namespace163 prompt="/demo-plugin:greet", # Use plugin skill with namespace
161164 options={"plugins": [{"type": "local", "path": "./plugins/demo-plugin"}]}, options=ClaudeAgentOptions(
165 plugins=[{"type": "local", "path": "./plugins/demo-plugin"}]
166 ),
162 ):167 ):
163 # Claude executes the custom greeting skill from the plugin168 # Claude executes the custom greeting skill from the plugin
164 if isinstance(message, AssistantMessage):169 if isinstance(message, AssistantMessage):
219 from claude_agent_sdk import (224 from claude_agent_sdk import (
220 AssistantMessage,225 AssistantMessage,
221 ClaudeAgentOptions,226 ClaudeAgentOptions,
227 SystemMessage,
222 TextBlock,228 TextBlock,
223 query,229 query,
224 )230 )
238 async for message in query(244 async for message in query(
239 prompt="What custom commands do you have available?", options=options245 prompt="What custom commands do you have available?", options=options
240 ):246 ):
241247 if message.type == "system" and message.subtype == "init": if isinstance(message, SystemMessage) and message.subtype == "init":
242 print(f"Loaded plugins: {message.data.get('plugins')}")248 print(f"Loaded plugins: {message.data.get('plugins')}")
243 print(f"Available commands: {message.data.get('slash_commands')}")249 print(f"Available commands: {message.data.get('slash_commands')}")
244 250