SharpClawCode Architecture Explained: A Native C# AI Coding Agent Runtime for .NET 10

[AI Readability Summary] SharpClawCode is a native C# coding agent runtime built for .NET 10 and C# 13. It addresses the lack of an engineered AI coding runtime in the .NET ecosystem with persistent sessions, permission controls, and MCP extensibility. Keywords: .NET 10, Coding Agent, MCP.

The technical specification snapshot is straightforward

Parameter Description
Language C# 13
Runtime .NET 10
Protocols MCP, ACP, OpenAI Compatible, Anthropic API
Core Positioning Native C# coding agent runtime
Session Storage FileSystem, SQLite, NDJSON event log
Core Dependencies System.Text.Json, System.CommandLine, Microsoft Agent Framework, ModelContextProtocol
Key Capabilities Persistent sessions, event sourcing, permission approvals, plugin system, structured telemetry
Repository https://github.com/clawdotnet/SharpClawCode

SharpClawCode fills a critical AI engineering gap in .NET

SharpClawCode is not just “an AI SDK wrapped for C#”. It treats the coding agent itself as a runtime abstraction. It targets long-running, recoverable, auditable, and embeddable development infrastructure rather than one-off scripts.

Compared with the ad hoc script-based approaches common in Python and TypeScript ecosystems, this project places much more emphasis on state management, permission boundaries, and enterprise deployment readiness. Its vision can be summarized simply: rebuild a Claude Code–style engineered coding agent platform in C#.

This architecture is better suited for enterprise adoption

It builds cross-cutting capabilities directly into the platform, including durable sessions, approval workflows, telemetry, plugins, and multi-model adaptation. Developers do not need to rebuild these foundations repeatedly. They can focus on extending business-specific functionality.

var host = new SharpClawRuntimeHostBuilder()
    .UseModelProvider("anthropic") // Configure the default model provider
    .UseSessionStore("sqlite") // Configure persistent session storage
    .UsePermissionMode("workspaceWrite") // Set the default permission mode
    .Build();

This code illustrates the core value of SharpClawCode as a host SDK: it builds an embeddable runtime through explicit configuration.

It uses a clear layered architecture to control complexity

The protocol layer, SharpClaw.Code.Protocol, defines DTOs, events, enums, and command result contracts. One of its standout characteristics is that it has zero NuGet dependencies and uses System.Text.Json source-generated contexts to balance type safety, performance, and NativeAOT compatibility.

The infrastructure layer encapsulates the file system, path handling, and shared helper components. This design works especially well with Windows path security behavior and also makes it easier to swap in an in-memory file system during testing.

The runtime layer is the core scheduler of the entire system

ConversationRuntime manages the session state machine, while DefaultTurnRunner orchestrates single-turn execution. Together with ISessionStore, IModelProvider, IToolRegistry, and IPermissionPolicyEngine, they form a complete execution loop.

var result = await turnRunner.RunAsync(input, cancellationToken); // Execute a single conversation turn
if (!result.Success)
{
    logger.LogWarning("turn failed: {Reason}", result.Error); // Log the failure reason
}

This invocation shows the primary entry point for conversation turns: input, execution, diagnostics, and failure recovery all converge into one unified flow.

Persistent sessions and event sourcing are its most distinctive capabilities

SharpClawCode stores session state as an immutable event stream instead of saving only the latest snapshot. User messages, model responses, tool executions, and approval decisions are all appended as NDJSON records, creating a recoverable and auditable historical chain.

The value of this model is immediate: the system can replay events after a restart to restore state, operators can trace any tool invocation, and teams can treat the conversation itself as a collaborative asset rather than ephemeral context.

The snapshot mechanism further reduces recovery cost

When the event stream grows too long, the system uses snapshots to shorten the recovery path. It only needs to load the latest snapshot and replay incremental events. This preserves full history while avoiding startup latency in long-running sessions.

{"event":"UserMessageAdded","sessionId":"s-001"}
{"event":"ToolCallRequested","tool":"file_write"}
{"event":"ApprovalGranted","mode":"workspaceWrite"}

This kind of NDJSON event log is suitable both for programmatic consumption and for manual auditing or integration with external logging systems.

Permission-aware tool execution is the key to production readiness

SharpClawCode divides permissions into levels such as readOnly, workspaceWrite, and dangerFullAccess, and applies unified policy decisions through IPermissionPolicyEngine. High-risk operations such as file writes, shell execution, and network access do not pass straight through without control.

At the same time, it introduces IApprovalService and session-level approval memory. Similar operations that have already been approved can avoid repeated prompts, but once the approval budget is exhausted, the flow returns to human review. This design balances efficiency and safety.

The tool system and MCP ecosystem provide strong extensibility

The tool framework is built around IToolRegistry and IToolExecutor, with built-in capabilities for files, shell commands, Git, and code analysis. External tools can connect through plugins or MCP servers and still flow through the same permission pipeline.

SharpClaw.Code.Mcp further closes the gap with Model Context Protocol compatibility by supporting stdio/SSE connections, tool discovery, health checks, and lifecycle orchestration. That means SharpClawCode can plug directly into the rapidly growing MCP tooling ecosystem.

Multi-model abstraction prevents vendor lock-in

The project uses IModelProvider to provide a unified abstraction over Anthropic, OpenAI-compatible endpoints, and local model backends. Upper layers do not need to care whether the underlying call goes to Claude, GPT, or Ollama. They only care whether the required capability is available.

This kind of decoupling is critical for enterprise teams. It enables cost and performance switching on one side, while allowing model selection based on data sensitivity on the other. It is especially valuable for teams that need offline coding, private deployment, or hybrid inference.

services.AddSingleton<IModelProvider, OpenAiCompatibleProvider>(); // Register an OpenAI-compatible model provider
services.AddSingleton<IModelProvider, AnthropicProvider>(); // Or switch to a Claude provider

This provider registration pattern ensures that model integration affects only the adapter layer, not the upper runtime logic.

Structured telemetry gives it real operational visibility

SharpClawCode does not treat logs as plain strings. Instead, it defines runtime behavior as structured events. Through IRuntimeEventPublisher and a ring buffer, it can capture low-overhead records for sessions, tools, models, permissions, and system state changes.

This matters enormously in production: teams can use it for cost accounting, failure analysis, behavioral auditing, webhook export, and tenant-level metering. As a result, it stops being just a developer tool and becomes an AI runtime that can fit into a DevOps operating model.

It behaves more like a platform than a small AI utility

If all you need in .NET is to “call a large language model once,” SharpClawCode may feel heavy. But if your goal is to build a testable, extensible, observable, and governable coding agent system, its design density maps directly to long-term requirements.

Its greatest value is not any single feature. It is the way it unifies sessions, permissions, tools, models, plugins, telemetry, and host integration inside one native .NET runtime. That is exactly the missing layer in serious AI engineering for the .NET ecosystem.

WeChat sharing prompt

AI Visual Insight: This image is a blog platform sharing prompt animation that guides users to trigger WeChat sharing from the web page. It does not convey SharpClawCode architecture, runtime behavior, or interaction flow information, so it should not be treated as technical evidence for the project.

The FAQ section answers the most important implementation questions

FAQ 1: What is the biggest difference between SharpClawCode and ordinary AI scripting tools?

The biggest difference is that it is runtime-oriented. It provides persistent sessions, event sourcing, permission approvals, plugins, and telemetry instead of making one-off script calls to model APIs.

FAQ 2: Why is it more compelling for .NET teams?

Because it is built natively for .NET 10 and C# 13, supports dependency injection, NativeAOT, and System.Text.Json source generation, and can embed cleanly into existing .NET engineering systems.

FAQ 3: Which scenarios should adopt SharpClawCode first?

It is best suited for teams that need enterprise-grade AI coding infrastructure, such as IDE backends, automated code review, test generation platforms, private AI developer assistants, and multi-tenant coding services.

Core Summary: SharpClawCode is a native AI coding agent runtime for .NET 10 and C# 13. It provides persistent sessions, permission-aware tool execution, MCP integration, and structured telemetry, filling a major gap in engineered AI development infrastructure across the .NET ecosystem.