Skip to content
BENIBIX Learn

query() vs ClaudeSDKClient

People think query() and ClaudeSDKClient are two names for the same thing. query() runs a task and ends, and each new call starts fresh unless you pass resume or continue. ClaudeSDKClient is a Python class that keeps one session open, so each prompt you send remembers the ones before. Use query() for one job, and the client for a chat.

AI🧩 Claude Agent SDK

query() Function

The main function of the kit. Give it a prompt, and it runs the agent and sends back each step.

query() is the main function of the Agent SDK. You pass it a prompt and an options object, and it starts the agent loop. It returns a stream you read with a loop, and each item is a message: a tool call, a tool result, some text, or the final result. One call can run many turns before it ends.

Example
Leo calls query() with the prompt find and fix the bug in utils.py. His loop prints each tool Claude uses, then the result.
Why it matters
It is the one way in to the agent, so most programs start here.
Full entry
AI🧩 Claude Agent SDK

ClaudeSDKClient

A Python class that keeps one chat open for many prompts.

ClaudeSDKClient is a Python class in the Agent SDK that keeps one session open. Each call to its query method goes on with the same chat, so the agent recalls what came before. You read the reply with receive_response. It can also stop a turn with interrupt. TypeScript has no such class, and uses continue or resume.

Example
Mia builds a chat app in Python. She keeps one ClaudeSDKClient per user, so each follow-up knows the earlier messages.
Why it matters
A chat needs memory across prompts, and the client keeps it with no IDs to track.
Full entry

In one line

query() Function
The main function of the kit. Give it a prompt, and it runs the agent and sends back each step.
ClaudeSDKClient
A Python class that keeps one chat open for many prompts.