r/moderndotnet • • 23d 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/moderndotnet/comments/1wg1r6g/net_sdk_for_opencodes_server_api/

For anyone unfamiliar with OpenCode, it's an open-source coding agent/harness with a server API underneath its TUI, desktop, and web clients. That API lets you use OpenCode more like an agent runtime from another application.

That was why I started working on the .NET SDK.

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:

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

var created = await client.Sessions.CreateSessionAsync(
    new SessionCreateRequest { Title = "hello from .NET" });

Console.WriteLine($"session {created.Session.Id}");

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

23 Upvotes

3 comments sorted by

2

u/Anon4573 23d ago

How is this useful compared to using the agent client protocol?

2

u/denizirgin 21d ago

Hey u/Anon4573 ,

If your goal is to use OpenCode from an ACP-compatible editor/client, I'd use ACP. For example, I'm already using it with JetBrains Rider IDE

I see the SDK at a different level. ACP gives you a common protocol to talk to coding agents, while the SDK gives you direct access to OpenCode's server API and OpenCode-specific features.

So roughly:

ACP -> portable agent protocol
SDK -> OpenCode as an application/runtime API

If ACP covers your use case, it's probably the simpler choice. The SDK is more useful when you need the OpenCode-specific surface underneath it.

for example: https://www.reddit.com/r/dotnet/comments/1xpqe1g/comment/19sde1ee127cw/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button

2

u/goqsane 23d ago

It’s not.