{"id":"c526ad9e-bf58-4920-baec-2c6176f039e1","shortId":"tnmxyQ","kind":"skill","title":"Copilot Sdk","tagline":"Awesome Copilot skill by Github","description":"# GitHub Copilot SDK\n\nEmbed Copilot's agentic workflows in any application using Python, TypeScript, Go, or .NET.\n\n## Overview\n\nThe GitHub Copilot SDK exposes the same engine behind Copilot CLI: a production-tested agent runtime you can invoke programmatically. No need to build your own orchestration - you define agent behavior, Copilot handles planning, tool invocation, file edits, and more.\n\n## Prerequisites\n\n1. **GitHub Copilot CLI** installed and authenticated ([Installation guide](https://docs.github.com/en/copilot/how-tos/set-up/install-copilot-cli))\n2. **Language runtime**: Node.js 18+, Python 3.8+, Go 1.21+, or .NET 8.0+\n\nVerify CLI: `copilot --version`\n\n## Installation\n\n### Node.js/TypeScript\n```bash\nmkdir copilot-demo && cd copilot-demo\nnpm init -y --init-type module\nnpm install @github/copilot-sdk tsx\n```\n\n### Python\n```bash\npip install github-copilot-sdk\n```\n\n### Go\n```bash\nmkdir copilot-demo && cd copilot-demo\ngo mod init copilot-demo\ngo get github.com/github/copilot-sdk/go\n```\n\n### .NET\n```bash\ndotnet new console -n CopilotDemo && cd CopilotDemo\ndotnet add package GitHub.Copilot.SDK\n```\n\n## Quick Start\n\n### TypeScript\n```typescript\nimport { CopilotClient, approveAll } from \"@github/copilot-sdk\";\n\nconst client = new CopilotClient();\nconst session = await client.createSession({\n    onPermissionRequest: approveAll,\n    model: \"gpt-4.1\",\n});\n\nconst response = await session.sendAndWait({ prompt: \"What is 2 + 2?\" });\nconsole.log(response?.data.content);\n\nawait client.stop();\nprocess.exit(0);\n```\n\nRun: `npx tsx index.ts`\n\n### Python\n```python\nimport asyncio\nfrom copilot import CopilotClient, PermissionHandler\n\nasync def main():\n    client = CopilotClient()\n    await client.start()\n\n    session = await client.create_session({\n        \"on_permission_request\": PermissionHandler.approve_all,\n        \"model\": \"gpt-4.1\",\n    })\n    response = await session.send_and_wait({\"prompt\": \"What is 2 + 2?\"})\n\n    print(response.data.content)\n    await client.stop()\n\nasyncio.run(main())\n```\n\n### Go\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n    \"os\"\n    copilot \"github.com/github/copilot-sdk/go\"\n)\n\nfunc main() {\n    client := copilot.NewClient(nil)\n    if err := client.Start(); err != nil {\n        log.Fatal(err)\n    }\n    defer client.Stop()\n\n    session, err := client.CreateSession(&copilot.SessionConfig{\n        OnPermissionRequest: copilot.PermissionHandler.ApproveAll,\n        Model:               \"gpt-4.1\",\n    })\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    response, err := session.SendAndWait(copilot.MessageOptions{Prompt: \"What is 2 + 2?\"}, 0)\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    fmt.Println(*response.Data.Content)\n    os.Exit(0)\n}\n```\n\n### .NET (C#)\n```csharp\nusing GitHub.Copilot.SDK;\n\nawait using var client = new CopilotClient();\nawait using var session = await client.CreateSessionAsync(new SessionConfig\n{\n    OnPermissionRequest = PermissionHandler.ApproveAll,\n    Model = \"gpt-4.1\",\n});\n\nvar response = await session.SendAndWaitAsync(new MessageOptions { Prompt = \"What is 2 + 2?\" });\nConsole.WriteLine(response?.Data.Content);\n```\n\nRun: `dotnet run`\n\n## Streaming Responses\n\nEnable real-time output for better UX:\n\n### TypeScript\n```typescript\nimport { CopilotClient, approveAll, SessionEvent } from \"@github/copilot-sdk\";\n\nconst client = new CopilotClient();\nconst session = await client.createSession({\n    onPermissionRequest: approveAll,\n    model: \"gpt-4.1\",\n    streaming: true,\n});\n\nsession.on((event: SessionEvent) => {\n    if (event.type === \"assistant.message_delta\") {\n        process.stdout.write(event.data.deltaContent);\n    }\n    if (event.type === \"session.idle\") {\n        console.log(); // New line when done\n    }\n});\n\nawait session.sendAndWait({ prompt: \"Tell me a short joke\" });\n\nawait client.stop();\nprocess.exit(0);\n```\n\n### Python\n```python\nimport asyncio\nimport sys\nfrom copilot import CopilotClient, PermissionHandler\nfrom copilot.generated.session_events import SessionEventType\n\nasync def main():\n    client = CopilotClient()\n    await client.start()\n\n    session = await client.create_session({\n        \"on_permission_request\": PermissionHandler.approve_all,\n        \"model\": \"gpt-4.1\",\n        \"streaming\": True,\n    })\n\n    def handle_event(event):\n        if event.type == SessionEventType.ASSISTANT_MESSAGE_DELTA:\n            sys.stdout.write(event.data.delta_content)\n            sys.stdout.flush()\n        if event.type == SessionEventType.SESSION_IDLE:\n            print()\n\n    session.on(handle_event)\n    await session.send_and_wait({\"prompt\": \"Tell me a short joke\"})\n    await client.stop()\n\nasyncio.run(main())\n```\n\n### Go\n```go\nsession, err := client.CreateSession(&copilot.SessionConfig{\n\tOnPermissionRequest: copilot.PermissionHandler.ApproveAll,\n    Model:     \"gpt-4.1\",\n    Streaming: true,\n})\n\nsession.On(func(event copilot.SessionEvent) {\n    if event.Type == \"assistant.message_delta\" {\n        fmt.Print(*event.Data.DeltaContent)\n    }\n    if event.Type == \"session.idle\" {\n        fmt.Println()\n    }\n})\n\n_, err = session.SendAndWait(copilot.MessageOptions{Prompt: \"Tell me a short joke\"}, 0)\n```\n\n### .NET\n```csharp\nawait using var session = await client.CreateSessionAsync(new SessionConfig\n{\n    OnPermissionRequest = PermissionHandler.ApproveAll,\n    Model = \"gpt-4.1\",\n    Streaming = true,\n});\n\nsession.On(ev =>\n{\n    if (ev is AssistantMessageDeltaEvent deltaEvent)\n        Console.Write(deltaEvent.Data.DeltaContent);\n    if (ev is SessionIdleEvent)\n        Console.WriteLine();\n});\n\nawait session.SendAndWaitAsync(new MessageOptions { Prompt = \"Tell me a short joke\" });\n```\n\n## Custom Tools\n\nDefine tools that Copilot can invoke during reasoning. When you define a tool, you tell Copilot:\n1. **What the tool does** (description)\n2. **What parameters it needs** (schema)\n3. **What code to run** (handler)\n\n### TypeScript (JSON Schema)\n```typescript\nimport { CopilotClient, approveAll, defineTool, SessionEvent } from \"@github/copilot-sdk\";\n\nconst getWeather = defineTool(\"get_weather\", {\n    description: \"Get the current weather for a city\",\n    parameters: {\n        type: \"object\",\n        properties: {\n            city: { type: \"string\", description: \"The city name\" },\n        },\n        required: [\"city\"],\n    },\n    handler: async (args: { city: string }) => {\n        const { city } = args;\n        // In a real app, call a weather API here\n        const conditions = [\"sunny\", \"cloudy\", \"rainy\", \"partly cloudy\"];\n        const temp = Math.floor(Math.random() * 30) + 50;\n        const condition = conditions[Math.floor(Math.random() * conditions.length)];\n        return { city, temperature: `${temp}°F`, condition };\n    },\n});\n\nconst client = new CopilotClient();\nconst session = await client.createSession({\n    onPermissionRequest: approveAll,\n    model: \"gpt-4.1\",\n    streaming: true,\n    tools: [getWeather],\n});\n\nsession.on((event: SessionEvent) => {\n    if (event.type === \"assistant.message_delta\") {\n        process.stdout.write(event.data.deltaContent);\n    }\n});\n\nawait session.sendAndWait({\n    prompt: \"What's the weather like in Seattle and Tokyo?\",\n});\n\nawait client.stop();\nprocess.exit(0);\n```\n\n### Python (Pydantic)\n```python\nimport asyncio\nimport random\nimport sys\nfrom copilot import CopilotClient, PermissionHandler\nfrom copilot.tools import define_tool\nfrom copilot.generated.session_events import SessionEventType\nfrom pydantic import BaseModel, Field\n\nclass GetWeatherParams(BaseModel):\n    city: str = Field(description=\"The name of the city to get weather for\")\n\n@define_tool(description=\"Get the current weather for a city\")\nasync def get_weather(params: GetWeatherParams) -> dict:\n    city = params.city\n    conditions = [\"sunny\", \"cloudy\", \"rainy\", \"partly cloudy\"]\n    temp = random.randint(50, 80)\n    condition = random.choice(conditions)\n    return {\"city\": city, \"temperature\": f\"{temp}°F\", \"condition\": condition}\n\nasync def main():\n    client = CopilotClient()\n    await client.start()\n\n    session = await client.create_session({\n        \"on_permission_request\": PermissionHandler.approve_all,\n        \"model\": \"gpt-4.1\",\n        \"streaming\": True,\n        \"tools\": [get_weather],\n    })\n\n    def handle_event(event):\n        if event.type == SessionEventType.ASSISTANT_MESSAGE_DELTA:\n            sys.stdout.write(event.data.delta_content)\n            sys.stdout.flush()\n\n    session.on(handle_event)\n\n    await session.send_and_wait({\n        \"prompt\": \"What's the weather like in Seattle and Tokyo?\"\n    })\n\n    await client.stop()\n\nasyncio.run(main())\n```\n\n### Go\n```go\ntype WeatherParams struct {\n    City string `json:\"city\" jsonschema:\"The city name\"`\n}\n\ntype WeatherResult struct {\n    City        string `json:\"city\"`\n    Temperature string `json:\"temperature\"`\n    Condition   string `json:\"condition\"`\n}\n\ngetWeather := copilot.DefineTool(\n    \"get_weather\",\n    \"Get the current weather for a city\",\n    func(params WeatherParams, inv copilot.ToolInvocation) (WeatherResult, error) {\n        conditions := []string{\"sunny\", \"cloudy\", \"rainy\", \"partly cloudy\"}\n        temp := rand.Intn(30) + 50\n        condition := conditions[rand.Intn(len(conditions))]\n        return WeatherResult{\n            City:        params.City,\n            Temperature: fmt.Sprintf(\"%d°F\", temp),\n            Condition:   condition,\n        }, nil\n    },\n)\n\nsession, _ := client.CreateSession(&copilot.SessionConfig{\n\tOnPermissionRequest: copilot.PermissionHandler.ApproveAll,\n    Model:     \"gpt-4.1\",\n    Streaming: true,\n    Tools:     []copilot.Tool{getWeather},\n})\n```\n\n### .NET (Microsoft.Extensions.AI)\n```csharp\nusing GitHub.Copilot.SDK;\nusing Microsoft.Extensions.AI;\nusing System.ComponentModel;\n\nvar getWeather = AIFunctionFactory.Create(\n    ([Description(\"The city name\")] string city) =>\n    {\n        var conditions = new[] { \"sunny\", \"cloudy\", \"rainy\", \"partly cloudy\" };\n        var temp = Random.Shared.Next(50, 80);\n        var condition = conditions[Random.Shared.Next(conditions.Length)];\n        return new { city, temperature = $\"{temp}°F\", condition };\n    },\n    \"get_weather\",\n    \"Get the current weather for a city\"\n);\n\nawait using var session = await client.CreateSessionAsync(new SessionConfig\n{\n    OnPermissionRequest = PermissionHandler.ApproveAll,\n    Model = \"gpt-4.1\",\n    Streaming = true,\n    Tools = [getWeather],\n});\n```\n\n## How Tools Work\n\nWhen Copilot decides to call your tool:\n1. Copilot sends a tool call request with the parameters\n2. The SDK runs your handler function\n3. The result is sent back to Copilot\n4. Copilot incorporates the result into its response\n\nCopilot decides when to call your tool based on the user's question and your tool's description.\n\n## Interactive CLI Assistant\n\nBuild a complete interactive assistant:\n\n### TypeScript\n```typescript\nimport { CopilotClient, approveAll, defineTool, SessionEvent } from \"@github/copilot-sdk\";\nimport * as readline from \"readline\";\n\nconst getWeather = defineTool(\"get_weather\", {\n    description: \"Get the current weather for a city\",\n    parameters: {\n        type: \"object\",\n        properties: {\n            city: { type: \"string\", description: \"The city name\" },\n        },\n        required: [\"city\"],\n    },\n    handler: async ({ city }) => {\n        const conditions = [\"sunny\", \"cloudy\", \"rainy\", \"partly cloudy\"];\n        const temp = Math.floor(Math.random() * 30) + 50;\n        const condition = conditions[Math.floor(Math.random() * conditions.length)];\n        return { city, temperature: `${temp}°F`, condition };\n    },\n});\n\nconst client = new CopilotClient();\nconst session = await client.createSession({\n    onPermissionRequest: approveAll,\n    model: \"gpt-4.1\",\n    streaming: true,\n    tools: [getWeather],\n});\n\nsession.on((event: SessionEvent) => {\n    if (event.type === \"assistant.message_delta\") {\n        process.stdout.write(event.data.deltaContent);\n    }\n});\n\nconst rl = readline.createInterface({\n    input: process.stdin,\n    output: process.stdout,\n});\n\nconsole.log(\"Weather Assistant (type 'exit' to quit)\");\nconsole.log(\"Try: 'What's the weather in Paris?'\\n\");\n\nconst prompt = () => {\n    rl.question(\"You: \", async (input) => {\n        if (input.toLowerCase() === \"exit\") {\n            await client.stop();\n            rl.close();\n            return;\n        }\n\n        process.stdout.write(\"Assistant: \");\n        await session.sendAndWait({ prompt: input });\n        console.log(\"\\n\");\n        prompt();\n    });\n};\n\nprompt();\n```\n\n### Python\n```python\nimport asyncio\nimport random\nimport sys\nfrom copilot import CopilotClient, PermissionHandler\nfrom copilot.tools import define_tool\nfrom copilot.generated.session_events import SessionEventType\nfrom pydantic import BaseModel, Field\n\nclass GetWeatherParams(BaseModel):\n    city: str = Field(description=\"The name of the city to get weather for\")\n\n@define_tool(description=\"Get the current weather for a city\")\nasync def get_weather(params: GetWeatherParams) -> dict:\n    conditions = [\"sunny\", \"cloudy\", \"rainy\", \"partly cloudy\"]\n    temp = random.randint(50, 80)\n    condition = random.choice(conditions)\n    return {\"city\": params.city, \"temperature\": f\"{temp}°F\", \"condition\": condition}\n\nasync def main():\n    client = CopilotClient()\n    await client.start()\n\n    session = await client.create_session({\n        \"on_permission_request\": PermissionHandler.approve_all,\n        \"model\": \"gpt-4.1\",\n        \"streaming\": True,\n        \"tools\": [get_weather],\n    })\n\n    def handle_event(event):\n        if event.type == SessionEventType.ASSISTANT_MESSAGE_DELTA:\n            sys.stdout.write(event.data.delta_content)\n            sys.stdout.flush()\n\n    session.on(handle_event)\n\n    print(\"Weather Assistant (type 'exit' to quit)\")\n    print(\"Try: 'What's the weather in Paris?'\\n\")\n\n    while True:\n        try:\n            user_input = input(\"You: \")\n        except EOFError:\n            break\n\n        if user_input.lower() == \"exit\":\n            break\n\n        sys.stdout.write(\"Assistant: \")\n        await session.send_and_wait({\"prompt\": user_input})\n        print(\"\\n\")\n\n    await client.stop()\n\nasyncio.run(main())\n```\n\n## MCP Server Integration\n\nConnect to MCP (Model Context Protocol) servers for pre-built tools. Connect to GitHub's MCP server for repository, issue, and PR access:\n\n### TypeScript\n```typescript\nconst session = await client.createSession({\n    onPermissionRequest: approveAll,\n    model: \"gpt-4.1\",\n    mcpServers: {\n        github: {\n            type: \"http\",\n            url: \"https://api.githubcopilot.com/mcp/\",\n        },\n    },\n});\n```\n\n### Python\n```python\nsession = await client.create_session({\n    \"on_permission_request\": PermissionHandler.approve_all,\n    \"model\": \"gpt-4.1\",\n    \"mcp_servers\": {\n        \"github\": {\n            \"type\": \"http\",\n            \"url\": \"https://api.githubcopilot.com/mcp/\",\n        },\n    },\n})\n```\n\n### Go\n```go\nsession, _ := client.CreateSession(&copilot.SessionConfig{\n\tOnPermissionRequest: copilot.PermissionHandler.ApproveAll,\n    Model: \"gpt-4.1\",\n    MCPServers: map[string]copilot.MCPServerConfig{\n        \"github\": {\n            \"type\": \"http\",\n            \"url\": \"https://api.githubcopilot.com/mcp/\",\n        },\n    },\n})\n```\n\n### .NET\n```csharp\nawait using var session = await client.CreateSessionAsync(new SessionConfig\n{\n    OnPermissionRequest = PermissionHandler.ApproveAll,\n    Model = \"gpt-4.1\",\n    McpServers = new Dictionary<string, McpServerConfig>\n    {\n        [\"github\"] = new McpServerConfig\n        {\n            Type = \"http\",\n            Url = \"https://api.githubcopilot.com/mcp/\",\n        },\n    },\n});\n```\n\n## Custom Agents\n\nDefine specialized AI personas for specific tasks:\n\n### TypeScript\n```typescript\nconst session = await client.createSession({\n    onPermissionRequest: approveAll,\n    model: \"gpt-4.1\",\n    customAgents: [{\n        name: \"pr-reviewer\",\n        displayName: \"PR Reviewer\",\n        description: \"Reviews pull requests for best practices\",\n        prompt: \"You are an expert code reviewer. Focus on security, performance, and maintainability.\",\n    }],\n});\n```\n\n### Python\n```python\nsession = await client.create_session({\n    \"on_permission_request\": PermissionHandler.approve_all,\n    \"model\": \"gpt-4.1\",\n    \"custom_agents\": [{\n        \"name\": \"pr-reviewer\",\n        \"display_name\": \"PR Reviewer\",\n        \"description\": \"Reviews pull requests for best practices\",\n        \"prompt\": \"You are an expert code reviewer. Focus on security, performance, and maintainability.\",\n    }],\n})\n```\n\n## System Message\n\nCustomize the AI's behavior and personality:\n\n### TypeScript\n```typescript\nconst session = await client.createSession({\n    onPermissionRequest: approveAll,\n    model: \"gpt-4.1\",\n    systemMessage: {\n        content: \"You are a helpful assistant for our engineering team. Always be concise.\",\n    },\n});\n```\n\n### Python\n```python\nsession = await client.create_session({\n    \"on_permission_request\": PermissionHandler.approve_all,\n    \"model\": \"gpt-4.1\",\n    \"system_message\": {\n        \"content\": \"You are a helpful assistant for our engineering team. Always be concise.\",\n    },\n})\n```\n\n## External CLI Server\n\nRun the CLI in server mode separately and connect the SDK to it. Useful for debugging, resource sharing, or custom environments.\n\n### Start CLI in Server Mode\n```bash\ncopilot --server --port 4321\n```\n\n### Connect SDK to External Server\n\n#### TypeScript\n```typescript\nconst client = new CopilotClient({\n    cliUrl: \"localhost:4321\"\n});\n\nconst session = await client.createSession({\n    onPermissionRequest: approveAll,\n    model: \"gpt-4.1\",\n});\n```\n\n#### Python\n```python\nclient = CopilotClient({\n    \"cli_url\": \"localhost:4321\"\n})\nawait client.start()\n\nsession = await client.create_session({\n    \"on_permission_request\": PermissionHandler.approve_all,\n    \"model\": \"gpt-4.1\",\n})\n```\n\n#### Go\n```go\nclient := copilot.NewClient(&copilot.ClientOptions{\n    CLIUrl: \"localhost:4321\",\n})\n\nif err := client.Start(); err != nil {\n    log.Fatal(err)\n}\n\nsession, _ := client.CreateSession(&copilot.SessionConfig{\n\tOnPermissionRequest: copilot.PermissionHandler.ApproveAll,\n\tModel:               \"gpt-4.1\",\n})\n```\n\n#### .NET\n```csharp\nusing var client = new CopilotClient(new CopilotClientOptions\n{\n    CliUrl = \"localhost:4321\"\n});\n\nawait using var session = await client.CreateSessionAsync(new SessionConfig\n{\n    OnPermissionRequest = PermissionHandler.ApproveAll,\n    Model = \"gpt-4.1\",\n});\n```\n\n**Note:** When `cliUrl` is provided, the SDK will not spawn or manage a CLI process - it only connects to the existing server.\n\n## Event Types\n\n| Event | Description |\n|-------|-------------|\n| `user.message` | User input added |\n| `assistant.message` | Complete model response |\n| `assistant.message_delta` | Streaming response chunk |\n| `assistant.reasoning` | Model reasoning (model-dependent) |\n| `assistant.reasoning_delta` | Streaming reasoning chunk |\n| `tool.execution_start` | Tool invocation started |\n| `tool.execution_complete` | Tool execution finished |\n| `session.idle` | No active processing |\n| `session.error` | Error occurred |\n\n## Client Configuration\n\n| Option | Description | Default |\n|--------|-------------|---------|\n| `cliPath` | Path to Copilot CLI executable | System PATH |\n| `cliUrl` | Connect to existing server (e.g., \"localhost:4321\") | None |\n| `port` | Server communication port | Random |\n| `useStdio` | Use stdio transport instead of TCP | true |\n| `logLevel` | Logging verbosity | \"info\" |\n| `autoStart` | Launch server automatically | true |\n| `autoRestart` | Restart on crashes | true |\n| `cwd` | Working directory for CLI process | Inherited |\n\n## Session Configuration\n\n| Option | Description |\n|--------|-------------|\n| `model` | LLM to use (\"gpt-4.1\", \"claude-sonnet-4.5\", etc.) |\n| `sessionId` | Custom session identifier |\n| `tools` | Custom tool definitions |\n| `mcpServers` | MCP server connections |\n| `customAgents` | Custom agent personas |\n| `systemMessage` | Override default system prompt |\n| `streaming` | Enable incremental response chunks |\n| `availableTools` | Whitelist of permitted tools |\n| `excludedTools` | Blacklist of disabled tools |\n\n## Session Persistence\n\nSave and resume conversations across restarts:\n\n### Create with Custom ID\n```typescript\nconst session = await client.createSession({\n    onPermissionRequest: approveAll,\n    sessionId: \"user-123-conversation\",\n    model: \"gpt-4.1\"\n});\n```\n\n### Resume Session\n```typescript\nconst session = await client.resumeSession(\"user-123-conversation\", { onPermissionRequest: approveAll });\nawait session.send({ prompt: \"What did we discuss earlier?\" });\n```\n\n### List and Delete Sessions\n```typescript\nconst sessions = await client.listSessions();\nawait client.deleteSession(\"old-session-id\");\n```\n\n## Error Handling\n\n```typescript\ntry {\n    const client = new CopilotClient();\n    const session = await client.createSession({\n        onPermissionRequest: approveAll,\n        model: \"gpt-4.1\",\n    });\n    const response = await session.sendAndWait(\n        { prompt: \"Hello!\" },\n        30000 // timeout in ms\n    );\n} catch (error) {\n    if (error.code === \"ENOENT\") {\n        console.error(\"Copilot CLI not installed\");\n    } else if (error.code === \"ECONNREFUSED\") {\n        console.error(\"Cannot connect to Copilot server\");\n    } else {\n        console.error(\"Error:\", error.message);\n    }\n} finally {\n    await client.stop();\n}\n```\n\n## Graceful Shutdown\n\n```typescript\nprocess.on(\"SIGINT\", async () => {\n    console.log(\"Shutting down...\");\n    await client.stop();\n    process.exit(0);\n});\n```\n\n## Common Patterns\n\n### Multi-turn Conversation\n```typescript\nconst session = await client.createSession({\n    onPermissionRequest: approveAll,\n    model: \"gpt-4.1\",\n});\n\nawait session.sendAndWait({ prompt: \"My name is Alice\" });\nawait session.sendAndWait({ prompt: \"What's my name?\" });\n// Response: \"Your name is Alice\"\n```\n\n### File Attachments\n```typescript\nawait session.send({\n    prompt: \"Analyze this file\",\n    attachments: [{\n        type: \"file\",\n        path: \"./data.csv\",\n        displayName: \"Sales Data\"\n    }]\n});\n```\n\n### Abort Long Operations\n```typescript\nconst timeoutId = setTimeout(() => {\n    session.abort();\n}, 60000);\n\nsession.on((event) => {\n    if (event.type === \"session.idle\") {\n        clearTimeout(timeoutId);\n    }\n});\n```\n\n## Available Models\n\nQuery available models at runtime:\n\n```typescript\nconst models = await client.getModels();\n// Returns: [\"gpt-4.1\", \"gpt-4o\", \"claude-sonnet-4.5\", ...]\n```\n\n## Best Practices\n\n1. **Always cleanup**: Use `try-finally` or `defer` to ensure `client.stop()` is called\n2. **Set timeouts**: Use `sendAndWait` with timeout for long operations\n3. **Handle events**: Subscribe to error events for robust error handling\n4. **Use streaming**: Enable streaming for better UX on long responses\n5. **Persist sessions**: Use custom session IDs for multi-turn conversations\n6. **Define clear tools**: Write descriptive tool names and descriptions\n\n## Architecture\n\n```\nYour Application\n       |\n  SDK Client\n       | JSON-RPC\n  Copilot CLI (server mode)\n       |\n  GitHub (models, auth)\n```\n\nThe SDK manages the CLI process lifecycle automatically. All communication happens via JSON-RPC over stdio or TCP.\n\n## Resources\n\n- **GitHub Repository**: https://github.com/github/copilot-sdk\n- **Getting Started Tutorial**: https://github.com/github/copilot-sdk/blob/main/docs/tutorials/first-app.md\n- **GitHub MCP Server**: https://github.com/github/github-mcp-server\n- **MCP Servers Directory**: https://github.com/modelcontextprotocol/servers\n- **Cookbook**: https://github.com/github/copilot-sdk/tree/main/cookbook\n- **Samples**: https://github.com/github/copilot-sdk/tree/main/samples\n\n## Status\n\nThis SDK is in **Technical Preview** and may have breaking changes. Not recommended for production use yet.","tags":["copilot","sdk","awesome","github"],"capabilities":["skill","source-github","category-awesome-copilot"],"categories":["awesome-copilot"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/github/awesome-copilot/copilot-sdk","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"install_from":"skills.sh"}},"qualityScore":"0.300","qualityRationale":"deterministic score 0.30 from registry signals: · indexed on skills.sh · published under github/awesome-copilot","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill:v1","enrichmentVersion":1,"enrichedAt":"2026-04-22T16:40:17.412Z","embedding":null,"createdAt":"2026-04-18T20:25:38.433Z","updatedAt":"2026-04-22T16:40:17.412Z","lastSeenAt":"2026-04-22T16:40:17.412Z","tsv":"'-123':1990,2003 '-4.1':183,231,282,330,378,444,492,533,687,821,942,1012,1166,1327,1431,1453,1472,1498,1532,1574,1624,1652,1724,1746,1769,1794,1927,1994,2046,2112,2179 '/data.csv':2145 '/en/copilot/how-tos/set-up/install-copilot-cli))':79 '/github/copilot-sdk':2296 '/github/copilot-sdk/blob/main/docs/tutorials/first-app.md':2302 '/github/copilot-sdk/go':148,259 '/github/copilot-sdk/tree/main/cookbook':2318 '/github/copilot-sdk/tree/main/samples':2322 '/github/github-mcp-server':2308 '/mcp/':1439,1462,1483,1512 '/modelcontextprotocol/servers':2314 '/typescript':99 '0':199,297,306,409,518,716,2096 '1':68,578,1027,2189 '1.21':88 '18':84 '2':80,191,192,240,241,295,296,340,341,584,1037,2203 '3':590,1044,2213 '3.8':86 '30':661,916,1140 '30000':2053 '4':1052,2224 '4.5':1931,2186 '4321':1701,1715,1732,1754,1781,1882 '4o':2182 '5':2235 '50':662,789,917,977,1141,1295 '6':2247 '60000':2157 '8.0':91 '80':790,978,1296 'abort':2149 'access':1420 'across':1975 'activ':1857 'ad':1824 'add':159 'agent':14,41,56,1514,1576,1947 'ai':1517,1609 'aifunctionfactory.create':959 'alic':2119,2131 'alway':1636,1665,2190 'analyz':2138 'api':648 'api.githubcopilot.com':1438,1461,1482,1511 'api.githubcopilot.com/mcp/':1437,1460,1481,1510 'app':644 'applic':18,2259 'approveal':168,180,362,375,602,684,1090,1163,1428,1529,1621,1721,1987,2006,2043,2109 'architectur':2257 'arg':635,640 'assist':1080,1085,1189,1217,1351,1380,1631,1660 'assistant.message':386,501,697,1176,1825,1829 'assistant.reasoning':1834,1840 'assistantmessagedeltaev':541 'async':213,426,634,772,803,1127,1207,1280,1309,2089 'asyncio':207,413,721,1229 'asyncio.run':246,480,859,1392 'attach':2133,2141 'auth':2271 'authent':74 'automat':1904,2279 'autorestart':1906 'autostart':1901 'avail':2165,2168 'availabletool':1959 'await':177,186,196,218,221,233,244,312,318,322,333,372,398,406,431,434,468,478,521,525,550,681,701,713,808,811,843,857,1000,1004,1160,1212,1218,1314,1317,1381,1390,1425,1443,1486,1490,1526,1564,1618,1642,1718,1733,1736,1782,1786,1984,2000,2007,2022,2024,2040,2049,2082,2093,2106,2113,2120,2135,2175 'awesom':3 'back':1049 'base':1067 'basemodel':744,748,1252,1256 'bash':100,121,129,150,1697 'behavior':57,1611 'behind':34 'best':1546,1590,2187 'better':356,2230 'blacklist':1965 'break':1374,1378,2333 'build':50,1081 'built':1407 'c':308 'call':645,1024,1032,1064,2202 'cannot':2072 'catch':2057 'category-awesome-copilot' 'cd':105,134,156 'chang':2334 'chunk':1833,1844,1958 'citi':619,624,629,632,636,639,670,749,757,771,779,795,796,866,869,872,877,880,899,925,962,965,986,999,1112,1117,1122,1125,1128,1149,1257,1265,1279,1301 'class':746,1254 'claud':1929,2184 'claude-sonnet':1928,2183 'cleanup':2191 'clear':2249 'cleartimeout':2163 'cli':36,71,93,1079,1669,1673,1693,1729,1808,1871,1915,2064,2266,2276 'client':172,216,262,315,367,429,676,806,1155,1312,1710,1727,1749,1774,1862,2035,2261 'client.create':222,435,812,1318,1444,1565,1643,1737 'client.createsession':178,276,373,486,682,936,1161,1426,1466,1527,1619,1719,1763,1985,2041,2107 'client.createsessionasync':323,526,1005,1491,1787 'client.deletesession':2025 'client.getmodels':2176 'client.listsessions':2023 'client.resumesession':2001 'client.start':219,267,432,809,1315,1734,1757 'client.stop':197,245,273,407,479,714,858,1213,1391,2083,2094,2200 'clipath':1867 'cliurl':1713,1752,1779,1797,1875 'cloudi':653,656,783,786,910,913,970,973,1132,1135,1289,1292 'code':592,1553,1597 'common':2097 'communic':1886,2281 'complet':1083,1826,1851 'concis':1638,1667 'condit':651,664,665,674,781,791,793,801,802,885,888,907,918,919,922,932,933,967,980,981,990,1130,1143,1144,1153,1287,1297,1299,1307,1308 'conditions.length':668,983,1147 'configur':1863,1919 'connect':1397,1409,1679,1702,1812,1876,1944,2073 'consol':153 'console.error':2062,2071,2078 'console.log':193,393,1187,1194,1222,2090 'console.write':543 'console.writeline':342,549 'const':171,175,184,366,370,607,638,650,657,663,675,679,1100,1129,1136,1142,1154,1158,1180,1203,1423,1524,1616,1709,1716,1982,1998,2020,2034,2038,2047,2104,2153,2173 'content':458,838,1344,1626,1655 'context':1401 'convers':1974,1991,2004,2102,2246 'cookbook':2315 'copilot':1,4,9,12,28,35,58,70,94,103,107,126,132,136,142,209,256,417,565,577,727,1021,1028,1051,1053,1060,1235,1698,1870,2063,2075,2265 'copilot-demo':102,106,131,135,141 'copilot.clientoptions':1751 'copilot.definetool':890 'copilot.generated.session':422,737,1245 'copilot.mcpserverconfig':1476 'copilot.messageoptions':291,511 'copilot.newclient':263,1750 'copilot.permissionhandler.approveall':279,489,939,1469,1766 'copilot.sessionconfig':277,487,937,1467,1764 'copilot.sessionevent':498 'copilot.tool':946 'copilot.toolinvocation':904 'copilot.tools':732,1240 'copilotcli':167,174,211,217,317,361,369,419,430,601,678,729,807,1089,1157,1237,1313,1712,1728,1776,2037 'copilotclientopt':1778 'copilotdemo':155,157 'crash':1909 'creat':1977 'csharp':309,520,950,1485,1771 'current':615,767,895,995,1108,1275 'custom':560,1513,1575,1607,1690,1934,1938,1946,1979,2239 'customag':1533,1945 'cwd':1911 'd':929 'data':2148 'data.content':195,344 'debug':1686 'decid':1022,1061 'def':214,427,447,773,804,827,1281,1310,1333 'default':1866,1951 'defer':272,2197 'defin':55,562,572,734,762,1242,1270,1515,2248 'definetool':603,609,1091,1102 'definit':1940 'delet':2017 'delta':387,455,502,698,835,1177,1341,1830,1841 'deltaev':542 'deltaevent.data.deltacontent':544 'demo':104,108,133,137,143 'depend':1839 'descript':583,612,627,752,764,960,1077,1105,1120,1260,1272,1541,1585,1820,1865,1921,2252,2256 'dict':778,1286 'dictionari':1501 'directori':1913,2311 'disabl':1967 'discuss':2013 'display':1581 'displaynam':1538,2146 'docs.github.com':78 'docs.github.com/en/copilot/how-tos/set-up/install-copilot-cli))':77 'done':397 'dotnet':151,158,346 'e.g':1880 'earlier':2014 'econnrefus':2070 'edit':64 'els':2067,2077 'emb':11 'enabl':350,1955,2227 'engin':33,1634,1663 'enoent':2061 'ensur':2199 'environ':1691 'eoferror':1373 'err':266,268,271,275,284,287,289,299,302,485,509,1756,1758,1761 'error':906,1860,2030,2058,2079,2218,2222 'error.code':2060,2069 'error.message':2080 'etc':1932 'ev':537,539,546 'event':382,423,449,450,467,497,693,738,829,830,842,1172,1246,1335,1336,1348,1817,1819,2159,2215,2219 'event.data.delta':457,837,1343 'event.data.deltacontent':389,504,700,1179 'event.type':385,391,452,461,500,506,696,832,1175,1338,2161 'except':1372 'excludedtool':1964 'execut':1853,1872 'exist':1815,1878 'exit':1191,1211,1353,1377 'expert':1552,1596 'expos':30 'extern':1668,1705 'f':673,798,800,930,989,1152,1304,1306 'field':745,751,1253,1259 'file':63,2132,2140,2143 'final':2081,2195 'finish':1854 'fmt':253 'fmt.print':503 'fmt.println':303,508 'fmt.sprintf':928 'focus':1555,1599 'func':260,496,900 'function':1043 'get':145,610,613,759,765,774,825,891,893,991,993,1103,1106,1267,1273,1282,1331,2297 'getweath':608,691,889,947,958,1016,1101,1170 'getweatherparam':747,777,1255,1285 'github':7,8,27,69,125,1411,1433,1456,1477,1504,2269,2292,2303 'github-copilot-sdk':124 'github.com':147,258,2295,2301,2307,2313,2317,2321 'github.com/github/copilot-sdk':2294 'github.com/github/copilot-sdk/blob/main/docs/tutorials/first-app.md':2300 'github.com/github/copilot-sdk/go':146,257 'github.com/github/copilot-sdk/tree/main/cookbook':2316 'github.com/github/copilot-sdk/tree/main/samples':2320 'github.com/github/github-mcp-server':2306 'github.com/modelcontextprotocol/servers':2312 'github.copilot.sdk':161,311,952 'github/copilot-sdk':118,170,365,606,1094 'go':22,87,128,138,144,248,249,482,483,861,862,1463,1464,1747,1748 'gpt':182,230,281,329,377,443,491,532,686,820,941,1011,1165,1326,1430,1452,1471,1497,1531,1573,1623,1651,1723,1745,1768,1793,1926,1993,2045,2111,2178,2181 'gpt-4o':2180 'grace':2084 'guid':76 'handl':59,448,466,828,841,1334,1347,2031,2214,2223 'handler':595,633,1042,1126 'happen':2282 'hello':2052 'help':1630,1659 'http':1435,1458,1479,1508 'id':1980,2029,2241 'identifi':1936 'idl':463 'import':166,206,210,252,360,412,414,418,424,600,720,722,724,728,733,739,743,1088,1095,1228,1230,1232,1236,1241,1247,1251 'incorpor':1054 'increment':1956 'index.ts':203 'info':1900 'inherit':1917 'init':110,113,140 'init-typ':112 'input':1183,1208,1221,1369,1370,1387,1823 'input.tolowercase':1210 'instal':72,75,96,117,123,2066 'instead':1893 'integr':1396 'interact':1078,1084 'inv':903 'invoc':62,1848 'invok':45,567 'issu':1417 'joke':405,477,517,559 'json':597,868,879,883,887,2263,2285 'json-rpc':2262,2284 'jsonschema':870 'languag':81 'launch':1902 'len':921 'lifecycl':2278 'like':708,852 'line':395 'list':2015 'llm':1923 'localhost':1714,1731,1753,1780,1881 'log':254,1898 'log.fatal':270,286,301,1760 'loglevel':1897 'long':2150,2211,2233 'main':215,247,251,261,428,481,805,860,1311,1393 'maintain':1560,1604 'manag':1806,2274 'map':1474 'math.floor':659,666,1138,1145 'math.random':660,667,1139,1146 'may':2331 'mcp':1394,1399,1413,1454,1942,2304,2309 'mcpserver':1432,1473,1499,1941 'mcpserverconfig':1503,1506 'messag':454,834,1340,1606,1654 'messageopt':336,553 'microsoft.extensions.ai':949,954 'mkdir':101,130 'mod':139 'mode':1676,1696,2268 'model':181,229,280,328,376,442,490,531,685,819,940,1010,1164,1325,1400,1429,1451,1470,1496,1530,1572,1622,1650,1722,1744,1767,1792,1827,1835,1838,1922,1992,2044,2110,2166,2169,2174,2270 'model-depend':1837 'modul':115 'ms':2056 'multi':2100,2244 'multi-turn':2099,2243 'n':154,1202,1223,1364,1389 'name':630,754,873,963,1123,1262,1534,1577,1582,2117,2126,2129,2254 'need':48,588 'net':24,90,149,307,519,948,1484,1770 'new':152,173,316,324,335,368,394,527,552,677,968,985,1006,1156,1492,1500,1505,1711,1775,1777,1788,2036 'nil':264,269,285,300,934,1759 'node.js':83,98 'node.js/typescript':97 'none':1883 'note':1795 'npm':109,116 'npx':201 'object':622,1115 'occur':1861 'old':2027 'old-session-id':2026 'onpermissionrequest':179,278,326,374,488,529,683,938,1008,1162,1427,1468,1494,1528,1620,1720,1765,1790,1986,2005,2042,2108 'oper':2151,2212 'option':1864,1920 'orchestr':53 'os':255 'os.exit':305 'output':354,1185 'overrid':1950 'overview':25 'packag':160,250 'param':776,901,1284 'paramet':586,620,1036,1113 'params.city':780,926,1302 'pari':1201,1363 'part':655,785,912,972,1134,1291 'path':1868,1874,2144 'pattern':2098 'perform':1558,1602 'permiss':225,438,815,1321,1447,1568,1646,1740 'permissionhandl':212,420,730,1238 'permissionhandler.approve':227,440,817,1323,1449,1570,1648,1742 'permissionhandler.approveall':327,530,1009,1495,1791 'permit':1962 'persist':1970,2236 'person':1613 'persona':1518,1948 'pip':122 'plan':60 'port':1700,1884,1887 'pr':1419,1536,1539,1579,1583 'pr-review':1535,1578 'practic':1547,1591,2188 'pre':1406 'pre-built':1405 'prerequisit':67 'preview':2329 'print':242,464,1349,1356,1388 'process':1809,1858,1916,2277 'process.exit':198,408,715,2095 'process.on':2087 'process.stdin':1184 'process.stdout':1186 'process.stdout.write':388,699,1178,1216 'product':39,2338 'production-test':38 'programmat':46 'prompt':188,237,292,337,400,472,512,554,703,847,1204,1220,1224,1225,1385,1548,1592,1953,2009,2051,2115,2122,2137 'properti':623,1116 'protocol':1402 'provid':1799 'pull':1543,1587 'pydant':718,742,1250 'python':20,85,120,204,205,410,411,717,719,1226,1227,1440,1441,1561,1562,1639,1640,1725,1726 'queri':2167 'question':1072 'quick':162 'quit':1193,1355 'raini':654,784,911,971,1133,1290 'rand.intn':915,920 'random':723,1231,1888 'random.choice':792,1298 'random.randint':788,1294 'random.shared.next':976,982 'readlin':1097,1099 'readline.createinterface':1182 'real':352,643 'real-tim':351 'reason':569,1836,1843 'recommend':2336 'repositori':1416,2293 'request':226,439,816,1033,1322,1448,1544,1569,1588,1647,1741 'requir':631,1124 'resourc':1687,2291 'respons':185,194,232,288,332,343,349,1059,1828,1832,1957,2048,2127,2234 'response.data.content':243,304 'restart':1907,1976 'result':1046,1056 'resum':1973,1995 'return':669,794,923,984,1148,1215,1300,2177 'review':1537,1540,1542,1554,1580,1584,1586,1598 'rl':1181 'rl.close':1214 'rl.question':1205 'robust':2221 'rpc':2264,2286 'run':200,345,347,594,1040,1671 'runtim':42,82,2171 'sale':2147 'sampl':2319 'save':1971 'schema':589,598 'sdk':2,10,29,127,1039,1681,1703,1801,2260,2273,2325 'seattl':710,854 'secur':1557,1601 'send':1029 'sendandwait':2207 'sent':1048 'separ':1677 'server':1395,1403,1414,1455,1670,1675,1695,1699,1706,1816,1879,1885,1903,1943,2076,2267,2305,2310 'session':176,220,223,274,321,371,433,436,484,524,680,810,813,935,1003,1159,1316,1319,1424,1442,1445,1465,1489,1525,1563,1566,1617,1641,1644,1717,1735,1738,1762,1785,1918,1935,1969,1983,1996,1999,2018,2021,2028,2039,2105,2237,2240 'session.abort':2156 'session.error':1859 'session.idle':392,507,1855,2162 'session.on':381,465,495,536,692,840,1171,1346,2158 'session.send':234,469,844,1382,2008,2136 'session.sendandwait':187,290,399,510,702,1219,2050,2114,2121 'session.sendandwaitasync':334,551 'sessionconfig':325,528,1007,1493,1789 'sessionev':363,383,604,694,1092,1173 'sessioneventtyp':425,740,1248 'sessioneventtype.assistant':453,833,1339 'sessioneventtype.session':462 'sessionid':1933,1988 'sessionidleev':548 'set':2204 'settimeout':2155 'share':1688 'short':404,476,516,558 'shut':2091 'shutdown':2085 'sigint':2088 'skill':5 'sonnet':1930,2185 'source-github' 'spawn':1804 'special':1516 'specif':1520 'start':163,1692,1846,1849,2298 'status':2323 'stdio':1891,2288 'str':750,1258 'stream':348,379,445,493,534,688,822,943,1013,1167,1328,1831,1842,1954,2226,2228 'string':626,637,867,878,882,886,908,964,1119,1475,1502 'struct':865,876 'subscrib':2216 'sunni':652,782,909,969,1131,1288 'sys':415,725,1233 'sys.stdout.flush':459,839,1345 'sys.stdout.write':456,836,1342,1379 'system':1605,1653,1873,1952 'system.componentmodel':956 'systemmessag':1625,1949 'task':1521 'tcp':1895,2290 'team':1635,1664 'technic':2328 'tell':401,473,513,555,576 'temp':658,672,787,799,914,931,975,988,1137,1151,1293,1305 'temperatur':671,797,881,884,927,987,1150,1303 'test':40 'time':353 'timeout':2054,2205,2209 'timeoutid':2154,2164 'tokyo':712,856 'tool':61,561,563,574,581,690,735,763,824,945,1015,1018,1026,1031,1066,1075,1169,1243,1271,1330,1408,1847,1852,1937,1939,1963,1968,2250,2253 'tool.execution':1845,1850 'transport':1892 'tri':1195,1357,1367,2033,2194 'true':380,446,494,535,689,823,944,1014,1168,1329,1366,1896,1905,1910 'try-fin':2193 'tsx':119,202 'turn':2101,2245 'tutori':2299 'type':114,621,625,863,874,1114,1118,1190,1352,1434,1457,1478,1507,1818,2142 'typescript':21,164,165,358,359,596,599,1086,1087,1421,1422,1522,1523,1614,1615,1707,1708,1981,1997,2019,2032,2086,2103,2134,2152,2172 'url':1436,1459,1480,1509,1730 'use':19,310,313,319,522,951,953,955,1001,1487,1684,1772,1783,1890,1925,2192,2206,2225,2238,2339 'user':1070,1368,1386,1822,1989,2002 'user.message':1821 'user_input.lower':1376 'usestdio':1889 'ux':357,2231 'var':314,320,331,523,957,966,974,979,1002,1488,1773,1784 'verbos':1899 'verifi':92 'version':95 'via':2283 'wait':236,471,846,1384 'weather':611,616,647,707,760,768,775,826,851,892,896,992,996,1104,1109,1188,1199,1268,1276,1283,1332,1350,1361 'weatherparam':864,902 'weatherresult':875,905,924 'whitelist':1960 'work':1019,1912 'workflow':15 'write':2251 'y':111 'yet':2340","prices":[{"id":"f2dfcc0d-2790-4ae8-a8bf-1de9036cd68a","listingId":"c526ad9e-bf58-4920-baec-2c6176f039e1","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"github","category":"awesome-copilot","install_from":"skills.sh"},"createdAt":"2026-04-18T20:25:38.433Z"}],"sources":[{"listingId":"c526ad9e-bf58-4920-baec-2c6176f039e1","source":"github","sourceId":"github/awesome-copilot/copilot-sdk","sourceUrl":"https://github.com/github/awesome-copilot/tree/main/skills/copilot-sdk","isPrimary":false,"firstSeenAt":"2026-04-18T21:48:43.839Z","lastSeenAt":"2026-04-22T12:52:08.774Z"},{"listingId":"c526ad9e-bf58-4920-baec-2c6176f039e1","source":"skills_sh","sourceId":"github/awesome-copilot/copilot-sdk","sourceUrl":"https://skills.sh/github/awesome-copilot/copilot-sdk","isPrimary":true,"firstSeenAt":"2026-04-18T20:25:38.433Z","lastSeenAt":"2026-04-22T16:40:17.412Z"}],"details":{"listingId":"c526ad9e-bf58-4920-baec-2c6176f039e1","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"github","slug":"copilot-sdk","source":"skills_sh","category":"awesome-copilot","skills_sh_url":"https://skills.sh/github/awesome-copilot/copilot-sdk"},"updatedAt":"2026-04-22T16:40:17.412Z"}}