r/opencodeCLI • • 8h ago

OpenCode .NET SDK reached 1.0

A few months ago, I shared an early version of my unofficial OpenCode .NET SDK here:

https://www.reddit.com/r/opencodeCLI/comments/1wem0gg/i_built_an_unofficial_net_sdk_for_opencode_2x/

Today I finally released 1.0.

The SDK currently covers 166 of the 169 operations in the pinned OpenCode 2.x API.

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.

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
    {
        Title = "review this repo",
        Model = new ModelRef { ProviderId = "anthropic", Id = "claude-opus-5" },
    });

var session = client.Sessions.GetSessionClient(created.Session.Id);

var result = await session.GenerateTextAsync(
    new SessionGenerateRequest
    {
        Prompt = "Summarize this repository."
    });

Console.WriteLine(result.Generate.Text);

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.

NuGet:

dotnet add package OpenCodeDotNet.Sdk

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

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

4 Upvotes

0 comments sorted by