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

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

## Install

```cmake
include(FetchContent)

FetchContent_Declare(
  autohand_sdk
  GIT_REPOSITORY https://github.com/autohandai/code-agent-sdk-cpp.git
  GIT_TAG main
)

FetchContent_MakeAvailable(autohand_sdk)
target_link_libraries(my_app PRIVATE autohand::sdk)
```

## `autohand::Config` [#configuration]

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

```cpp
auto config = autohand::Config::from_environment()
    .with_cwd(".")
    .with_model("fantail2")
    .with_skill("cpp")
    .with_instructions("Prefer small, typed C++ APIs.");
```

## `autohand::AutohandSdk` [#low-level]

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

- start() / stop()
- request(method, params\_json)
- prompt(message, options)
- stream\_prompt(message, on\_event, options)
- interrupt()
- set\_plan\_mode(enabled)
- set\_permission\_mode(mode)
- set\_model(model)
- get\_state()
- get\_messages()
- permission\_response(request\_id, decision)

## `autohand::Agent` [#agent]

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

```cpp
autohand::Agent agent(autohand::Config::from_environment().with_cwd("."));
auto run = agent.send("Review the public API.");
auto result = run.wait();
agent.close();
```

- send(prompt, options)
- run(prompt, options)
- run\_json(prompt, schema\_json)
- allow\_permission(request\_id)
- deny\_permission(request\_id)
- set\_plan\_mode(enabled)
- close()

## Run

- stream(on\_event): stream events and record final text
- wait(): wait until the run finishes and collect text/events
- json\_text(): parse final output as JSON text
- abort(): interrupt the current run

## CLI 0.9.13 run options

Configure the CLI process through `autohand::Config` before startup.

- `max_requests`, `max_duration_seconds` set the request budget and wall-clock limit in seconds.
- `allowed_tools`, `disallowed_tools` accept lists of tool patterns.
- `profile`, `setting_overrides` select a saved profile and apply ordered run-only overrides.
- `no_daemon`, `sync_settings`, `search_engine` control background services, settings synchronization, and web search.

Use `SdkEvent.method` and `SdkEvent.raw_json` 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 `autohand::Agent` and `autohand::AutohandSdk`. Use `autohand::AutohandSdk` for the complete approval, session, MCP, learning, tool-registry, and context surface.

- **Conversation and handoff:** `reset`, `create_browser_handoff`, `attach_browser_handoff`, `attach_latest_browser_handoff`
- **Auto-mode:** `start_automode`, `get_automode_status`, `pause_automode`, `resume_automode`, `cancel_automode`, `get_automode_log`
- **Approvals and sessions:** `acknowledge_permission`, `respond_to_directory_access`, `acknowledge_directory_access`, `decide_changes`, `get_session_history`, `get_session`, `attach_session`
- **Integrations and context:** `set_yolo`, `set_yolo_compat`, `set_vscode_mcp_tools`, `respond_to_mcp_invocation`, `recommend_project_skills`, `update_project_skills`, `generate_skill`, `get_tools_registry`, `set_context_compact`

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.

```cpp
auto json = agent.run_json(
    "Assess release readiness.",
    R"({"summary":"string","risks":[]})");
```
