Query for a one-shot answer, ClaudeSyncClient for blocking multi-turn
sessions and ClaudeAsyncClient for reactive streams with Project Reactor. Hooks, permission callbacks, MCP servers,
subagents and structured output come with it. Pure Java, with no native code and no Spring dependency: the SDK needs only
zt-exec, Jackson, Reactor, SLF4J and the MCP Java SDK. Spring Boot auto-configuration for Claude lives in
Agent Client, whose Claude provider, agent-claude, is built on this SDK.
claude CLI must be installed and authenticated.
What you get
Three APIs, one transport
Query.text, query, stream and execute for one-shot calls; ClaudeSyncClient for blocking turns;
ClaudeAsyncClient returns Mono and Flux for text, text streams and messages.Sessions you can steer
Resume, continue or fork a session. During a session,
interrupt(), setModel(...) and setPermissionMode(...)
change course without starting over.Hooks that the CLI obeys
Register Java callbacks for all six hook events, PreToolUse to PreCompact, and allow, block or rewrite a tool call.
From 1.8.0 a PreToolUse
deny reaches the CLI in the nested form it reads.Permission callbacks
A
ToolPermissionCallback sees each tool request with its input and returns allow, allow with changed input, or
deny with a message.MCP servers
Attach stdio, SSE and HTTP MCP servers by name; their tools appear to Claude as
mcp__{name}__{tool}.Structured output
Pass a JSON schema and read the result back as your own type with
getStructuredOutputAs(...), with cost and usage
in the result metadata.Record exactly what the CLI wrote
New in 1.8.0: every standard-output line before parsing, the original JSON of every message, and the raw process
bytes of stdin, stdout and stderr, so a recorder can keep a session as it happened.
Shutdown you can check
New in 1.8.0:
close() makes one bounded cleanup attempt of seven seconds, and transportResources() reports which
observed processes, readers and temporary files actually ended.1.8.0 in brief
1.8.0 fixes four Jackson vulnerabilities by moving to Jackson 2.22.3 and 3.2.3. Published 1.5.1, 1.6.0 and 1.7.0 declare Jackson 2.22.2 and 3.2.2, which carry CVE-2026-89407, CVE-2026-89425, CVE-2026-91776 and CVE-2026-91777 (CVSS 7.5), so upgrade to 1.8.0. It also repairs three wire defects: a required MCP configuration that cannot be written now fails before the CLI starts, control responses carrysubtype once, and hook responses keep their nested fields. Builder users need no
code change; direct new CLIOptions(...) calls and three ParsedMessage record constructors gain components, and the
unused ClaudeCliPrototype class is removed. Release notes.
1.7.0: Closing or cancelling a session destroys the Claude CLI process tree before closing streams, unblocking readers and preventing the CLI from surviving cancellation.
1.5.0: A security, packaging and behaviour-correction release: it raises the Jackson floors so they reach standalone consumers, embeds the Apache licence in every archive, publishes a CycloneDX 1.6 SBOM, and stops a no-argument connect() from sending a prompt of its own. It follows 1.4.0, which bumped the MCP SDK from 0.15.0 to 2.0.0 (mcp-core 2.0.0), clearing CVE-2026-35568; 1.8.0 uses MCP SDK 2.0.1. See What’s New →.
How it operates
The SDK does not call the Anthropic API. It spawns the Claude Code CLI as a child process and speaks the stream-JSON control protocol to it over stdin and stdout. That shapes what you need to know:- The
claudeexecutable must be installed and authenticated on the machine that runs your code. The SDK discovers it onPATHand in the usual install locations. ANTHROPIC_API_KEYis passed through to the child process when set. Environment inheritance is otherwise a whitelist, not a copy of your whole environment.- Every session consumes real model usage and is billed. That includes the integration
test suite in the SDK repository. A no-argument
connect()sends nothing on its own: from 1.5.0 it starts and initialises the session and leaves the first turn to yourquery(...). Before 1.5.0 it substituted a literal"Hello"and billed that turn. - The child process, and its descendants, are terminated on close.
MCP servers
McpServerConfig is a sealed interface with four server types (1.8.0):
Register a server by name with
CLIOptions.Builder.mcpServer(name, config), or on a client spec with ClaudeClient SyncSpec/AsyncSpec .mcpServer(name, config) and .mcpServers(Map). Its tools are named mcp__{name}__{tool}, for example mcp__fs__read_file, which is the name to use in an allowed-tools list.
In-process servers list tools but cannot yet run them. In 1.8.0 the SDK answers
initialize and the list methods for an McpSdkServerConfig, but a tools/call, resources/read or prompts/get through it returns the JSON-RPC error “not yet implemented”. Use a stdio, SSE or HTTP server for tools Claude must call.--mcp-config that cannot be written fails before the CLI is launched, with TransportException("Failed to prepare required MCP configuration") (f555e72b). In 1.7.0 the SDK logs a warning and launches the CLI without the MCP servers.
Licence
Apache License 2.0 — see the repository LICENSE. This SDK is a supporting public project and is not part of the AgentWorks BSL set.Tutorials
23 progressive modules from fundamentals to multi-agent orchestration. The tutorial builds against SDK 1.8.0 from Maven Central (tutorialfeddc99).
Query & Clients
Query API, sync client, async client, message types
Configuration
CLI options, tool permissions, permission modes, structured outputs
Sessions
Multi-turn conversations, session resume, session fork
Safety & Hooks
Permission callbacks, pre/post tool-use hooks, interrupt handling
MCP Integration
External MCP servers, multiple servers, MCP with hooks (stdio servers only; see MCP servers above for SSE, HTTP and in-process)
Multi-Agent
Subagent definitions, parallel subagents, orchestrator pattern
Source
SDK Source
SDK implementation
Tutorial Code
23 runnable tutorial modules
Role in the Lab
- Agent Client uses the SDK for Claude Code integration (
agent-claude), with Spring Boot lifecycle and sandbox isolation - Agent Workflow does not depend on this SDK. Its
ClaudeStepruns theclaudeCLI as a subprocess through Workflow’s ownClaudeSyncClientinterface, whose default implementation an application can replace - Agent Experiment 0.9.0 invokes Claude through
ClaudeSdkInvoker(experiment-claude). On main it is replaced byAgentClientInvoker, which reaches this SDK through Agent Client