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.
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.
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.
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.