---
title: "Java SDK"
description: "Run the Autohand agent loop on the JVM. The Java SDK exposes a builder-style API, sealed event types, and the same permission and streaming model as the other SDKs."
sidebar:
  label: "Java"
seo:
  title: "Java SDK | Autohand Code Agent SDK"
  description: "Use the Java SDK for the Autohand Code Agent SDK with builder-style configuration and event-streaming."
---

## Install

```xml
<dependency>
    <groupId>ai.autohand</groupId>
    <artifactId>agent-sdk-java</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>
```

## API shape [#shape]

The Java wrapper mirrors the same runtime ideas as the TypeScript and Go SDKs: create an agent, send a prompt, stream events, then close the session.

```java
import ai.autohand.sdk.sdk.Agent;
import ai.autohand.sdk.sdk.AgentOptions;
import ai.autohand.sdk.sdk.RunResult;
import ai.autohand.sdk.types.Events;
import ai.autohand.sdk.types.PermissionMode;

Agent agent = Agent.create(AgentOptions.builder()
    .cwd(".")
    .instructions("Review code with concise release-readiness notes.")
    .permissionMode(PermissionMode.INTERACTIVE)
    .build());

var run = agent.send("Review the repository for release risks.");
run.stream(event -> {
    if (event instanceof Events.MessageUpdateEvent mue) {
        System.out.print(mue.delta());
    }
});

RunResult result = run.waitForResult();
System.out.println(result.text());
agent.close();
```

## Permissions

Permission events follow the same pattern as the other wrappers.

```java
import ai.autohand.sdk.sdk.AutohandSDK;
import ai.autohand.sdk.types.DecisionScope;
import ai.autohand.sdk.types.Events;
import ai.autohand.sdk.types.PromptParams;
import ai.autohand.sdk.types.SDKConfig;

AutohandSDK sdk = new AutohandSDK(new SDKConfig(
    ".",
    null,
    false,
    300000
));

sdk.start();
sdk.streamPrompt(new PromptParams("Run the test suite and summarize failures."), event -> {
    if (event instanceof Events.PermissionRequestEvent pre) {
        sdk.allowPermission(pre.requestId(), DecisionScope.ONCE);
    }
});
sdk.stop();
```

## What to expect

- Builder-based configuration via `AgentOptions` and `SDKConfig`.
- Stream callbacks over sealed event types in `Events`.
- Low-level `AutohandSDK` access when you need direct runtime control.
- Higher-level `Agent` access for everyday application code.

## Next steps

- Use [Quickstart](/agent-sdk/quickstart) for the cross-language setup flow.
- Compare with the [Go SDK](/agent-sdk/go) or [TypeScript SDK](/agent-sdk/typescript) for the same patterns in other languages.
