rea
Reverse engineer anything with agents, from app behavior down to native binaries.
- 470k
- TypeScript
- MIT
- 5 h ago
CLI-first .NET / C# SDK for Claude Code CLI with typed thread API, streamed JSONL events, structured outputs
Repo managedcode/ClaudeCodeSharpSDK, read from GitHub 1 min ago. managedcode has not joined Take My Repo.
managedcode/ClaudeCodeSharpSDK is a public repo on GitHub by managedcode. CLI-first .NET / C# SDK for Claude Code CLI with typed thread API, streamed JSONL events, structured outputs. It declares the MIT license on GitHub. It is written mainly in C#, has 1 stars and last changed on 2026-11-01. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-20.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
ManagedCode.ClaudeCodeSharpSDK is a .NET SDK for driving the Claude Code CLI from C#.
It is intentionally CLI-first. The library does not reimplement Anthropic APIs or invent its own transport. It wraps the local claude binary, runs Claude Code in print mode, and maps the emitted protocol into typed C# models.
ClaudeClient / ClaudeThread API for start, resume, run, and stream workflowsclaude -pstream-json eventsStructuredOutputSchemaMicrosoft.Extensions.AI adapter packageanthropics/claude-codeThis SDK follows the real Claude Code CLI contract in print mode:
claude -p --output-format jsonclaude -p --output-format stream-json --verboseIf the docs in this repository and the observed CLI behavior ever diverge, the observed CLI behavior wins and the SDK should be updated to match.
Upstream tracking is built into the repo:
submodules/anthropic-claude-code.github/workflows/claude-cli-watch.ymlCore SDK:
dotnet add package ManagedCode.ClaudeCodeSharpSDK
Optional Microsoft.Extensions.AI adapter:
dotnet add package ManagedCode.ClaudeCodeSharpSDK.Extensions.AI
Optional Microsoft Agent Framework adapter:
dotnet add package ManagedCode.ClaudeCodeSharpSDK.Extensions.AgentFramework --prerelease
Before using the SDK, you need:
claude installed and available in PATH, or configured via ClaudeOptions.ClaudeExecutablePathQuick sanity check:
claude --version
claude --help
claude -p --output-format json --dangerously-skip-permissions --no-session-persistence "Reply with ok only."using ManagedCode.ClaudeCodeSharpSDK.Client; using var client = new ClaudeClient(); using var thread = client.StartThread(); var result = await thread.RunAsync("Diagnose failing tests and propose a fix."); Console.WriteLine(result.FinalResponse); Console.WriteLine($"Items: {result.Items.Count}");
ClaudeClient auto-starts by default. If you want explicit lifecycle control, create it with AutoStart = false and call StartAsync() yourself.
ClaudeClient owns executable discovery, lifecycle, and metadata queries:
StartThread()ResumeThread(sessionId)GetCliMetadata()GetCliUpdateStatus()ClaudeThread represents one Claude Code conversation/session:
RunAsync(...) returns the final response plus collected itemsRunStreamedAsync(...) exposes the parsed event streamAt runtime the SDK executes Claude Code in print mode and parses stream-json output. It does not maintain a separate protocol implementation.
using ManagedCode.ClaudeCodeSharpSDK.Client; using ManagedCode.ClaudeCodeSharpSDK.Models; using var client = new ClaudeClient(); using var thread = client.StartThread(); var streamed = await thread.RunStreamedAsync("Implement the fix."); await foreach (var evt in streamed.Events) { switch (evt) { case ItemCompletedEvent completed: Console.WriteLine($"Item: {completed.Item.Type}"); break; case TurnCompletedEvent done: Console.WriteLine(done.Result); Console.WriteLine($"Output tokens: {done.Usage.OutputTokens}"); break; } }
using System.Text.Json.Serialization; using ManagedCode.ClaudeCodeSharpSDK.Client; using ManagedCode.ClaudeCodeSharpSDK.Models; public sealed record RepositorySummary(string Summary, string Status); [JsonSerializable(typeof(RepositorySummary))] internal sealed partial class AppJsonContext : JsonSerializerContext; var schema = StructuredOutputSchema.Map<RepositorySummary>( additionalProperties: false, (response => response.Summary, StructuredOutputSchema.PlainText()), (response => response.Status, StructuredOutputSchema.PlainText())); using var client = new ClaudeClient(); using var thread = client.StartThread(); var result = await thread.RunAsync( "Summarize the repository status as JSON.", schema, AppJsonContext.Default.RepositorySummary); Console.WriteLine(result.TypedResponse.Status); Console.WriteLine(result.TypedResponse.Summary);
If you want full turn control, use TurnOptions:
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(30)); var result = await thread.RunAsync( "Summarize the repository status as JSON.", AppJsonContext.Default.RepositorySummary, new TurnOptions { OutputSchema = schema, CancellationToken = timeout.Token, });
Notes:
TurnOptions.OutputSchema or a direct outputSchema overloadJsonTypeInfo<T> overloads are the AOT-safe pathusing ManagedCode.ClaudeCodeSharpSDK.Client; using var client = new ClaudeClient(); using var thread = client.ResumeThread("existing-session-id"); var result = await thread.RunAsync("Continue from the previous plan."); Console.WriteLine(result.FinalResponse);
Claude Code persists SDK print-mode sessions by default. Unless you set NoSessionPersistence = true, the session transcript is written under ~/.claude/projects/.../<session-id>.jsonl and can be resumed later by session id.
claude --resume <session-id>
Claude stores those sessions in project-scoped directories derived from the working directory, so external CLI/App resume should use the same WorkingDirectory or project that created the session. The SDK guarantees persistence and resume-by-id; whether a non-interactive -p session is shown in the default Claude history/resume picker is controlled by the Claude CLI/App itself.
ManagedCode.ClaudeCodeSharpSDK.Extensions.AgentFramework is a thin Microsoft Agent Framework package over the existing ClaudeChatClient.
It is currently published as a prerelease package because the upstream Microsoft.Agents.AI dependency is still prerelease.
using ManagedCode.ClaudeCodeSharpSDK.Extensions.AI; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; IChatClient chatClient = new ClaudeChatClient(); AIAgent agent = chatClient.AsAIAgent( name: "ClaudeAssistant", instructions: "You are a concise coding assistant."); var response = await agent.RunAsync("What changed in this repository?"); Console.WriteLine(response.Text);
DI registration:
using ManagedCode.ClaudeCodeSharpSDK.Extensions.AgentFramework.Extensions; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; builder.Services.AddClaudeCodeAgent( configureAgent: options => { options.Name = "ClaudeAssistant"; options.ChatOptions = new ChatOptions { Instructions = "You are a concise coding assistant." }; }); app.MapGet("/agent", async (AIAgent agent) => { var response = await agent.RunAsync("Summarize the repository"); return response.ToString(); });
Keyed DI registration:
using ManagedCode.ClaudeCodeSharpSDK.Extensions.AgentFramework.Extensions; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; using Microsoft.Extensions.DependencyInjection; var services = new ServiceCollection(); services.AddKeyedClaudeCodeAgent( "claude-main", configureAgent: options => { options.Name = "ClaudeAssistant"; options.ChatOptions = new ChatOptions { Instructions = "You are a concise coding assistant." }; }); using var provider = services.BuildServiceProvider(); var keyedAgent = provider.GetRequiredKeyedService<AIAgent>("claude-main");
This package builds on the existing IChatClient adapter, so the canonical MAF path remains IChatClient.AsAIAgent(...); the Claude-specific package adds a supported package boundary and DI convenience methods.
Current limitations are the same as the underlying ClaudeChatClient adapter:
ClaudeChatClient updates rather than token-level deltasThreadOptions maps the Claude Code flags currently supported by this SDK.
using ManagedCode.ClaudeCodeSharpSDK.Client; using ManagedCode.ClaudeCodeSharpSDK.Models; var options = new ThreadOptions { Model = ClaudeModels.ClaudeOpus45, PermissionMode = PermissionMode.AcceptEdits, AllowedTools = ["Read", "Write", "Edit"], DisallowedTools = ["Bash"], AdditionalDirectories = ["/workspace", "/tmp"], SystemPrompt = "Be concise and explicit about risk.", AppendSystemPrompt = "Prefer concrete file paths in explanations.", MaxBudgetUsd = 0.50m, NoSessionPersistence = true, AdditionalCliArguments = ["--some-future-flag", "custom-value"], }; using var thread = client.StartThread(options);
Not every flag in the upstream CLI is necessarily surfaced yet, but unsupported future non-transport flags can still be passed through AdditionalCliArguments. SDK-managed transport flags such as --print, --output-format, --input-format, and --json-schema are reserved and rejected if passed through manually.
using System.Linq; using ManagedCode.ClaudeCodeSharpSDK.Client; using var client = new ClaudeClient(); var metadata = client.GetCliMetadata(); Console.WriteLine($"Installed Claude Code: {metadata.InstalledVersion}"); Console.WriteLine($"Default model: {metadata.DefaultModel}"); foreach (var model in metadata.Models.Where(model => model.IsListed)) { Console.WriteLine(model.Slug); } var update = client.GetCliUpdateStatus(); if (update.IsUpdateAvailable) { Console.WriteLine(update.UpdateMessage); Console.WriteLine(update.UpdateCommand); }
Current metadata support includes:
claude --versionsonnetanthropics/claude-codeusing ManagedCode.ClaudeCodeSharpSDK.Client; using ManagedCode.ClaudeCodeSharpSDK.Configuration; using Microsoft.Extensions.Logging; public sealed class ConsoleClaudeLogger : ILogger { public IDisposable BeginScope<TState>(TState state) where TState : notnull => NullScope.Instance; public bool IsEnabled(LogLevel logLevel) => true; public void Log<TState>( LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) { Console.WriteLine($"[{logLevel}] {formatter(state, exception)}"); if (exception is not null) { Console.WriteLine(exception); } } private sealed class NullScope : IDisposable { public static NullScope Instance { get; } = new(); public void Dispose() { } } } using var client = new ClaudeClient(new ClaudeOptions { Logger = new ConsoleClaudeLogger(), });
LocalImageInput exists in the model layer but is rejected in the current Claude print-mode implementationTurnOptions.ReplayUserMessages is reserved for future stream-json input support and currently throwsMicrosoft.Extensions.AI adapter is text-first and does not expose custom Claude internal item typesChatOptions.Tools is ignored because Claude Code manages tools internallyusing Microsoft.Extensions.AI; using ManagedCode.ClaudeCodeSharpSDK.Extensions.AI; IChatClient client = new ClaudeChatClient(); var response = await client.GetResponseAsync( [ new ChatMessage(ChatRole.User, "Summarize the repository."), ]); Console.WriteLine(response.Text);
Streaming:
await foreach (var update in client.GetStreamingResponseAsync( [ new ChatMessage(ChatRole.User, "Implement the fix."), ])) { Console.Write(update.Text); }
Claude-specific options flow through ChatOptions.AdditionalProperties:
using ManagedCode.ClaudeCodeSharpSDK.Client; using Microsoft.Extensions.AI; var options = new ChatOptions { AdditionalProperties = new AdditionalPropertiesDictionary { ["claude:working_directory"] = "/workspace", ["claude:permission_mode"] = PermissionMode.AcceptEdits, ["claude:allowed_tools"] = new[] { "Read", "Write" }, ["claude:max_budget_usd"] = 0.25m, }, };
See:
Clone with submodules:
git clone https://github.com/managedcode/ClaudeCodeSharpSDK.git
cd ClaudeCodeSharpSDK
git submodule update --init --recursiveBuild and test:
dotnet build ManagedCode.ClaudeCodeSharpSDK.slnx -c Release -warnaserror
dotnet test --solution ManagedCode.ClaudeCodeSharpSDK.slnx -c ReleaseSmoke-only subset:
dotnet test --project ClaudeCodeSharpSDK.Tests/ClaudeCodeSharpSDK.Tests.csproj -c Release --no-build -- --treenode-filter "/*/*/*/ClaudeCli_Smoke_*"
Streaming enables native partial messages by default and exposes text deltas through the core SDK and MEAI adapter. Text/tool/text blocks sharing one message ID continue normally; final snapshots do not duplicate streamed text. The CLI release target is 2.1.308.
The SDK can start native CLI sign-in and return the browser URL for your user. Keep the returned session alive until sign-in finishes.
await using var login = await client.BeginLoginAsync(cancellationToken); var instructions = login.Instructions; if (instructions is not null) { Console.WriteLine(instructions.LoginUrl); Console.WriteLine(instructions.UserCode); } while (instructions?.RequiresAuthorizationCode == true) { var code = Console.ReadLine() ?? throw new InvalidOperationException("Authorization code required."); instructions = await login.SubmitAuthorizationCodeAsync(code, cancellationToken); if (instructions is not null) { Console.WriteLine(instructions.LoginUrl); } } await login.WaitForCompletionAsync(cancellationToken);
CancelAsync or disposal terminates unfinished sign-in. Cancelling a completion wait leaves native sign-in running. Credentials stay in the selected CLI profile; select a separate profile for each server user and reuse it for agent execution. See native sign-in for retry, cancellation and profile details.
managedcode/ClaudeCodeSharpSDK is a public repo on GitHub by managedcode. CLI-first .NET / C# SDK for Claude Code CLI with typed thread API, streamed JSONL events, structured outputs.
It declares the MIT license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-11-01. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
A powerful GUI app and Toolkit for Claude Code - Create custom agents, manage interactive Claude Code sessions, run secure background agents, and more.
The Free Software Media System - Server Backend & API
Build infinite canvas apps in React with the tldraw SDK. World's best, top-most agent recommended #1 five star SDK.

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
Vercel AI SDK community provider for Claude Agent SDK

One of the largest .NET-focused skill collections for AI coding assistants, with a catalog, CLI, and orchestration agents for Codex, Claude Code, GitHub Copilot, Gemini, and Junie.

Storage library provides a universal interface for accessing and manipulating data in different cloud blob storage providers
Result pattern for .NET that replaces exceptions with type-safe return values. Features railway-oriented programming, ASP.NET Core integration, RFC 7807 Problem Details, and built-in pagination. Designed for production systems requiring explicit error handling without the overhead of throwing exceptions.
MCAF is a framework for building software products together with AI coding agents.
Browser-first teleprompter, rehearsal, and live presentation studio built with .NET 10 and Blazor WebAssembly.
Orleans.SignalR is a lightweight, open-source library that enables easy integration of SignalR with Orleans, a distributed virtual actor model framework for building scalable, fault-tolerant systems. The library provides a SignalR backplane, allowing you to effortlessly add real-time communication capabilities to your distributed systems.
Take My Repo has not tested this on your machine. Requirements come from the project's own documentation.