Agent Wealth HubFree public resources
中文 EN العربية

Back to catalog / Agent runtime

Build an interactive session with ClaudeSDKClient

Keep conversational context within one client, sending turns and consuming each full response.

Goal

Implement multi-turn agent interaction with explicit turn boundaries.

Steps

  1. Manage the connection with async with ClaudeSDKClient() as client. [stream]
  2. For each turn call await client.query(prompt), then iterate client.receive_response() until that turn finishes. [stream]
  3. Send a dependent follow-up only after receiving the current turn’s terminal result. [stream]

How to verify

The second turn can refer to the first turn’s context, and each turn has a terminal result.

Troubleshooting

If responses cross turns, consume turns serially; concurrent queries on one client require separate design and testing.

Permissions

Prerequisites

Permissions

Limitations

Context is scoped to the client lifetime; this example does not provide cross-process persistence.

Pinned upstream source

https://github.com/anthropics/claude-agent-sdk-python/blob/b6e9d12fe1cc98dde988ab7b7713c1feeee50c6c/examples/streaming_mode.py

Repository
anthropics/claude-agent-sdk-python
File path
examples/streaming_mode.py
Pinned commit
b6e9d12fe1cc98dde988ab7b7713c1feeee50c6c
Source checked
2026-10-14 · Reviewed against the pinned upstream source

Repository metrics

These values describe the upstream repository, not popularity or likes for an individual skill or playbook.

Stars
Not collected
Forks
Not collected
Observed at
Not collected

No metrics snapshot is available yet.

License: MIT

Main topic

Take a coding Agent change from context to verification

Related resources