Skip to content
BENIBIX Learn

ClaudeSDKClient

AI🧩 Claude Agent SDKAgent SDK Basics

Also known as Python SDK client, ClaudeSDKClient class

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

Think of it like

It is like a phone call you keep open. You do not hang up after each question.

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.

Definition

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 code

python
async with ClaudeSDKClient() as client:
    await client.query("Read auth.py")
    async for m in client.receive_response():
        print(m)
Open a client, send a prompt, and read the reply.

Common mistake

Calling query() again for a follow-up and losing the context. Use the client, or pass resume.

Key takeaways

  1. 1
    One open session. Many prompts.
  2. 2
    receive_response(). Reads the reply.
  3. 3
    Python only. TypeScript uses continue.

Compare