Skip to content

Commit 0d5b0e6

Browse files
committed
feat: expose transport parameter in ClaudeSDKClient init
1 parent 9d4659c commit 0d5b0e6

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/claude_agent_sdk/client.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from dataclasses import replace
77
from typing import Any
88

9+
from . import Transport
910
from ._errors import CLIConnectionError
1011
from .types import ClaudeAgentOptions, HookEvent, HookMatcher, Message, ResultMessage
1112

@@ -51,12 +52,17 @@ class ClaudeSDKClient:
5152
exist.
5253
"""
5354

54-
def __init__(self, options: ClaudeAgentOptions | None = None):
55+
def __init__(
56+
self,
57+
options: ClaudeAgentOptions | None = None,
58+
transport: Transport | None = None,
59+
):
5560
"""Initialize Claude SDK client."""
5661
if options is None:
5762
options = ClaudeAgentOptions()
5863
self.options = options
59-
self._transport: Any | None = None
64+
self._custom_transport = transport
65+
self._transport: Transport | None = None
6066
self._query: Any | None = None
6167
os.environ["CLAUDE_CODE_ENTRYPOINT"] = "sdk-py-client"
6268

@@ -115,10 +121,14 @@ async def _empty_stream() -> AsyncIterator[dict[str, Any]]:
115121
else:
116122
options = self.options
117123

118-
self._transport = SubprocessCLITransport(
119-
prompt=actual_prompt,
120-
options=options,
121-
)
124+
# Use provided custom transport or create subprocess transport
125+
if self._custom_transport:
126+
self._transport = self._custom_transport
127+
else:
128+
self._transport = SubprocessCLITransport(
129+
prompt=actual_prompt,
130+
options=options,
131+
)
122132
await self._transport.connect()
123133

124134
# Extract SDK MCP servers from options

0 commit comments

Comments
 (0)