ClaudeCodeWrapper 1.1.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package ClaudeCodeWrapper --version 1.1.1
NuGet\Install-Package ClaudeCodeWrapper -Version 1.1.1
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="ClaudeCodeWrapper" Version="1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ClaudeCodeWrapper" Version="1.1.1" />
<PackageReference Include="ClaudeCodeWrapper" />
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 ClaudeCodeWrapper --version 1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ClaudeCodeWrapper, 1.1.1"
#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 ClaudeCodeWrapper@1.1.1
#: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=ClaudeCodeWrapper&version=1.1.1
#tool nuget:?package=ClaudeCodeWrapper&version=1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ClaudeCodeWrapper
C# wrapper for Claude Code CLI.
Requirements
- .NET 8.0+
- Claude Code CLI installed (
npm install -g @anthropic-ai/claude-code)
Installation
dotnet add package ClaudeCodeWrapper
Quick Start
using ClaudeCodeWrapper;
// Initialize
var claude = ClaudeCode.Initialize();
// Send a message
var response = await claude.SendAsync("Hello Claude!");
Usage
With Options
var claude = ClaudeCode.Initialize(new ClaudeCodeOptions
{
Model = "sonnet",
WorkingDirectory = "/path/to/project",
SystemPrompt = "You are a helpful assistant",
PermissionMode = PermissionMode.AcceptEdits
});
Stream Activities
Monitor tool calls and results in real-time:
var response = await claude.StreamWithResponseAsync(
"Refactor this code",
activity => Console.WriteLine($"[{activity.Type}] {activity.Tool}: {activity.Summary}")
);
With Metrics
var response = await claude.SendWithResponseAsync("Explain this code");
Console.WriteLine($"Response: {response.Content}");
Console.WriteLine($"Tokens: {response.Tokens?.Input} in, {response.Tokens?.Output} out");
Console.WriteLine($"Session: {response.SessionId}");
Session Management
// Resume a previous session
var response = await claude.ResumeAsync("session-id", "Continue...");
// Continue the last session
var response = await claude.ContinueAsync("What were we discussing?");
Permission Modes
| Mode | Description |
|---|---|
PermissionMode.Default |
Standard - asks permission for writes |
PermissionMode.Plan |
Read-only, no modifications |
PermissionMode.AcceptEdits |
Auto-accept file edits |
PermissionMode.BypassPermissions |
No permission prompts |
Usage Monitoring
Track your API usage limits:
var claude = ClaudeCode.Initialize(new ClaudeCodeOptions
{
EnableUsageMonitoring = true
});
// Get current usage
var usage = await claude.GetUsageAsync();
if (usage != null)
{
Console.WriteLine($"Session: {usage.FiveHour.Utilization}% used");
Console.WriteLine($"Weekly: {usage.SevenDay.Utilization}% used");
Console.WriteLine($"Resets: {usage.FiveHour.ResetsAt}");
}
// Check if within limits
if (await claude.IsWithinLimitsAsync(sessionThreshold: 90, weeklyThreshold: 80))
{
await claude.SendAsync("Safe to send!");
}
Error Handling
The wrapper throws specific exceptions for rate limit errors:
try
{
var response = await claude.SendAsync(prompt);
}
catch (RateLimitException ex)
{
// HTTP 429 - Rate limit exceeded
Console.WriteLine($"Rate limited: {ex.Message}");
Console.WriteLine($"Request ID: {ex.RequestId}");
// Implement your own retry logic
}
catch (OverloadedException ex)
{
// HTTP 529 - API overloaded
Console.WriteLine($"API overloaded, retry after: {ex.RetryAfter}");
}
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- System.Reactive (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.1.1: Fixed path sanitization bug in SessionMonitor - underscore characters are now properly replaced with dashes to match Claude CLI behavior.