### Complete Agents Configuration Example Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/agents-sandbox.md Demonstrates a comprehensive setup of multiple custom agents with their respective descriptions, prompts, tools, and model overrides. ```csharp var options = Claude.Options() .Agents(a => a .Add("python_expert", "Python development specialist", "You are an expert Python developer. Write clean, efficient Python code.", ["Read", "Write", "Bash"], "claude-opus-4-20250805") .Add("code_reviewer", "Code quality reviewer", "Review code for quality, security, and performance issues.", ["Read", "Grep"]) .Add("documentation_writer", "Creates comprehensive documentation", "Write clear, helpful documentation with examples.", ["Write", "Read"])) .Build(); ``` -------------------------------- ### Example: Adding SDK MCP Servers Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/mcp-sdk.md Demonstrates how to configure and add SDK-based MCP servers, including defining tools for them. This is typically used within a larger configuration setup. ```csharp .McpServers(m => m .AddSdk("calculator", s => s .Tool("add", (double a, double b) => a + b, "Add two numbers") .Tool("multiply", (double a, double b) => a * b, "Multiply two numbers"))) ``` -------------------------------- ### Complete Sandbox Configuration Example Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/agents-sandbox.md A comprehensive example demonstrating how to configure sandbox options, including tools, command exclusions, network settings, and violation ignores. ```csharp var options = Claude.Options() .AllowTools("Bash") .Sandbox(s => s .Enable() .AutoAllowBash() .ExcludeCommands("rm", "rmdir", "dd", "sudo", "chmod") .Network(n => n .AllowLocalBinding() .AllowUnixSockets("/run/docker.sock") .HttpProxyPort(8080)) .IgnoreViolations(v => v .File("/tmp/*", "*.log") .Network("127.0.0.1:*"))) .Build(); await foreach (var msg in Claude.QueryAsync("Build a Docker image", options)) { // Process response } ``` -------------------------------- ### Multi-Agent Configuration Example Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/agents-sandbox.md Example of setting up multiple agents with specific roles, capabilities, and system prompts for coordinated task execution. ```csharp var options = Claude.Options() .Agents(a => a .Add("architect", "System design specialist", @"You are a software architect. Design scalable systems. Consider performance, maintainability, and cost.", ["Read", "Grep"]) .Add("implementer", "Code implementation specialist", @"You are an experienced developer. Implement designs cleanly. Write well-tested, production-ready code.", ["Write", "Bash", "Read"]) .Add("tester", "Quality assurance specialist", @"You are a QA engineer. Design and verify tests. Ensure correctness and edge case coverage.", ["Bash", "Write", "Read"])) .SystemPrompt(@"You are coordinating a team of specialists. Delegate tasks appropriately and review their work.") .Build(); await foreach (var msg in Claude.QueryAsync("Build a REST API", options)) { if (msg is AssistantMessage am) foreach (var block in am.Content) if (block is TextBlock tb) Console.WriteLine(tb.Text); } ``` -------------------------------- ### Complete Hook Configuration Example Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/hooks-builder.md Demonstrates how to configure various hooks (PreToolUse, PostToolUse, UserPromptSubmit) using the HooksBuilder. Includes an example of blocking destructive commands. ```csharp var options = Claude.Options() .AllowTools("Bash", "Read", "Write") .Hooks(h => h .PreToolUse("Bash", async (input, toolUseId, ctx, ct) => { var hookInput = JsonSerializer.Deserialize(input); Console.WriteLine($"[Pre] Running {hookInput.ToolName}"); if (hookInput.ToolInput.GetProperty("command").GetString()?.Contains("rm") == true) { return new HookOutput { Continue = false, StopReason = "Blocking destructive command" }; } return new HookOutput { Continue = true }; }) .PostToolUse("*", async (input, toolUseId, ctx, ct) => { var hookInput = JsonSerializer.Deserialize(input); Console.WriteLine($"[Post] {hookInput.ToolName} completed"); return new HookOutput { Continue = true }; }) .UserPromptSubmit(async (input, toolUseId, ctx, ct) => { var hookInput = JsonSerializer.Deserialize(input); Console.WriteLine($"[Prompt] {hookInput.Prompt}"); return new HookOutput { Continue = true }; })) .Build(); ``` -------------------------------- ### Example McpToolAnnotations Instance Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/mcp-sdk.md Demonstrates how to instantiate and populate McpToolAnnotations with specific hints for a tool. This example sets the title, destructive, and idempotent hints for a 'Delete User' tool. ```csharp new McpToolAnnotations { Title = "Delete User", DestructiveHint = true, IdempotentHint = true } ``` -------------------------------- ### One-Shot Query Example Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/README.md Use Claude.QueryAsync() for simple, stateless queries. This example demonstrates setting system prompts, models, and allowed tools. ```csharp var options = Claude.Options() .SystemPrompt("You are helpful.") .Model("claude-sonnet-4-20250514") .AllowTools("Bash", "Read") .Build(); await foreach (var msg in Claude.QueryAsync("List files", options)) { if (msg is AssistantMessage am) foreach (var block in am.Content) Console.WriteLine(block); } ``` -------------------------------- ### Development Setup Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/configuration.md Basic configuration for development, including system prompt, model selection, allowed tools, and error stream logging. ```csharp var options = Claude.Options() .SystemPrompt("You are a helpful coding assistant.") .Model("claude-sonnet-4-20250514") .AllowTools("Bash", "Read", "Write") .IncludePartialMessages(true) .OnStderr(msg => Console.Error.WriteLine(msg)) .Build(); ``` -------------------------------- ### Interactive Session Example Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/README.md Use ClaudeSDKClient for bidirectional conversations. This example shows connecting, sending a query, and receiving responses. ```csharp await using var client = new ClaudeSDKClient(options); await client.ConnectAsync(); await client.QueryAsync("First question?"); await foreach (var msg in client.ReceiveResponseAsync()) { // Process response } // Send follow-up await client.QueryAsync("Follow-up question?"); await foreach (var msg in client.ReceiveResponseAsync()) { // Process follow-up } ``` -------------------------------- ### Configuration with Logging Hooks Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/configuration.md Setup with hooks for logging pre and post tool usage. Wildcards are used to apply hooks to all tools. ```csharp var options = Claude.Options() .AllowTools("Bash") .Hooks(h => h .PreToolUse("*", async (input, id, ctx, ct) => { var hookInput = JsonSerializer.Deserialize(input); _logger.LogInformation($ ``` -------------------------------- ### Install Claude Code CLI Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/README.md Install the Claude Code CLI globally using npm. This is a prerequisite for using the SDK. ```bash npm install -g @anthropic-ai/claude-code ``` -------------------------------- ### Get Server Initialization Info Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/sdk-client.md Gets server initialization info including available commands and output styles. Returns a dictionary with server info or null if not in streaming mode. This method may throw a CliConnectionException if not connected. ```csharp public JsonElement? GetServerInfo() ``` -------------------------------- ### Tool Permission Control Example Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/README.md Dynamically control tool execution using the CanUseTool method. This example denies destructive commands like 'rm'. ```csharp .CanUseTool(async (toolName, input, context, ct) => { if (toolName == "Bash" && input.GetProperty("command").GetString()?.Contains("rm") == true) return new PermissionResultDeny("No destructive commands"); return new PermissionResultAllow(); }) ``` -------------------------------- ### Example: Tool with Cancellation Token Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/mcp-sdk.md Demonstrates registering a tool ('search') that uses an asynchronous handler and accepts a CancellationToken for cancellation. This is useful for long-running operations. ```csharp .Tool("search", async (string query, int maxResults, CancellationToken ct) => { // Implement search logic var results = await SearchAsync(query, maxResults, ct); return results; }, "Search for documents") ``` -------------------------------- ### Example: Simple Arithmetic Tools Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/mcp-sdk.md Registers simple arithmetic tools like 'add' and 'multiply' with their respective lambda function handlers and descriptions. These are basic examples of tool definitions. ```csharp .Tool("add", (double a, double b) => a + b, "Add two numbers") .Tool("multiply", (double a, double b) => a * b, "Multiply two numbers") ``` -------------------------------- ### Custom Agents Example Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/README.md Define specialized AI agents using the Agents builder. This example adds 'reviewer' and 'writer' agents with specified roles and tools. ```csharp .Agents(a => a .Add("reviewer", "Code reviewer", "Review for quality.", "Read", "Grep") .Add("writer", "Code writer", "Write clean code.", "Write", "Bash")) ``` -------------------------------- ### Add NuGet Package Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/README.md Install the Claude Agent SDK using the .NET CLI. This package is coming soon. ```bash dotnet add package Claude.AgentSdk ``` -------------------------------- ### Configure MCP SDK Server with Tool Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/configuration.md Set up an MCP server configuration for an SDK, defining tools and their corresponding C# functions. This example adds a 'calculator' SDK with an 'add' tool. ```csharp .McpServers(m => m.AddSdk("calculator", s => s .Tool("add", (double a, double b) => a + b, "Add two numbers"))) ``` -------------------------------- ### Example: Tool with Destructive Hint Annotation Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/mcp-sdk.md Shows how to register a tool ('delete_file') and provide annotations, specifically a DestructiveHint, to indicate that the tool performs a destructive operation. ```csharp .Tool("delete_file", (string path) => File.Delete(path), "Delete a file", new McpToolAnnotations { DestructiveHint = true }) ``` -------------------------------- ### Production Setup with Safety Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/configuration.md Secure configuration for production, specifying model, limited tools, permission mode, budget, turn limits, and custom tool permission logic. ```csharp var options = Claude.Options() .SystemPrompt("You are a secure assistant.") .Model("claude-opus-4-20250805") .AllowTools("Read") .PermissionMode(PermissionMode.Default) .MaxBudget(100m) .MaxTurns(20) .CanUseTool(async (toolName, input, context, ct) => { // Add custom permission logic return new PermissionResultAllow(); }) .Build(); ``` -------------------------------- ### Example: Tool with Single Complex Parameter Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/mcp-sdk.md Illustrates registering a tool ('search') that accepts a single complex parameter object, which will be populated from the JSON arguments. This simplifies handling multiple arguments. ```csharp public class SearchArgs { public string Query { get; set; } public int MaxResults { get; set; } } // Handler receives entire JSON object deserialized to SearchArgs .Tool("search", (SearchArgs args) => PerformSearch(args.Query, args.MaxResults), "Search documents") ``` -------------------------------- ### Multi-Turn Conversation Example Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/README.md Initiate and manage a multi-turn conversation with the Claude API using the `ClaudeSDKClient`. This example shows connecting, sending a message, and receiving responses. ```csharp using Claude.AgentSdk; await using var client = new ClaudeSDKClient(); await client.ConnectAsync(); await client.QueryAsync("Write a Python hello world"); await foreach (var msg in client.ReceiveResponseAsync()) { if (msg is AssistantMessage am) foreach (var block in am.Content) if (block is TextBlock tb) Console.Write(tb.Text); } ``` -------------------------------- ### Execute Query with Pre-Tool Use Hooks Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/main-api.md Executes a query with pre-tool use hooks. This example demonstrates logging the input before a 'Bash' tool is used, allowing for custom logic execution prior to tool invocation. ```csharp var options = Claude.Options() .AllowTools("Bash") .Hooks(h => h .PreToolUse("Bash", async (input, toolUseId, ctx, ct) => { Console.WriteLine($"[Hook] Bash command: {input}"); return new HookOutput { Continue = true }; })) .Build(); await foreach (var msg in Claude.QueryAsync("List files", options)) { // Process messages } ``` -------------------------------- ### Sandbox Configuration Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/README.md Configure the sandbox environment for executing commands. This example enables the sandbox, auto-allows Bash, excludes specific commands, and configures network access. ```csharp var options = Claude.Options() .Sandbox(s => s .Enable() .AutoAllowBash() .ExcludeCommands("rm", "sudo") .Network(n => n.AllowLocalBinding())) .Build(); ``` -------------------------------- ### Installation Check for CLI Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/errors.md Verify that the Claude Code CLI is installed and accessible in your system's PATH or via npm. ```bash # Verify CLI is installed which claude # OR npm install -g @anthropic-ai/claude-code ``` -------------------------------- ### MCP Servers (In-Process) Example Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/README.md Define tools directly in .NET using McpServers. This snippet adds 'add' and 'multiply' tools to a 'calculator' MCP server. ```csharp .McpServers(m => m.AddSdk("calculator", s => s .Tool("add", (double a, double b) => a + b, "Add two numbers") .Tool("multiply", (double a, double b) => a * b, "Multiply two numbers"))) ``` -------------------------------- ### Custom Agent Configuration Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/README.md Define custom agents with specific roles, descriptions, and capabilities. This example creates 'reviewer' and 'writer' agents. ```csharp var options = Claude.Options() .Agents(a => a .Add("reviewer", "Reviews code", "You are a code reviewer.", "Read", "Grep") .Add("writer", "Writes code", "You are a clean coder.", tools: ["Read", "Write"])) .Build(); ``` -------------------------------- ### OnSubagentStart Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/hooks-builder.md Registers a hook that fires when a subagent starts. This enables you to execute custom logic whenever a new subagent is initiated. ```APIDOC ## OnSubagentStart ### Description Registers a hook that fires when a subagent starts. ### Method Signature `public HooksBuilder OnSubagentStart(HookCallback callback, double? timeout = null)` ### Parameters * `callback` (`HookCallback`) - The callback function to execute when a subagent starts. * `timeout` (`double?`) - Optional timeout for the hook. ### Input Type `SubagentStartHookInput` ``` -------------------------------- ### Sandbox Restrictions Example Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/README.md Limit tool execution scope using the Sandbox builder. This example enables the sandbox, auto-allows Bash, excludes specific commands, and configures network binding. ```csharp .Sandbox(s => s .Enable() .AutoAllowBash() .ExcludeCommands("rm", "sudo") .Network(n => n.AllowLocalBinding())) ``` -------------------------------- ### Hooks System Example Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/README.md Register callbacks for lifecycle events using the Hooks builder. This snippet shows pre-tool use and post-tool use hooks. ```csharp .Hooks(h => h .PreToolUse("Bash", async (input, id, ctx, ct) => { Console.WriteLine("Before bash"); return new HookOutput { Continue = true }; }) .PostToolUse("*", async (input, id, ctx, ct) => { Console.WriteLine("After any tool"); return new HookOutput { Continue = true }; })) ``` -------------------------------- ### Configure Claude SDK Options Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/main-api.md Example of configuring SDK options using the fluent builder API. This includes setting the system prompt, model, allowed tools, and maximum turns for a query. ```csharp using Claude.AgentSdk; var options = Claude.Options() .SystemPrompt("You are a helpful coding assistant.") .Model("claude-sonnet-4-20250514") .AllowTools("Bash", "Read", "Write") .MaxTurns(5) .Build(); ``` -------------------------------- ### In-Process MCP Tools Configuration Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/README.md Configure in-process Message Communication Protocol (MCP) servers for tools. This example adds a 'calculator' tool with an 'add' function. ```csharp using Claude.AgentSdk; using Claude.AgentSdk.Mcp; var options = Claude.Options() .McpServers(m => m.AddSdk("calculator", s => s .Tool("add", (double a, double b) => a + b, "Add two numbers"))) .AllowAllTools() .Build(); ``` -------------------------------- ### Configure MCP Tools for Queries Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/README.md Build custom options using Claude.Options() to enable MCP servers and define tools. This example registers 'add' and 'multiply' functions accessible via SDK. ```csharp var options = Claude.Options() .McpServers(m => m.AddSdk("tools", s => s .Tool("add", (double a, double b) => a + b, "Add") .Tool("multiply", (double a, double b) => a * b, "Multiply"))) .AllowAllTools() .Build(); await foreach (var msg in Claude.QueryAsync("What is 5 * 3 plus 2?", options)) { // Process } ``` -------------------------------- ### Connect to Claude with an Initial Prompt Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/sdk-client.md Connects to Claude and sends an initial system prompt and user prompt. This configures the client's behavior and starts the conversation. ```csharp var options = Claude.Options() .SystemPrompt("You are a Python expert.") .Build(); await using var client = new ClaudeSDKClient(options); await client.ConnectAsync("Write a Hello World program"); await foreach (var msg in client.ReceiveResponseAsync()) { if (msg is AssistantMessage am) foreach (var block in am.Content) if (block is TextBlock tb) Console.WriteLine(tb.Text); } ``` -------------------------------- ### Tool Permission Callback Configuration Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/README.md Define a callback to control tool usage permissions. This example denies permission for 'Bash' tool if the command is 'rm'. ```csharp var options = Claude.Options() .CanUseTool(async (toolName, input, context, ct) => { if (toolName == "Bash" && input.GetProperty("command").GetString()?.Contains("rm") == true) return new PermissionResultDeny("Destructive commands not allowed"); return new PermissionResultAllow(); }) .Build(); ``` -------------------------------- ### ClaudeSDKClient.GetServerInfo Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/sdk-client.md Gets server initialization information, including available commands and output styles. The information is returned as a nullable JSON element. A CliConnectionException may be thrown if the client is not connected. ```APIDOC ## ClaudeSDKClient.GetServerInfo() ### Description Gets server initialization info including available commands and output styles. ### Method Signature ```csharp public JsonElement? GetServerInfo() ``` ### Return Type `JsonElement?` - Dictionary with server info, or null if not in streaming mode. ### Exceptions - `CliConnectionException`: If not connected. ``` -------------------------------- ### Configure Pre-Tool Use Hook Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/configuration.md Define a hook to execute logic before a specific tool is used. This example logs a message when the 'Bash' tool is about to be used. ```csharp .Hooks(h => h .PreToolUse("Bash", async (input, id, ctx, ct) => { Console.WriteLine("Running Bash tool"); return new HookOutput { Continue = true }; })) ``` -------------------------------- ### One-Shot Query Example Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/README.md Perform a simple, one-time query to the Claude API. This snippet demonstrates how to send a prompt and process the assistant's text response. ```csharp using Claude.AgentSdk; await foreach (var msg in Claude.QueryAsync("What is 2+2?")) { if (msg is AssistantMessage am) foreach (var block in am.Content) if (block is TextBlock tb) Console.Write(tb.Text); } ``` -------------------------------- ### Execute Query with Custom Options Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/main-api.md Executes a query to Claude Code using custom-configured options. This example demonstrates setting a system prompt, working directory, allowed tools, and processing the results. ```csharp var options = Claude.Options() .SystemPrompt("You are an expert Python developer") .Cwd("/home/user/project") .AllowTools("Bash", "Read") .Build(); await foreach (var message in Claude.QueryAsync("Create a Python web server", options)) { Console.WriteLine(message); } ``` -------------------------------- ### ClaudeSDKClient.ConnectAsync(string?, CancellationToken) Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/sdk-client.md Establishes a connection to Claude, optionally sending an initial prompt. Supports interactive mode or starting a conversation with a predefined message. ```APIDOC ## ClaudeSDKClient.ConnectAsync(string?, CancellationToken) ### Description Establishes a connection to Claude, optionally sending an initial prompt. Supports interactive mode or starting a conversation with a predefined message. ### Signature ```csharp public async Task ConnectAsync( string? prompt = null, CancellationToken cancellationToken = default) ``` ### Parameters #### Parameters - **prompt** (`string?`) - Optional - Optional initial prompt to send. If null, enters interactive mode. - **cancellationToken** (`CancellationToken`) - Optional - Cancellation token. ### Return Type `Task` ### Exceptions - **ArgumentException**: If `can_use_tool` callback is configured with a prompt string (requires streaming mode). - **CliConnectionException**: If connection to CLI fails. ### Remarks This method establishes the connection to Claude Code. If a prompt is provided, it will be automatically sent as the first user message. For interactive mode (no initial prompt), pass `null`. ### Example: Interactive Mode ```csharp await using var client = new ClaudeSDKClient(); await client.ConnectAsync(); // null prompt = interactive mode await client.QueryAsync("What is 2+2?"); await foreach (var msg in client.ReceiveResponseAsync()) { // Process response } ``` ### Example: With Initial Prompt ```csharp var options = Claude.Options() .SystemPrompt("You are a Python expert.") .Build(); await using var client = new ClaudeSDKClient(options); await client.ConnectAsync("Write a Hello World program"); await foreach (var msg in client.ReceiveResponseAsync()) { if (msg is AssistantMessage am) foreach (var block in am.Content) if (block is TextBlock tb) Console.WriteLine(tb.Text); } ``` ``` -------------------------------- ### Start an Interactive Session Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/README.md Utilize ClaudeSDKClient for interactive sessions. Connect to the client, read user input from the console, send prompts, and receive/display responses until the user enters an empty line. ```csharp await using var client = new ClaudeSDKClient(); await client.ConnectAsync(); while (true) { var prompt = Console.ReadLine(); if (string.IsNullOrEmpty(prompt)) break; await client.QueryAsync(prompt); await foreach (var msg in client.ReceiveResponseAsync()) { if (msg is AssistantMessage am) foreach (var block in am.Content) if (block is TextBlock tb) Console.Write(tb.Text); } } await client.DisconnectAsync(); ``` -------------------------------- ### Handling ArgumentException Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/errors.md Shows how to catch a standard .NET ArgumentException, which is raised for invalid arguments passed to SDK methods. This example catches errors related to client connection or configuration. ```csharp try { var client = new ClaudeSDKClient(); // Providing initial prompt with can_use_tool callback requires streaming mode await client.ConnectAsync("test prompt"); } catch (ArgumentException ex) { Console.WriteLine($"Invalid argument: {ex.Message}"); } ``` -------------------------------- ### Example Usage of Claude.QueryAsync with Streaming Prompts Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/main-api.md Demonstrates how to use Claude.QueryAsync with a streaming input prompt. The prompt is generated using a yield return statement within an async iterator. ```csharp async IAsyncEnumerable> GeneratePrompts() { yield return new Dictionary { ["type"] = "user", ["message"] = new { role = "user", content = "First question?" }, ["parent_tool_use_id"] = null, ["session_id"] = "default" }; } await foreach (var message in Claude.QueryAsync(GeneratePrompts())) { // Process response } ``` -------------------------------- ### Build from Source Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/README.md Clone the repository and build the Claude Agent SDK from source using the .NET CLI. ```bash git clone https://github.com/anthropics/claude-agent-sdk-dotnet.git cd claude-agent-sdk-dotnet dotnet build ``` -------------------------------- ### Configuration with MCP Servers Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/configuration.md Setting up MCP servers with custom tools like 'add' and 'multiply' for a calculator service. ```csharp var options = Claude.Options() .McpServers(m => m .AddSdk("calculator", s => s .Tool("add", (double a, double b) => a + b, "Add") .Tool("multiply", (double a, double b) => a * b, "Multiply"))) .AllowAllTools() .Build(); ``` -------------------------------- ### Get MCP Server Status Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/sdk-client.md Retrieves the current MCP server status. This method may throw a CliConnectionException if not connected. ```csharp public async Task GetMcpStatusAsync(CancellationToken cancellationToken = default) ``` -------------------------------- ### Enable Beta Features Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/configuration.md List beta features to enable for early access. Defaults to an empty list. ```csharp public IReadOnlyList Betas { get; init; } ``` ```csharp .Betas("feature1", "feature2") ``` -------------------------------- ### SystemPrompt(SystemPromptPreset) Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Sets the system prompt using a predefined preset. ```APIDOC ## SystemPrompt(SystemPromptPreset) ### Description Sets the system prompt using a predefined preset. ### Method `public ClaudeAgentOptionsBuilder SystemPrompt(SystemPromptPreset preset)` ### Parameters #### Path Parameters - **preset** (SystemPromptPreset) - Required - The system prompt preset to use. ``` -------------------------------- ### CliNotFoundException Definition Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/errors.md Thrown when the Claude Code CLI is not found or not installed. It inherits from CliConnectionException and provides the attempted CLI path if available. ```csharp public class CliNotFoundException : CliConnectionException { public string? CliPath { get; } public CliNotFoundException(string message, string? cliPath = null); } ``` -------------------------------- ### Configure Settings Path or JSON Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/configuration.md Specify a path to settings or provide JSON configuration directly. ```csharp public string? Settings { get; init; } ``` -------------------------------- ### Set AI Model Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Specifies the AI model to be used for agent interactions. Example model identifier: "claude-sonnet-4-20250514". ```csharp public ClaudeAgentOptionsBuilder Model(string model) ``` ```csharp .Model("claude-opus-4-20250805") ``` -------------------------------- ### Register Subagent Start Hook Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/hooks-builder.md Registers a hook that is triggered when a subagent begins execution. Useful for monitoring or managing subagent lifecycles. ```csharp public HooksBuilder OnSubagentStart(HookCallback callback, double? timeout = null) ``` -------------------------------- ### Configure McpServers with Action Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Use this method to configure MCP servers by providing a delegate that modifies the McpServerRegistry. ```csharp public ClaudeAgentOptionsBuilder McpServers(Action configure) ``` ```csharp .McpServers(m => m.AddSdk("calculator", s => s .Tool("add", (double a, double b) => a + b, "Add two numbers"))) ``` -------------------------------- ### Enable Thinking and Set Effort Level Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/README.md Configure query options to enable thinking with a specified token budget and set the effort level to High. Includes setting a system prompt for careful consideration. ```csharp var options = Claude.Options() .ThinkingEnabled(15000) // 15K token budget .Effort(EffortLevel.High) // Deep thinking .SystemPrompt("Think carefully before responding.") .Build(); await foreach (var msg in Claude.QueryAsync("Solve this complex problem", options)) { if (msg is AssistantMessage am) { foreach (var block in am.Content) { if (block is ThinkingBlock tb) Console.WriteLine($"Thinking: {tb.Thinking}"); else if (block is TextBlock txb) Console.WriteLine($"Response: {txb.Text}"); } } } ``` -------------------------------- ### Configure Setting Sources Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/configuration.md Specify the sources from which to load settings, such as User, Project, or Local. Defaults to None. ```csharp public IReadOnlyList? SettingSources { get; init; } ``` -------------------------------- ### Configure Sandbox settings with Action Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Use this method to configure sandbox settings by providing a delegate that modifies the SandboxBuilder. ```csharp public ClaudeAgentOptionsBuilder Sandbox(Action configure) ``` ```csharp .Sandbox(s => s .Enable() .AutoAllowBash() .ExcludeCommands("rm", "sudo") .Network(n => n.AllowLocalBinding())) ``` -------------------------------- ### Configuration with Sandbox Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/configuration.md Enabling a sandbox environment with specific configurations like auto-allowing Bash and excluding certain commands. ```csharp var options = Claude.Options() .AllowTools("Bash") .Sandbox(s => s .Enable() .AutoAllowBash() .ExcludeCommands("rm", "rmdir", "dd") .Network(n => n.AllowLocalBinding())) .Build(); ``` -------------------------------- ### SystemPrompt(string) Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Sets a custom system prompt for the Claude Agent. ```APIDOC ## SystemPrompt(string) ### Description Sets a custom system prompt for the Claude Agent. ### Method `public ClaudeAgentOptionsBuilder SystemPrompt(string prompt)` ### Parameters #### Path Parameters - **prompt** (string) - Required - The custom system prompt to set. ``` -------------------------------- ### Set System Prompt with String Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/configuration.md Configure the agent with a custom string-based system prompt. This is useful for defining the AI's persona or task. ```csharp .SystemPrompt("You are a Python expert.") ``` -------------------------------- ### Handle Errors During Queries Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/README.md Implement try-catch blocks to manage potential exceptions like CliNotFoundException (if the Claude Code CLI is not installed) or general ClaudeSDKException. Provides specific guidance for each error type. ```csharp try { await foreach (var msg in Claude.QueryAsync("test")) { // Process } } catch (CliNotFoundException) { Console.WriteLine("Install: npm install -g @anthropic-ai/claude-code"); } catch (ClaudeSDKException ex) { Console.WriteLine($"Error: {ex.Message}"); } ``` -------------------------------- ### Add Directories to Include Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/configuration.md Specify additional directories to be included in the project context. Defaults to an empty list. ```csharp public IReadOnlyList AddDirs { get; init; } ``` -------------------------------- ### Create Text Tool Result Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/mcp-sdk.md Example of using the McpToolResults.Text helper method to create a tool result containing a simple text message. This is useful for returning string responses from tool calls. ```csharp .Tool("greet", (string name) => { return McpToolResults.Text($"Hello, {name}!"); }, "Greet a person") ``` -------------------------------- ### Set McpServers directly with object Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Use this method to set MCP servers directly by passing an object that represents the server configuration. ```csharp public ClaudeAgentOptionsBuilder McpServers(object servers) ``` -------------------------------- ### Set System Prompt with Preset Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Sets the system prompt using a predefined preset. ```csharp public ClaudeAgentOptionsBuilder SystemPrompt(SystemPromptPreset preset) ``` -------------------------------- ### Query with Custom Options Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/README.md Configure a query with specific options such as system prompt, maximum turns, and model. This allows for fine-tuning the assistant's behavior. ```csharp var options = Claude.Options() .SystemPrompt("You are a helpful coding assistant.") .MaxTurns(5) .Model("claude-sonnet-4-20250514") .AcceptEdits() .Build(); await foreach (var msg in Claude.QueryAsync("Explain async/await", options)) { // handle messages } ``` -------------------------------- ### Get ClaudeAgentOptionsBuilder Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/main-api.md Creates a new builder instance used to configure query options. The builder supports a fluent API for setting various parameters like system prompt, model, tools, hooks, and more. ```csharp public static ClaudeAgentOptionsBuilder Options() ``` -------------------------------- ### NetworkBuilder Methods Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/agents-sandbox.md Methods for configuring network settings within the sandbox. ```APIDOC ## NetworkBuilder ### AllowUnixSockets(params string[]) #### Description Allows access to specific Unix sockets. #### Parameters - `sockets` (params string[]) - The paths to the Unix sockets to allow. #### Example ```csharp .AllowUnixSockets("/run/docker.sock", "/var/run/docker.sock") ``` ### AllowAllUnixSockets(bool) #### Description Allows access to all Unix sockets. #### Parameters - `value` (bool) - Whether to allow all Unix sockets. Defaults to true. ### AllowLocalBinding(bool) #### Description Allows local network binding. #### Parameters - `value` (bool) - Whether to allow local binding. Defaults to true. #### Example ```csharp .AllowLocalBinding() // Allow localhost connections ``` ### HttpProxyPort(int) #### Description Sets the HTTP proxy port. #### Parameters - `port` (int) - The port number for the HTTP proxy. #### Example ```csharp .HttpProxyPort(8080) ``` ### SocksProxyPort(int) #### Description Sets the SOCKS proxy port. #### Parameters - `port` (int) - The port number for the SOCKS proxy. ``` -------------------------------- ### Enable Thinking with Token Budget Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Enables thinking with a specific token budget. Accepts the budget in tokens as an integer. ```csharp public ClaudeAgentOptionsBuilder ThinkingEnabled(int budgetTokens) ``` ```csharp .ThinkingEnabled(10000) ``` -------------------------------- ### McpServers(Action) Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Configures MCP servers using a registry builder. This method allows for detailed configuration of MCP server integrations. ```APIDOC ## McpServers(Action) ### Description Configures MCP servers using a builder pattern with a registry. ### Method Signature ```csharp public ClaudeAgentOptionsBuilder McpServers(Action configure) ``` ### Example ```csharp .McpServers(m => m.AddSdk("calculator", s => s.Tool("add", (double a, double b) => a + b, "Add two numbers"))) ``` ``` -------------------------------- ### SystemPromptPreset.ClaudeCode Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/types.md Creates a Claude Code preset system prompt configuration. This is useful for setting up agents that are intended to write or interact with code. ```APIDOC ## SystemPromptPreset.ClaudeCode ### Description Creates a Claude Code preset system prompt configuration. This is useful for setting up agents that are intended to write or interact with code. ### Method `ClaudeCode(string? append = null)` ### Parameters #### Query Parameters - **append** (string?) - Optional - Additional text to append to the default Claude Code prompt. ### Response #### Success Response (200) - **SystemPromptPreset** - An object representing the Claude Code system prompt configuration. ``` -------------------------------- ### Set Settings Path or JSON Configuration Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Configures the agent with a settings path or JSON configuration string. ```csharp public ClaudeAgentOptionsBuilder Settings(string settings) ``` -------------------------------- ### Configure Calculator MCP Server Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/mcp-sdk.md This snippet shows how to configure an MCP server to expose basic arithmetic operations (add, subtract, multiply, divide) to the Claude model. It includes error handling for division by zero. ```csharp using Claude.AgentSdk; var options = Claude.Options() .SystemPrompt("You are a helpful math assistant.") .McpServers(m => m.AddSdk("calculator", s => s .Tool("add", (double a, double b) => a + b, "Add two numbers") .Tool("subtract", (double a, double b) => a - b, "Subtract two numbers") .Tool("multiply", (double a, double b) => a * b, "Multiply two numbers") .Tool("divide", (double a, double b) => { if (b == 0) return McpToolResults.Text("Error: Division by zero", isError: true); return McpToolResults.Text((a / b).ToString()); }, "Divide two numbers"))) .AllowAllTools() .Build(); await foreach (var message in Claude.QueryAsync("What is 10 + 5? Then multiply by 3?", options)) { if (message is AssistantMessage am) { foreach (var block in am.Content) { if (block is TextBlock tb) Console.WriteLine(tb.Text); } } } ``` -------------------------------- ### Set System Prompt with Preset Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/configuration.md Configure the agent with a predefined system prompt preset, such as ClaudeCode. This allows for standardized prompt configurations. ```csharp .SystemPrompt(SystemPromptPreset.ClaudeCode("Always think step-by-step")) ``` -------------------------------- ### Build() Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Builds and returns the final ClaudeAgentOptions instance. This method must be called to finalize the configuration and obtain the options object for use with Claude SDK methods. ```APIDOC ## Build() ### Description Builds and returns the final `ClaudeAgentOptions` instance. ### Method Signature ```csharp public ClaudeAgentOptions Build() ``` ### Return Type `ClaudeAgentOptions` ### Remarks This must be called to create the options object for use with `Claude.QueryAsync()` or `ClaudeSDKClient`. ### Example ```csharp var options = Claude.Options() .SystemPrompt("You are helpful.") .Model("claude-sonnet-4-20250514") .AllowTools("Bash", "Read") .Build(); // Use options await foreach (var msg in Claude.QueryAsync("List files", options)) { // Process response } ``` ``` -------------------------------- ### Configure SDK Plugins Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/configuration.md Specify SDK plugin configurations. This allows for extending the SDK's functionality with custom plugins. ```csharp public IReadOnlyList Plugins { get; init; } ``` -------------------------------- ### Sandbox(Action) Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Configures sandbox settings using a builder. This allows for fine-grained control over the sandbox environment, including network access and command restrictions. ```APIDOC ## Sandbox(Action) ### Description Configures sandbox settings using a builder pattern. ### Method Signature ```csharp public ClaudeAgentOptionsBuilder Sandbox(Action configure) ``` ### Example ```csharp .Sandbox(s => s.Enable().AutoAllowBash().ExcludeCommands("rm", "sudo").Network(n => n.AllowLocalBinding())) ``` ``` -------------------------------- ### Plugin(string, string) Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Adds a plugin configuration with a specified type and path. ```APIDOC ## Plugin(string, string) ### Description Adds a plugin configuration. ### Method `ClaudeAgentOptionsBuilder` ### Parameters * **type** (string) - Required - The type of the plugin. * **path** (string) - Required - The path to the plugin configuration. ``` -------------------------------- ### McpStdioServerConfig Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/types.md Configuration for an stdio-based MCP server. ```APIDOC ## McpStdioServerConfig ### Description Configures a Message Communication Protocol (MCP) server that communicates over standard input/output (stdio). This is useful for launching MCP servers as separate processes. ### Parameters #### Request Body - **Command** (string) - Required - The command to execute to start the MCP server. - **Args** (IReadOnlyList?) - Optional - Arguments to pass to the MCP server command. - **Env** (IReadOnlyDictionary?) - Optional - Environment variables to set for the MCP server process. ### Request Example ```json { "Command": "/usr/local/bin/mcp-server", "Args": ["--config", "prod.yaml"], "Env": { "LOG_LEVEL": "INFO" } } ``` ### Response #### Success Response (200) - **McpStdioServerConfig** - The configured stdio-based MCP server settings. ``` -------------------------------- ### AppendSystemPrompt(string) Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Appends instructions to Claude Code's default system prompt, recommended for extending behavior while keeping defaults. ```APIDOC ## AppendSystemPrompt(string) ### Description Appends instructions to Claude Code's default system prompt. This is the recommended way to extend Claude Code's behavior while keeping its defaults. ### Method `public ClaudeAgentOptionsBuilder AppendSystemPrompt(string additionalInstructions)` ### Parameters #### Path Parameters - **additionalInstructions** (string) - Required - The additional instructions to append to the system prompt. ### Request Example ```csharp .AppendSystemPrompt("Always think step-by-step before responding.") ``` ``` -------------------------------- ### Add Allowed Tools Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Expands the list of tools that the agent is permitted to use. ```csharp public ClaudeAgentOptionsBuilder AllowTools(params string[] tools) ``` ```csharp .AllowTools("Bash", "Read") ``` -------------------------------- ### SandboxBuilder.Enable Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/agents-sandbox.md Enables the sandbox environment, allowing for the configuration of security restrictions. ```APIDOC ## SandboxBuilder.Enable() ### Description Enables the sandbox environment. ### Method ``` public SandboxBuilder Enable() ``` ### Parameters * None ### Return Type `SandboxBuilder` (for fluent chaining) ``` -------------------------------- ### SystemPromptPreset Record Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/types.md Configuration for preset system prompts. Use this to define a specific system prompt configuration, such as the Claude Code preset. ```csharp public record SystemPromptPreset { [JsonPropertyName("type")] public string Type => "preset"; [JsonPropertyName("preset")] public required string Preset { get; init; } [JsonPropertyName("append")] public string? Append { get; init; } public static SystemPromptPreset ClaudeCode(string? append = null); } ``` -------------------------------- ### Add Plugin Configuration Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Adds a plugin configuration by specifying its type and path. Accepts type and path as strings. ```csharp public ClaudeAgentOptionsBuilder Plugin(string type, string path) ``` -------------------------------- ### Build ClaudeAgentOptions instance Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Call this method to finalize the configuration and build the ClaudeAgentOptions instance. This is required before using the options with Claude.QueryAsync() or ClaudeSDKClient. ```csharp public ClaudeAgentOptions Build() ``` ```csharp var options = Claude.Options() .SystemPrompt("You are helpful.") .Model("claude-sonnet-4-20250514") .AllowTools("Bash", "Read") .Build(); // Use options await foreach (var msg in Claude.QueryAsync("List files", options)) { // Process response } ``` -------------------------------- ### McpServers(object) Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Sets MCP servers directly using an object. This provides a simpler way to set up MCP servers if a builder is not needed. ```APIDOC ## McpServers(object) ### Description Sets MCP servers directly using a provided object. ### Method Signature ```csharp public ClaudeAgentOptionsBuilder McpServers(object servers) ``` ``` -------------------------------- ### Set Base Tools Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Enables a foundational set of tools for the agent. ```csharp public ClaudeAgentOptionsBuilder Tools(params string[] tools) ``` ```csharp .Tools("Bash", "Read", "Write") ``` -------------------------------- ### Configuration with Extended Thinking Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/configuration.md Enabling extended thinking with a specified duration and high effort level for complex problem-solving. ```csharp var options = Claude.Options() .Thinking(new ThinkingConfigEnabled(15000)) .Effort(EffortLevel.High) .SystemPrompt("Solve this complex problem with careful analysis.") .Build(); ``` -------------------------------- ### SettingSources(params SettingSource[]) Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/options-builder.md Sets which sources to load settings from. ```APIDOC ## SettingSources(params SettingSource[]) ### Description Sets which sources to load settings from. ### Method `ClaudeAgentOptionsBuilder` ### Parameters * **sources** (SettingSource[]) - Required - An array of `SettingSource` values specifying where to load settings. ### Valid values * `SettingSource.User` * `SettingSource.Project` * `SettingSource.Local` ``` -------------------------------- ### McpStdioServerConfig Record Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/types.md Configuration for an stdio-based MCP server. Requires a command and optional arguments and environment variables. ```csharp public record McpStdioServerConfig { [JsonPropertyName("type")] public string Type => "stdio"; [JsonPropertyName("command")] public required string Command { get; init; } [JsonPropertyName("args")] public IReadOnlyList? Args { get; init; } [JsonPropertyName("env")] public IReadOnlyDictionary? Env { get; init; } } ``` -------------------------------- ### ClaudeSDKClient Constructor Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/sdk-client.md Initializes a new instance of the ClaudeSDKClient. Configuration options and custom transport can be provided. The client requires ConnectAsync() to be called before use and should be disposed properly. ```APIDOC ## ClaudeSDKClient Constructor ### Description Initializes a new instance of the ClaudeSDKClient. Configuration options and custom transport can be provided. The client requires ConnectAsync() to be called before use and should be disposed properly. ### Signature ```csharp public ClaudeSDKClient(ClaudeAgentOptions? options = null, ITransport? transport = null) ``` ### Parameters #### Parameters - **options** (`ClaudeAgentOptions?`) - Optional - Configuration options for the client. - **transport** (`ITransport?`) - Optional - Custom transport implementation (advanced use). ### Remarks Creates a new client instance. The client is not connected until `ConnectAsync()` is called. The client implements `IAsyncDisposable` and should be used with `await using` or disposed explicitly. ### Example ```csharp using Claude.AgentSdk; await using var client = new ClaudeSDKClient(); await client.ConnectAsync(); // Use client for bidirectional conversation ``` ``` -------------------------------- ### McpServerRegistry.AddSdk Source: https://github.com/0xeb/claude-agent-sdk-dotnet/blob/main/_autodocs/api-reference/mcp-sdk.md Adds an in-process ("sdk") MCP server to the registry. This method allows for the configuration of a new MCP server using a provided builder callback. ```APIDOC ## McpServerRegistry.AddSdk ### Description Adds an in-process ("sdk") MCP server. This method allows for the configuration of a new MCP server using a provided builder callback. ### Method `McpServerRegistry.AddSdk(string serverName, Action configure)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp .McpServers(m => m .AddSdk("calculator", s => s .Tool("add", (double a, double b) => a + b, "Add two numbers") .Tool("multiply", (double a, double b) => a * b, "Multiply two numbers"))) ``` ### Response #### Success Response - **McpServerRegistry** (McpServerRegistry) - Returns the McpServerRegistry instance for fluent chaining. ```