---
title: "C#/.NET API Reference"
description: "Reference surface for the C#/.NET SDK. These APIs wrap the Autohand Code CLI JSON-RPC runtime while keeping host-language lifecycle and event handling idiomatic."
sidebar:
  label: "C#/.NET API"
seo:
  title: "C#/.NET API Reference | Autohand Code Agent SDK"
  description: "API reference for the C#/.NET Autohand Code Agent SDK."
---

:::note
**Source:** [autohandai/code-agent-sdk-csharp/docs/API\_REFERENCE.md](https://github.com/autohandai/code-agent-sdk-csharp/blob/main/docs/API_REFERENCE.md).
:::

## Install

```bash title=".NET"
dotnet add package Autohand.CodeAgentSdk
```

```bash title="Source"
# Until the NuGet package is published, reference the project or repository directly from your solution.
```

## `AutohandOptions` [#configuration]

Configuration sets the working directory, CLI binary path, debug output, request timeout, model override, skills, system prompt additions, and execution-mode flags.

```csharp
var options = new AutohandOptions
{
    WorkingDirectory = ".",
    Debug = true,
    RequestTimeout = TimeSpan.FromMinutes(5),
    Model = "fantail2",
};
```

## `AutohandSdk` [#low-level]

Use the low-level wrapper when you need direct JSON-RPC control.

- StartAsync() / StopAsync()
- RequestAsync(method, parameters)
- PromptAsync(message, options)
- StreamPromptAsync(message, options)
- InterruptAsync()
- SetPlanModeAsync(enabled)
- SetPermissionModeAsync(mode)
- SetModelAsync(model)
- GetStateAsync()
- GetMessagesAsync()
- PermissionResponseAsync(requestId, decision)

## `Agent`

The high-level agent API is the best fit for product code that sends prompts, streams events, and waits for final results.

```csharp
await using var agent = await Agent.CreateAsync(new AgentOptions
{
    WorkingDirectory = ".",
});

var run = agent.Send("Review the public API.");
var result = await run.WaitAsync();
```

- Agent.CreateAsync(options)
- Agent.FromSdk(sdk)
- Send(prompt, options)
- RunAsync(prompt, options)
- RunJsonAsync\<T\>(prompt, jsonOptions, promptOptions)
- AllowPermissionAsync(requestId)
- DenyPermissionAsync(requestId)
- SuggestPermissionAlternativeAsync(requestId, alternative)
- SetPlanModeAsync(enabled)

## Run

- StreamAsync(): stream events
- WaitAsync(): wait until the run finishes and collect text/events
- JsonAsync\<T\>(): parse final output as JSON
- AbortAsync(): interrupt the current run

## CLI 0.9.13 run options

Configure the CLI process through `AutohandOptions` before startup.

- `MaxRequests`, `MaxDurationSeconds` set the request budget and wall-clock limit in seconds.
- `AllowedTools`, `DisallowedTools` accept lists of tool patterns.
- `Profile`, `SettingOverrides` select a saved profile and apply ordered run-only overrides.
- `NoDaemon`, `SyncSettings`, `SearchEngine` control background services, settings synchronization, and web search.

Use `SdkEvent.Method` and `SdkEvent.Raw` to read original CLI notifications. See [run option semantics](/agent-sdk/concepts/cli-runtime-control#run-options) and [notification payloads](/agent-sdk/concepts/hooks-and-events#runtime-notifications).

## CLI Runtime Control

Core lifecycle and auto-mode operations are available on `Agent` and `AutohandSdk`. Use `AutohandSdk` for the complete approval, session, MCP, learning, tool-registry, and context surface.

- **Conversation and handoff:** `ResetAsync`, `CreateBrowserHandoffAsync`, `AttachBrowserHandoffAsync`, `AttachLatestBrowserHandoffAsync`
- **Auto-mode:** `StartAutoModeAsync`, `GetAutoModeStatusAsync`, `PauseAutoModeAsync`, `ResumeAutoModeAsync`, `CancelAutoModeAsync`, `GetAutoModeLogAsync`
- **Approvals and sessions:** `AcknowledgePermissionAsync`, `RespondDirectoryAccessAsync`, `AcknowledgeDirectoryAccessAsync`, `DecideChangesAsync`, `GetHistoryAsync`, `GetSessionAsync`, `AttachSessionAsync`
- **Integrations and context:** `SetYoloModeAsync`, `SetYoloModeAliasAsync`, `SetVscodeMcpToolsAsync`, `RespondMcpInvocationAsync`, `RecommendLearnAsync`, `UpdateLearnAsync`, `GenerateLearnAsync`, `GetToolsRegistryAsync`, `SetContextCompactAsync`

See [Control the CLI runtime](/agent-sdk/concepts/cli-runtime-control) for behavior, safety contracts, and the equivalent names in every CLI-backed SDK.

## SDK events [#events]

All CLI-backed SDKs expose the same runtime event names, with language-specific wrappers or helper methods around the raw JSON payload.

- `agent_start`
- `turn_start`
- `message_update`
- `message_end`
- `tool_start`
- `tool_update`
- `tool_end`
- `permission_request`
- `automode_iteration`, `automode_complete`, `automode_error`
- `error`

See [Hooks and events](/agent-sdk/concepts/hooks-and-events) for the complete normalized event contract.

## Structured JSON

Use the JSON helpers when the host application needs typed output from the final assistant response.

```csharp
var risk = await agent.RunJsonAsync<ReleaseRisk>(
    "Assess release readiness.",
    new JsonRunOptions { SchemaName = "ReleaseRisk" });
```
