---
title: "Go API Reference"
description: "Complete API reference for the Autohand SDK Go. The SDK spawns the Autohand Code CLI as a subprocess and communicates over JSON-RPC."
sidebar:
  label: "Go API"
seo:
  title: "Go API Reference | Autohand Code Agent SDK"
  description: "Complete API reference for the Autohand SDK Go. CLI wrapper with Config, AutohandSDK, and high-level Agent API."
---

## Installation

```bash
go get github.com/autohandai/agent-sdk-go
```

## Config

All fields are optional.

```go
type Config struct {
    CWD            string
    CLIPath        string
    Debug          bool
    Timeout        int
    Model          string
    Provider       string
    APIKey         string
    BaseURL        string
    Temperature    float64
    PermissionMode string
    Skills         []SkillRef
    AutoSkill      bool
    ContextCompact bool
    MaxTokens      int
    SysPrompt      string
    AppendSysPrompt string
    PersistSession bool
    Resume         bool
    AdditionalDirectories []string
    EnvVars        map[string]string
    MCPServers     map[string]McpServerConfig
    ExtraArgs      []string
}
```

## CLI 0.9.13 run options

Configure the CLI process through `Config` 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 `sdk.OnNotification` and the packet’s `Method` and `Params` fields 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).

## Low-Level API

### AutohandSDK

```go
sdk := autohand.NewSDK(&autohand.Config{...})
err := sdk.Start(ctx)
defer sdk.Close()
```

#### Prompting

```go
err := sdk.Prompt(ctx, &autohand.PromptParams{Message: "Hello"})
events, err := sdk.StreamPrompt(ctx, &autohand.PromptParams{Message: "Hello"})
```

#### Control Methods

```go
err := sdk.Interrupt(ctx)
err := sdk.SetPermissionMode(ctx, autohand.PermissionInteractive)
err := sdk.SetPlanMode(ctx, true)
err := sdk.SetModel(ctx, "openrouter/auto")
err := sdk.SetMaxThinkingTokens(ctx, 200000)
err := sdk.ApplyFlagSettings(ctx, &autohand.Config{...})
```

#### Information Methods

```go
init, err := sdk.InitializationResult(ctx)
commands, err := sdk.SupportedCommands(ctx)
models, err := sdk.SupportedModels(ctx)
agents, err := sdk.SupportedAgents(ctx)
status, err := sdk.McpServerStatus(ctx)
usage, err := sdk.GetContextUsage(ctx)
```

## High-Level API

### Agent

```go
agent, err := autohand.NewAgent(ctx, &autohand.Config{...})
defer agent.Close()
run, err := agent.Send(ctx, "Review this repo", nil)
```

### Run

```go
for event := range run.Stream(ctx) { ... }
result, err := run.Wait(ctx)
err := run.Abort(ctx)
```

## CLI Runtime Control

Core lifecycle and auto-mode methods are available on `Agent`, `SDK`, and `RPCClient`. The extended control surface is available on `SDK` and `RPCClient`.

- **Lifecycle:** `Reset`, `CreateBrowserHandoff`, `AttachBrowserHandoff`, `AttachLatestBrowserHandoff`.
- **Auto-mode:** `StartAutomode`, `GetAutomodeStatus`, `PauseAutomode`, `ResumeAutomode`, `CancelAutomode`, `GetAutomodeLog`.
- **Approvals and sessions:** `AcknowledgePermission`, `RespondToDirectoryAccess`, `AcknowledgeDirectoryAccess`, `DecideChanges`, `GetHistory`, `GetSession`, `AttachSession`.
- **Integrations:** `SetYolo`, `SetYoloAlias`, `SetVSCodeMCPTools`, `RespondToMCPInvocation`, `RecommendProjectLearning`, `UpdateProjectLearning`, `GenerateProjectSkill`, `GetToolsRegistry`, `SetContextCompact`.

Read [Control the Autohand Code CLI from every SDK](/agent-sdk/concepts/cli-runtime-control) for behavior, safety contracts, aliases, and the cross-language name map.

## Events

StreamPrompt and Run.Stream return channels of typed events:

- `MessageUpdateEvent` - Streaming assistant text delta
- `ToolStartEvent` - Tool execution started
- `ToolEndEvent` - Tool execution completed
- `PermissionRequestEvent` - Runtime pause for approval
- `automode_iteration`, `automode_complete`, and `automode_error` - Auto-mode lifecycle
- `ErrorEvent` - Transport, runtime, or execution failure

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

## Error Handling

The SDK returns errors from the standard `error` interface.

## See Also

- [Go SDK Overview](/agent-sdk/go)
- [CLI Quick Start](/guides/cli-quick-start)
