---
title: "C++ SDK"
description: "The C++20 SDK wraps the Autohand Code CLI in JSON-RPC mode and exposes a small host-friendly API with CMake integration, typed event helpers, and high-level agent runs."
sidebar:
  label: "C++"
seo:
  title: "C++ SDK | Autohand Code Agent SDK"
  description: "Use the C++ SDK to control Autohand Code agents from C++20 tools, editors, desktop apps, services, and CI utilities."
---

:::note
**Repository:** [autohandai/code-agent-sdk-cpp](https://github.com/autohandai/code-agent-sdk-cpp). This SDK is in beta while the Agent SDK APIs stabilize. Pin commits or package versions in production.
:::

## Requirements

- C++20 compiler.
- CMake 3.22 or newer.
- Autohand Code CLI installed, authenticated, and configured.
- POSIX runtime for the initial transport implementation.

## 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)
```

## Run your first agent [#first-agent]

Start with the high-level agent API when you want the SDK to own the run lifecycle and final result collection.

```cpp
#include <autohand/sdk.hpp>
#include <iostream>

int main() {
  autohand::Agent agent(
      autohand::Config::from_environment()
          .with_cwd(".")
          .with_instructions("Review code with senior C++ judgement."));

  auto run = agent.send("List the main source files and tell me what looks risky.");

  run.stream([](const autohand::SdkEvent& event) {
    if (event.type == "message_update") {
      std::cout << event.text_delta();
    }
  });

  auto result = run.wait();
  std::cout << result.text << "\n";
  agent.close();
}
```

## API shape

- CMake target: `autohand::sdk`.
- Value-oriented `autohand::Config` setup.
- High-level `autohand::Agent` and `autohand::Run` workflow.
- Low-level `autohand::AutohandSdk` methods for direct runtime control.

## Low-level control [#extra]

Use `AutohandSdk` when your native host needs to toggle plan mode, stream events directly, or own JSON-RPC request timing.

```cpp
#include <autohand/sdk.hpp>
#include <iostream>

int main() {
  autohand::AutohandSdk sdk(autohand::Config::from_environment().with_cwd("."));
  sdk.start();
  sdk.set_plan_mode(true);

  sdk.stream_prompt("Create a discovery plan for this SDK change.", [](const autohand::SdkEvent& event) {
    std::cout << event.type << "\n";
  });

  sdk.stop();
}
```

## Next steps

- Use [Quickstart](/agent-sdk/quickstart) for the cross-language setup flow.
- Open [C++ API](/agent-sdk/cpp-api) for the reference surface.
- Read [Stream responses in real-time](/agent-sdk/io/streaming) and [Handle approvals and user input](/agent-sdk/io/approvals) for shared runtime behavior.
