Skip to content

connect(prompt=...) followed by receive_messages() hangs indefinitely #766

@jeremy-newhouse

Description

@jeremy-newhouse

Description

When using ClaudeSDKClient.connect(prompt='...') with a prompt argument, calling receive_messages() afterwards hangs indefinitely — no messages are ever yielded.

The working pattern is connect() (no prompt) followed by query(prompt) then receive_messages().

Steps to Reproduce

Hangs:

client = ClaudeSDKClient(options=options)
await client.connect(prompt='Say hello')  # With prompt
async for msg in client.receive_messages():  # Hangs forever
    print(type(msg).__name__)

Works:

client = ClaudeSDKClient(options=options)
await client.connect()  # No prompt
await client.query('Say hello')
async for msg in client.receive_messages():  # Yields messages
    print(type(msg).__name__)

Expected Behavior

Both patterns should work. connect(prompt=...) should be equivalent to connect() + query(prompt).

Environment

  • claude-agent-sdk: 0.1.51
  • Claude CLI: 2.1.86
  • Python: 3.12
  • OS: Linux (Docker)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions