- Status: Accepted
- Date: 2026-03-05
ManagedCode.ClaudeCodeSharpSDK wraps the Claude Code CLI with a bespoke API surface (ClaudeClient/ClaudeThread/RunResult). The .NET ecosystem has standardized on Microsoft.Extensions.AI abstractions (IChatClient) for provider-agnostic AI integration with composable middleware pipelines.
Implement IChatClient from Microsoft.Extensions.AI.Abstractions in a separate NuGet package (ManagedCode.ClaudeCodeSharpSDK.Extensions.AI) that adapts the existing SDK types without modifying the core SDK.
-
Separate package — Core SDK remains M.E.AI-free. The adapter is opt-in, following the pattern of other provider-specific
Extensions.AIintegrations. -
Text-first adapter — The current adapter maps Claude chat usage to assistant text, usage, conversation ID, and streaming updates. It does not attempt to expose every Claude internal item type through custom
AIContentcontracts. -
Claude-specific options via
AdditionalProperties— StandardChatOptionsproperties (ModelId,ConversationId) map directly. Claude-unique features useclaude:*prefixed keys inChatOptions.AdditionalProperties(for exampleclaude:permission_mode,claude:allowed_tools,claude:max_budget_usd). -
Thread-per-call with
ConversationIdresume — EachGetResponseAsynccall creates or resumes aClaudeThread. Thread ID flows viaChatResponse.ConversationIdfor multi-turn continuity. -
No
AIToolsupport — Claude Code CLI manages tools internally. Consumer-registeredChatOptions.Toolsare ignored.
flowchart LR
Consumer["Consumer code\n(IChatClient)"]
Adapter["ClaudeChatClient\n(Extensions.AI)"]
Core["ClaudeClient\n(Core SDK)"]
CLI["claude -p --output-format stream-json"]
Consumer --> Adapter
Adapter --> Core
Core --> CLI
subgraph "M.E.AI Middleware (free)"
Logging["UseLogging()"]
Cache["UseDistributedCache()"]
Telemetry["UseOpenTelemetry()"]
end
Consumer -.-> Logging
Logging -.-> Cache
Cache -.-> Telemetry
Telemetry -.-> Adapter
- SDK participates in the .NET AI ecosystem: DI registration, middleware pipelines, provider swapping.
- Consumers get logging, caching, and telemetry for free via M.E.AI middleware.
- Adapter stays simple and aligned with the currently validated CLI print-mode contract.
- Impedance mismatch: Claude is an agentic coding tool, not a simple chat API. Multi-turn via message history does not map cleanly and instead uses thread resume.
- Image
DataContentis currently unsupported because the validated print-mode contract in this SDK is text-only. - Streaming is item-level, not token-level.
- Additional NuGet package to maintain.
ChatOptions.Toolsis a documented no-op.
- Implement
IChatClientdirectly in the core SDK: rejected to avoid a mandatory M.E.AI dependency. - Model the adapter as text-only over the validated print-mode contract: accepted for now because it matches the current supported SDK surface and is easy to evolve later.