Skip to main content

Module 04: ClaudeAsyncClient

Reactive, composable, non-blocking chains with Project Reactor.

What You’ll Learn

  • Creating clients with ClaudeClient.async()
  • The TurnSpec pattern for response handling
  • Multi-turn conversations with flatMap chaining
  • When to choose async vs sync clients

ClaudeSyncClient vs ClaudeAsyncClient

Both clients provide identical capabilities. They differ only in programming paradigm:

TurnSpec: Response Handling

ClaudeAsyncClient returns a TurnSpec that provides three ways to handle responses:

Multi-Turn Conversation

The .text() method returns Mono<String>, enabling elegant flatMap chaining:

Text Streaming

For streaming text as it arrives:

Full Message Access

When you need metadata, tool use details, or cost information:

Key Points

  • Factory pattern: Use ClaudeClient.async() to create clients
  • TurnSpec pattern: connect()/query() return TurnSpec, not void
  • flatMap for multi-turn: Chain turns with .text().flatMap(r -> ...)
  • Non-blocking: Use .subscribe(), avoid .block()
  • Same capabilities: Hooks, MCP, permissions all work identically to sync

ClaudeAsyncClient Methods

TurnSpec Methods

Builder Options

When to Choose

Source Code

View on GitHub

Running the Example

Next Module

Module 05: Message Types - Understanding the different message types and content blocks.