Module 01: Hello World
Your first Claude Agent SDK program.What You’ll Learn
- How to add the SDK dependency to your project
- The simplest way to query Claude:
Query.text() - Running a query and getting a text response
Prerequisites
-
Claude CLI installed and authenticated
- Java 21 or later
The Code
Source Code
View on GitHubRunning the Example
How It Works
Query.text()is a static method that takes a prompt string- It starts the Claude CLI as a subprocess
- Sends your prompt to Claude
- Returns Claude’s text response as a String
- The CLI subprocess exits automatically
Key Points
- Stateless: Each
Query.text()call creates a new session - Blocking: The call waits for Claude’s complete response
- Simple: No configuration required for basic usage
Next Module
Module 02: Query API - Learn aboutQuery.execute() for getting response metadata like cost and token usage.