ClaudeSDKClient.connect() with an async iterable closes stdin, so follow-up query() fails

オープン 初心者向け
#1,443 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@m4xkushnir がすでに取り組んでいます。

2026年10月25日 から。

  • #1444 @m4xkushnir による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

まず ClaudeSDKClient.connect() と Query.stream_input() を読みます。issue では、iterable が終了すると入力を閉じる経路として特定されています。これを iterable を使う ClaudeSDKClient.query() と比較します。示されている非同期ジェネレーターで再現し、connect(stream) が後続の query() に使える状態でセッションを維持する一方、1回限りの query() の動作は保たれることを確認します。

索引モデルが issue の本文から書いたものです。

説明

bug

Hi, I ran into this while sending an image as the first message of a ClaudeSDKClient session.

If I call connect() with a string, I can keep talking to the session with query() afterwards. If I call connect() with an async iterable instead, the session is over as soon as the iterable runs out, and the next query() raises CLIConnectionError: ProcessTransport is not ready for writing.

async def first_message():
    yield {"type": "user", "message": {"role": "user", "content": "Hi"}}

client = ClaudeSDKClient()
await client.connect(first_message())
async for msg in client.receive_response():
    print(msg)

await client.query("Follow-up")  # CLIConnectionError

The same thing with await client.connect("Hi") works fine, and so does connect() followed by query(first_message()).

From what I can tell, connect() hands the iterable to Query.stream_input(), which ends input once the stream is exhausted. That makes sense for one-shot query(), but for the client it closes stdin, the CLI exits, and nothing else can be sent. ClaudeSDKClient.query() with an iterable doesn't end input, so the two paths behave differently for the same kind of prompt.

I'd expect connect(stream) to behave like connect("text") and only open the session. Happy to send a PR if that sounds right to you.

Version 0.2.174 (current main), Python 3.13, macOS.

主要言語
Python
スター
8.5k
フォーク
1.4k
平均マージ
3日 10時間
マージ済み PR(30日)
13

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

anthropics/claude-agent-sdk-python のほかの issue

anthropics/claude-agent-sdk-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。