Skip to content

feat: ClaudeSDKClient supports custom transport.#187

Merged
dicksontsai merged 1 commit into
anthropics:mainfrom
jwx0925:feat/client-arg-transport
Sep 29, 2025
Merged

feat: ClaudeSDKClient supports custom transport.#187
dicksontsai merged 1 commit into
anthropics:mainfrom
jwx0925:feat/client-arg-transport

Conversation

@jwx0925
Copy link
Copy Markdown
Contributor

@jwx0925 jwx0925 commented Sep 28, 2025

query supports custom transport, but ClaudeSDKClient does not. So I add this feature. eg.

from claude_code_sdk import ClaudeSDKClient, Transport

class MyCustomTransport(Transport):
    # Implement custom transport logic
    pass

transport = MyCustomTransport()
async with ClaudeSDKClient( transport=transport) as client:
    await client.query("Greet Alice")

    # Extract and print response
    async for msg in client.receive_response():
        print(msg)

@dicksontsai
Copy link
Copy Markdown
Collaborator

"Commits must have verified signatures." Could you please re-push and address the lint errors?

@jwx0925 jwx0925 force-pushed the feat/client-arg-transport branch 2 times, most recently from 886268e to 0d5b0e6 Compare September 29, 2025 03:26
@jwx0925
Copy link
Copy Markdown
Contributor Author

jwx0925 commented Sep 29, 2025

"Commits must have verified signatures." Could you please re-push and address the lint errors?

I have repushed and fixed the lint issues.

Copy link
Copy Markdown
Collaborator

@dicksontsai dicksontsai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like your commit still doesn't have a verified signature.

"""Initialize Claude SDK client."""
if options is None:
options = ClaudeAgentOptions()
self.options = options
self._transport: Any | None = None
self._custom_transport = transport
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is self._custom_transport necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If _transport is assigned directly, the test case TestClaudeSDKClientEdgeCases.test_double_connect will fail. If there is no custom transport, client.connect() should ensure that the self._transport is renewed.

@jwx0925 jwx0925 force-pushed the feat/client-arg-transport branch from 0d5b0e6 to 0cf9987 Compare September 29, 2025 04:04
@dicksontsai dicksontsai merged commit d9dd841 into anthropics:main Sep 29, 2025
5 of 9 checks passed
@dicksontsai
Copy link
Copy Markdown
Collaborator

Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants