SharpCoder 0.4.0-alpha.2

This is a prerelease version of SharpCoder.
There is a newer version of this package available.
See the version list below for details.
dotnet add package SharpCoder --version 0.4.0-alpha.2
                    
NuGet\Install-Package SharpCoder -Version 0.4.0-alpha.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SharpCoder" Version="0.4.0-alpha.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SharpCoder" Version="0.4.0-alpha.2" />
                    
Directory.Packages.props
<PackageReference Include="SharpCoder" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SharpCoder --version 0.4.0-alpha.2
                    
#r "nuget: SharpCoder, 0.4.0-alpha.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SharpCoder@0.4.0-alpha.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SharpCoder&version=0.4.0-alpha.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=SharpCoder&version=0.4.0-alpha.2&prerelease
                    
Install as a Cake Tool

SharpCoder

NuGet License: MIT

A standalone, embeddable autonomous coding agent for .NET — built on Microsoft.Extensions.AI.

SharpCoder gives any IChatClient (OpenAI, Ollama, Azure, Anthropic, etc.) the ability to read files, write code, search codebases, and execute shell commands autonomously. Plug it into your app with a few lines of code.

Features

  • Provider-agnostic — works with any IChatClient implementation
  • Built-in tools — file read/write/edit, glob, grep, bash, and skills
  • Persistent sessions — multi-turn conversations with save/load to JSON
  • StreamingIAsyncEnumerable<StreamingUpdate> for real-time token delivery
  • Auto-compaction — summarizes old context to stay within token limits
  • Security by default — path traversal protection, bash disabled by default
  • Workspace-aware — auto-loads AGENTS.md and .github/copilot-instructions.md
  • Rich results — token usage, tool call count, full message history, diagnostics
  • Targets netstandard2.1 — runs on .NET Core 3+, .NET 5–10, and beyond

Quick Start

dotnet add package SharpCoder
using Microsoft.Extensions.AI;
using SharpCoder;

// Use any IChatClient — OpenAI, Ollama, Azure, etc.
IChatClient chatClient = new OllamaChatClient("http://localhost:11434", "qwen2.5-coder");

var agent = new CodingAgent(chatClient, new AgentOptions
{
    WorkDirectory = "/path/to/your/project",
    MaxSteps = 15
});

var result = await agent.ExecuteAsync("Add unit tests for the Calculator class");

Console.WriteLine($"Status: {result.Status}");
Console.WriteLine($"Tool calls: {result.ToolCallCount}");
Console.WriteLine($"Tokens used: {result.Usage?.TotalTokenCount}");
Console.WriteLine(result.Message);

Sessions

Sessions provide persistent, multi-turn conversations. The agent remembers prior turns and builds on them:

var session = AgentSession.Create();

// Turn 1 — agent reads the codebase
await agent.ExecuteAsync(session, "Read the Calculator class and understand it");

// Turn 2 — agent remembers what it read
await agent.ExecuteAsync(session, "Now add tests for the edge cases you found");

// Save session to disk for crash recovery
await session.SaveAsync("session.json");

// Load a saved session later
var restored = await AgentSession.LoadAsync("session.json");
await agent.ExecuteAsync(restored, "What did we do so far?");

Sessions track cumulative token usage, tool call counts, and estimated context size.

Streaming

Stream text tokens as they arrive instead of waiting for the full response:

await foreach (var update in agent.ExecuteStreamingAsync(session, "Refactor the Parser class"))
{
    switch (update.Kind)
    {
        case StreamingUpdateKind.TextDelta:
            Console.Write(update.Text); // incremental text chunk
            break;
        case StreamingUpdateKind.Completed:
            Console.WriteLine($"\nDone: {update.Result!.Status}");
            break;
    }
}

Streaming uses the same tool invocation pipeline as ExecuteAsync — tools execute transparently between text chunks. The session is persisted after the stream completes.

Configuration

All behavior is controlled through AgentOptions:

var options = new AgentOptions
{
    // Where the agent operates (default: current directory)
    WorkDirectory = "/my/project",

    // Max tool call iterations before stopping (default: 25)
    MaxSteps = 25,

    // Enable shell command execution (default: false — security risk!)
    EnableBash = false,

    // File system tools (default: true)
    EnableFileOps = true,
    EnableFileWrites = true,

    // Skill loading from .github/skills/ (default: true)
    EnableSkills = true,

    // Override the default system prompt
    SystemPrompt = "You are a test-writing expert.",

    // Append custom instructions to the system prompt
    CustomInstructions = "Always use xUnit. Prefer Arrange-Act-Assert.",

    // Auto-load AGENTS.md and copilot-instructions.md (default: true)
    AutoLoadWorkspaceInstructions = true,

    // Add your own custom AITools
    CustomTools = new List<AITool>
    {
        AIFunctionFactory.Create(MyCustomTool)
    },

    // Context management
    MaxContextTokens = 100_000,   // model's context window
    CompactionThreshold = 0.8,    // compact at 80% usage
    CompactionRetainRecent = 10,  // keep last 10 messages verbatim
    EnableAutoCompaction = true,  // enabled by default

    // Optional: reasoning effort for models with extended thinking
    ReasoningEffort = ReasoningEffort.Medium,

    // Optional: callback when context is compacted
    OnCompacted = result =>
        Console.WriteLine($"Compacted {result.TokensBefore} → {result.TokensAfter} tokens")
};

Built-in Tools

Tool Description Enabled by
read_file Read file contents with line numbers and pagination EnableFileOps
write_file Create or overwrite files EnableFileWrites
edit_file Exact string replacement (single occurrence) EnableFileWrites
glob Find files by pattern (e.g. src/**/*.cs) EnableFileOps
grep Search file contents with regex EnableFileOps
execute_bash_command Run shell commands EnableBash
list_skills / load_skill Discover and load project skills EnableSkills

Agent Result

ExecuteAsync and ExecuteStreamingAsync return an AgentResult with:

result.Status        // "Success", "MaxStepsReached", or "Error"
result.Message       // Final text response from the agent
result.Messages      // Full conversation history (all messages, tool calls, results)
result.ToolCallCount // Number of tool invocations made
result.ModelId       // Model that produced the response
result.FinishReason  // Why the model stopped (e.g. Stop, Length, ToolCalls)
result.Usage         // Token counts (InputTokenCount, OutputTokenCount, TotalTokenCount)
result.Diagnostics   // Snapshot of everything sent to the LLM (system prompt, tools, etc.)

Context Compaction

Long-running sessions can exceed model context limits. SharpCoder automatically compacts conversation history by summarizing older messages while preserving recent context:

  • Triggered when estimated tokens exceed CompactionThreshold × MaxContextTokens
  • Older messages are summarized into a single [CONTEXT SUMMARY] message
  • Recent messages (count controlled by CompactionRetainRecent) are kept verbatim
  • Key decisions, findings, and file paths are preserved in the summary

Disable with EnableAutoCompaction = false if you manage context manually.

Skills

The agent can discover and load project-specific skills from .github/skills/. Each skill is a Markdown file with YAML frontmatter:

---
name: build
description: How to build this project
---

# Build Instructions

Run `dotnet build` to compile the solution.

The agent calls list_skills to discover what's available and load_skill to read the full instructions.

Security

  • Path traversal protection — all file operations are confined to WorkDirectory
  • Bash disabled by default — opt in explicitly with EnableBash = true
  • No sandboxing for bash — when enabled, the agent has full shell access with the process's privileges. Only enable in trusted environments (containers, CI runners)

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.7.0 0 4/2/2026
0.7.0-beta.44 0 4/2/2026
0.7.0-beta.43 0 4/2/2026
0.6.0 135 3/31/2026
0.6.0-beta-beta.36 35 3/30/2026
0.6.0-beta-beta.35 42 3/30/2026
0.6.0-beta.42 27 3/31/2026
0.6.0-beta.40 30 3/31/2026
0.6.0-beta.39 25 3/31/2026
0.6.0-beta.38 29 3/31/2026
0.6.0-beta.37 151 3/30/2026
0.5.1-beta.34 40 3/29/2026
0.5.0 247 3/29/2026
0.5.0-beta.32 40 3/29/2026
0.5.0-beta.31 184 3/28/2026
0.4.4 94 3/26/2026
0.4.3 43 3/26/2026
0.4.2 43 3/25/2026
0.4.1 40 3/25/2026
0.4.0-alpha.2 37 3/25/2026
Loading failed