Skip to main content

Module 03: ClaudeSyncClient

Multi-turn conversations with context preservation.

What You’ll Learn

  • Creating clients with ClaudeClient.sync()
  • Multi-turn conversations where Claude remembers context
  • Simple text responses with connectText() and queryText()
  • Full message access with connectAndReceive()

Query vs ClaudeSyncClient

Multi-Turn Conversation (Simple)

For most use cases, you just want the text response:

Multi-Turn with Message Access

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

Key Points

  • Use try-with-resources: Clients hold resources that must be released
  • Factory pattern: Use ClaudeClient.sync() to create clients
  • Text methods for 80% use case: connectText() and queryText() return String
  • Message iteration for 20% use case: connectAndReceive() returns Iterable<Message>
  • Good toString(): All message types print useful information

ClaudeSyncClient Methods

Builder Options

Source Code

View on GitHub

Running the Example

Next Module

Module 04: ClaudeAsyncClient - Reactive, composable, non-blocking chains.