/vibe:ghcopilot-instr-copilot-sdk-pythonfrom vibe
Provides guidance on using the GitHub Copilot SDK for Python, including client initialization, session management, and configuration options.
Ships in vibe. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Always install via pip:
pip install github-copilot-sdk
# or with poetry
poetry add github-copilot-sdk
# or with uv
uv add github-copilot-sdk
from copilot import CopilotClient, PermissionHandler
import asyncio
async def main():
async with CopilotClient() as client:
# Use client...
pass
asyncio.run(main())
When creating a CopilotClient, use a dict with these keys:
cli_path - Path to CLI executable (default: "copilot" from PATH or COPILOT_CLI_PATH env var)cli_url - URL of existing CLI server (e.g., "localhost:8080"). When provided, client won't spawn a processport - Server port (default: 0 for random)use_stdio - Use stdio transport instead of TCP (default: True)log_level - Log level (default: "info")auto_start - Auto-start server (default: True)auto_restart - Auto-restart on crash (default: True)cwd - Working directory for the CLI process (default: os.getcwd())env - Environment variables for the CLI process (dict)For explicit control:
from copilot import CopilotClient
import asyncio
async def main():
client = CopilotClient({"auto_start": False})
await client.start()
# Use client...
await client.stop()
asyncio.run(main())
Use force_stop() when stop() takes too long.
Use a dict for SessionConfig:
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"model": "gpt-5",
"streaming": True,
"tools": [...],
"system_message": { ... },
"available_tools": ["tool1", "tool2"],
"excluded_tools": ["tool3"],
"provider": { ... }
})
session_id - Custom session ID (str)model - Model name ("gpt-5", "claude-sonnet-4.5", etc.)tools - Custom tools exposed to the CLI (list[Tool])system_message - System message customization (dict)available_tools - Allowlist of tool names (list[str])excluded_tools - Blocklist of tool names (list[str])provider - Custom API provider configuration (BYOK) (ProviderConfig)streaming - Enable streaming response chunks (bool)mcp_servers - MCP server configurations (list)custom_agents - Custom agent configurations (list)config_dir - Config directory override (str)skill_directories - Skill directories (list[str])disabled_skills - Disabled skills (list[str])on_permission_request - Permission request handler (callable)session = await client.resume_session("session-id", {
"on_permission_request": PermissionHandler.approve_all,
"tools": [my_new_tool]
})
session.session_id - Get session identifier (str)await session.send({"prompt": "...", "attachments": [...]}) - Send message, returns str (message ID)await session.send_and_wait({"prompt": "..."}, timeout=60.0) - Send and wait for idle, returns SessionEvent | Noneawait session.abort() - Abort current processingawait session.get_messages() - Get all events/messages, returns list[SessionEvent]await session.destroy() - Clean up sessionALWAYS use asyncio events or futures for waiting on session events:
import asyncio
done = asyncio.Event()
def handler(event):
if event.type == "assistant.message":
print(event.data.content)
elif event.type == "session.idle":
done.set()
session.on(handler)
await session.send({"prompt": "..."})
await done.wait()
The on() method returns a function that unsubscribes:
unsubscribe = session.on(lambda event: print(event.type))
# Later...
unsubscribe()
Use attribute access for event type checking:
def handler(event):
if event.type == "user.message":
# Handle user message
pass
elif event.type == "assistant.message":
print(event.data.content)
elif event.type == "tool.executionStart":
# Tool execution started
pass
elif event.type == "tool.executionComplete":
# Tool execution completed
pass
elif event.type == "session.start":
# Session started
pass
elif event.type == "session.idle":
# Session is idle (processing complete)
pass
elif event.type == "session.error":
print(f"Error: {event.data.message}")
session.on(handler)
Set streaming: True in SessionConfig:
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"model": "gpt-5",
"streaming": True
})
Handle both delta events (incremental) and final events:
import asyncio
done = asyncio.Event()
def handler(event):
if event.type == "assistant.message.delta":
# Incremental text chunk
print(event.data.delta_content, end="", flush=True)
elif event.type == "assistant.reasoning.delta":
# Incremental reasoning chunk (model-dependent)
print(event.data.delta_content, end="", flush=True)
elif event.type == "assistant.message":
# Final complete message
print("\n--- Final ---")
print(event.data.content)
elif event.type == "assistant.reasoning":
# Final reasoning content
print("--- Reasoning ---")
print(event.data.content)
elif event.type == "session.idle":
done.set()
session.on(handler)
await session.send({"prompt": "Tell me a story"})
await done.wait()
Note: Final events (assistant.message, assistant.reasoning) are ALWAYS sent regardless of streaming setting.
Use define_tool for tool definitions:
from copilot import define_tool
async def fetch_issue(issue_id: str):
# Fetch issue from tracker
return {"id": issue_id, "status": "open"}
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"model": "gpt-5",
"tools": [
define_tool(
name="lookup_issue",
description="Fetch issue details from tracker",
parameters={
"type": "object",
"properties": {
"id": {"type": "string", "description": "Issue ID"}
},
"required": ["id"]
},
handler=lambda args, inv: fetch_issue(args["id"])
)
]
})
The SDK works well with Pydantic models:
from pydantic import BaseModel, Field
class WeatherArgs(BaseModel):
location: str = Field(description="City name")
units: str = Field(default="fahrenheit", description="Temperature units")
async def get_weather(args: WeatherArgs, inv):
return {"temperature": 72, "units": args.units}
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"tools": [
define_tool(
name="get_weather",
description="Get weather for a location",
parameters=WeatherArgs.model_json_schema(),
handler=lambda args, inv: get_weather(WeatherArgs(**args), inv)
)
]
})
{
"text_result_for_llm": str, # Result shown to LLM
"result_type": "success" | "failure",
"error": str, # Optional: Internal error (not shown to LLM)
"tool_telemetry": dict # Optional: Telemetry data
}
Tool handlers receive two arguments:
args (dict) - The tool arguments passed by the LLMinvocation (ToolInvocation) - Metadata about the invocation
invocation.session_id - Session IDinvocation.tool_call_id - Tool call IDinvocation.tool_name - Tool nameinvocation.arguments - Same as args parameterWhen Copilot invokes a tool, the client automatically:
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"model": "gpt-5",
"system_message": {
"mode": "append",
"content": """
<workflow_rules>
- Always check for security vulnerabilities
- Suggest performance improvements when applicable
</workflow_rules>
"""
}
})
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"model": "gpt-5",
"system_message": {
"mode": "replace",
"content": "You are a helpful assistant."
}
})
Attach files to messages:
await session.send({
"prompt": "Analyze this file",
"attachments": [
{
"type": "file",
"path": "/path/to/file.py",
"display_name": "My File"
}
]
})
Use the mode key in message options:
"enqueue" - Queue message for processing"immediate" - Process message immediatelyawait session.send({
"prompt": "...",
"mode": "enqueue"
})
Sessions are independent and can run concurrently:
session1 = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"model": "gpt-5",
})
session2 = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"model": "claude-sonnet-4.5",
})
await asyncio.gather(
session1.send({"prompt": "Hello from session 1"}),
session2.send({"prompt": "Hello from session 2"})
)
Use custom API providers via provider:
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"provider": {
"type": "openai",
"base_url": "https://api.openai.com/v1",
"api_key": "your-api-key"
}
})
sessions = await client.list_sessions()
for metadata in sessions:
print(f"{metadata.session_id}: {metadata.summary}")
await client.delete_session(session_id)
last_id = await client.get_last_session_id()
if last_id:
session = await client.resume_session(last_id, on_permission_request=PermissionHandler.approve_all)
state = client.get_state()
# Returns: "disconnected" | "connecting" | "connected" | "error"
try:
session = await client.create_session(on_permission_request=PermissionHandler.approve_all)
await session.send({"prompt": "Hello"})
except Exception as e:
print(f"Error: {e}")
Monitor session.error event type for runtime errors:
def handler(event):
if event.type == "session.error":
print(f"Session Error: {event.data.message}")
session.on(handler)
Use ping to verify server connectivity:
response = await client.ping("health check")
print(f"Server responded at {response['timestamp']}")
ALWAYS use async context managers for automatic cleanup:
async with CopilotClient() as client:
async with await client.create_session(on_permission_request=PermissionHandler.approve_all) as session:
# Use session...
await session.send({"prompt": "Hello"})
# Session automatically destroyed
# Client automatically stopped
client = CopilotClient()
try:
await client.start()
session = await client.create_session(on_permission_request=PermissionHandler.approve_all)
try:
# Use session...
pass
finally:
await session.destroy()
finally:
await client.stop()
async with) for automatic cleanupfrom copilot import CopilotClient, PermissionHandler
import asyncio
async def main():
async with CopilotClient() as client:
async with await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"model": "gpt-5",
}) as session:
done = asyncio.Event()
def handler(event):
if event.type == "assistant.message":
print(event.data.content)
elif event.type == "session.idle":
done.set()
session.on(handler)
await session.send({"prompt": "What is 2+2?"})
await done.wait()
asyncio.run(main())
async def send_and_wait(session, prompt: str):
done = asyncio.Event()
result = []
def handler(event):
if event.type == "assistant.message":
result.append(event.data.content)
print(event.data.content)
elif event.type == "session.idle":
done.set()
elif event.type == "session.error":
result.append(None)
done.set()
unsubscribe = session.on(handler)
await session.send({"prompt": prompt})
await done.wait()
unsubscribe()
return result[0] if result else None
async with await client.create_session(on_permission_request=PermissionHandler.approve_all) as session:
await send_and_wait(session, "What is the capital of France?")
await send_and_wait(session, "What is its population?")
# Use built-in send_and_wait for simpler synchronous interaction
async with await client.create_session(on_permission_request=PermissionHandler.approve_all) as session:
response = await session.send_and_wait(
{"prompt": "What is 2+2?"},
timeout=60.0
)
if response and response.type == "assistant.message":
print(response.data.content)
from dataclasses import dataclass, asdict
from copilot import define_tool
@dataclass
class UserInfo:
id: str
name: str
email: str
role: str
async def get_user(args, inv) -> dict:
user = UserInfo(
id=args["user_id"],
name="John Doe",
email="[email protected]",
role="Developer"
)
return asdict(user)
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"tools": [
define_tool(
name="get_user",
description="Retrieve user information",
parameters={
"type": "object",
"properties": {
"user_id": {"type": "string", "description": "User ID"}
},
"required": ["user_id"]
},
handler=get_user
)
]
})
import asyncio
current_message = []
done = asyncio.Event()
def handler(event):
if event.type == "assistant.message.delta":
current_message.append(event.data.delta_content)
print(event.data.delta_content, end="", flush=True)
elif event.type == "assistant.message":
print(f"\n\n=== Complete ===")
print(f"Total length: {len(event.data.content)} chars")
elif event.type == "session.idle":
done.set()
unsubscribe = session.on(handler)
await session.send({"prompt": "Write a long story"})
await done.wait()
unsubscribe()
def handler(event):
if event.type == "session.error":
print(f"Session error: {event.data.message}")
# Optionally retry or handle error
session.on(handler)
try:
await session.send({"prompt": "risky operation"})
except Exception as e:
# Handle send errors
print(f"Failed to send: {e}")
from typing import TypedDict, List
class MessageOptions(TypedDict, total=False):
prompt: str
attachments: List[dict]
mode: str
class SessionConfig(TypedDict, total=False):
model: str
streaming: bool
tools: List
# Usage with type hints
options: MessageOptions = {
"prompt": "Hello",
"mode": "enqueue"
}
await session.send(options)
config: SessionConfig = {
"on_permission_request": PermissionHandler.approve_all,
"model": "gpt-5",
"streaming": True
}
session = await client.create_session(config)
from typing import AsyncGenerator
async def stream_response(session, prompt: str) -> AsyncGenerator[str, None]:
"""Stream response chunks as an async generator."""
queue = asyncio.Queue()
done = asyncio.Event()
def handler(event):
if event.type == "assistant.message.delta":
queue.put_nowait(event.data.delta_content)
elif event.type == "session.idle":
done.set()
unsubscribe = session.on(handler)
await session.send({"prompt": prompt})
while not done.is_set():
try:
chunk = await asyncio.wait_for(queue.get(), timeout=0.1)
yield chunk
except asyncio.TimeoutError:
continue
# Drain remaining items
while not queue.empty():
yield queue.get_nowait()
unsubscribe()
# Usage
async for chunk in stream_response(session, "Tell me a story"):
print(chunk, end="", flush=True)
from typing import Callable, Any
from copilot import define_tool
def copilot_tool(
name: str,
description: str,
parameters: dict
) -> Callable:
"""Decorator to convert a function into a Copilot tool."""
def decorator(func: Callable) -> Any:
return define_tool(
name=name,
description=description,
parameters=parameters,
handler=lambda args, inv: func(**args)
)
return decorator
@copilot_tool(
name="calculate",
description="Perform a calculation",
parameters={
"type": "object",
"properties": {
"expression": {"type": "string", "description": "Math expression"}
},
"required": ["expression"]
}
)
def calculate(expression: str) -> float:
return eval(expression)
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"tools": [calculate]})
The SDK implements __aenter__ and __aexit__:
class CopilotClient:
async def __aenter__(self):
await self.start()
return self
async def __aexit__(self, exc_type, exc_val, exc_tb):
await self.stop()
return False
class CopilotSession:
async def __aenter__(self):
return self
async def __aexit__(self, exc_type, exc_val, exc_tb):
await self.destroy()
return False
Event data is available as attributes:
def handler(event):
# Access event attributes directly
print(event.type)
print(event.data.content) # For assistant.message
print(event.data.delta_content) # For assistant.message.delta
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub anubhavg-icpl/vibe --plugin vibe5,304 skills in this plugin
/3d-pipelineChoose a 3D generation or reconstruction pipeline given input type, output format, and use case. Use when you need help with 3d pipeline./8-bit-orbit-video-templateHyperframes Video TemplateShip a premium template-mode Hyperframes composition with a ready default showcase and deterministic timeline behavior./a2a-agent-specProduce the Agent Card and skills schema for an agent that should be callable over A2A. Use when you need help with a2a agent spec.Other plugins' skills for the same job