Skip to main content
A progressive, hands-on tutorial. Each module takes 15-30 minutes and focuses on one concept.

Prerequisites

  • Java 21 or later
  • Maven 3.8+
  • Claude CLI installed and authenticated (claude login)

Tutorial Structure

PartModulesTopics
1. Fundamentals01-04Query API, ClaudeSyncClient, Message Types
2. Configuration05-08CLI Options, Permissions, Structured Output
3. Sessions & State09-12Multi-turn, Resume, Fork, Streaming
4. Safety & Control13-16Callbacks, Hooks, Interrupts
5. MCP Integration17-19External servers, Spring AI, Custom tools
6. Multi-Agent20-22Subagents, Parallel execution, Patterns
CapstoneFinalComplete research agent project

Getting the Code

git clone https://github.com/spring-ai-community/claude-agent-sdk-java-tutorial.git
cd claude-agent-sdk-java-tutorial

Running a Module

mvn compile exec:java -pl module-01-hello-world

Three API Styles

The SDK provides three ways to interact with Claude:
APIClassProgramming StyleBest For
One-shotQueryStatic methodsSimple queries, scripts
BlockingClaudeSyncClientIterator-basedTraditional applications, synchronous workflows
ReactiveClaudeAsyncClientFlux/MonoNon-blocking applications, high concurrency
Both ClaudeSyncClient and ClaudeAsyncClient support the full feature set: multi-turn conversations, hooks, MCP integration, and permission callbacks. They differ only in programming paradigm. The tutorial primarily uses Query for simple examples and ClaudeSyncClient for advanced features (blocking is more accessible to most developers).

Start Learning

Begin with Module 01: Hello World to write your first Claude Agent SDK program.