r/opencode • • 14d ago

OpenCode .NET SDK reached 1.0.x

I've been working on an unofficial .NET SDK for OpenCode for the last few months, and 1.0.x is now available on NuGet.

https://www.nuget.org/packages/OpenCodeDotNet.Sdk/1.0.1

It supports modern .NET as well as .NET Framework 4.7.2, with packages targeting netstandard2.0, net472, net10.0, and net11.0. The modern targets also support Native AOT.

There are a few small applications under playground showing different ways of using it, including a minimal QuickStart, a Worker using the Generic Host, a Blazor/Aspire example, and a Native AOT CLI..NET agent tooling

A basic example is roughly:

using OpenCode.Sdk;
using OpenCode.Sdk.Models;

await using var server = await OpenCodeServer.StartAsync();
using var client = server.CreateClient();

var created = await client.Sessions.CreateSessionAsync(new SessionCreateRequest
{
    Model = new ModelRef { ProviderId = "openai", Id = "gpt-6.1-sol" },
});
var currentSession = client.Sessions.GetSessionClient(created.Session.Id);

// Subscribe before prompting; the first event (server.connected) confirms the stream is live.
await using var events = client.Events.SubscribeAsync().GetAsyncEnumerator();
await events.MoveNextAsync();

await currentSession.PromptAsync(new SessionPromptRequest { Text = "Summarize this repository." });

while (await events.MoveNextAsync() && events.Current is not (SessionExecutionSucceeded or SessionExecutionFailed))
{
    if (events.Current is SessionTextDelta delta)
    {
        Console.Write(delta.Data.Delta);
    }
}

The SDK can start its own private OpenCode server like above, connect to one you already run, or discover the background service registered by the OpenCode CLI.

https://github.com/opencode-dotnet/opencode-sdk-dotnet

Feedback is very welcome, especially from anyone already experimenting with agent tooling from .NET.

3 Upvotes

0 comments sorted by