Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/claude_code_sdk/_internal/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Internal client implementation."""

from collections.abc import AsyncIterable, AsyncIterator
from pathlib import Path
from typing import Any

from ..types import ClaudeCodeOptions, Message
Expand All @@ -15,12 +16,15 @@ def __init__(self) -> None:
"""Initialize the internal client."""

async def process_query(
self, prompt: str | AsyncIterable[dict[str, Any]], options: ClaudeCodeOptions
self,
prompt: str | AsyncIterable[dict[str, Any]],
options: ClaudeCodeOptions,
cli_path: Path | None = None
) -> AsyncIterator[Message]:
"""Process a query through transport."""

transport = SubprocessCLITransport(
prompt=prompt, options=options, close_stdin_after_prompt=True
prompt=prompt, options=options, cli_path=cli_path, close_stdin_after_prompt=True
)

try:
Expand Down
6 changes: 5 additions & 1 deletion src/claude_code_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
from collections.abc import AsyncIterable, AsyncIterator
from pathlib import Path
from typing import Any

from ._errors import CLIConnectionError
Expand Down Expand Up @@ -99,7 +100,9 @@ def __init__(self, options: ClaudeCodeOptions | None = None):
os.environ["CLAUDE_CODE_ENTRYPOINT"] = "sdk-py-client"

async def connect(
self, prompt: str | AsyncIterable[dict[str, Any]] | None = None
self,
prompt: str | AsyncIterable[dict[str, Any]] | None = None,
cli_path: Path | None = None
) -> None:
"""Connect to Claude with a prompt or message stream."""
from ._internal.transport.subprocess_cli import SubprocessCLITransport
Expand All @@ -115,6 +118,7 @@ async def _empty_stream() -> AsyncIterator[dict[str, Any]]:
self._transport = SubprocessCLITransport(
prompt=_empty_stream() if prompt is None else prompt,
options=self.options,
cli_path=cli_path
)
await self._transport.connect()

Expand Down
5 changes: 4 additions & 1 deletion src/claude_code_sdk/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
from collections.abc import AsyncIterable, AsyncIterator
from pathlib import Path
from typing import Any

from ._internal.client import InternalClient
Expand All @@ -12,6 +13,7 @@ async def query(
*,
prompt: str | AsyncIterable[dict[str, Any]],
options: ClaudeCodeOptions | None = None,
cli_path: Path | None = None
) -> AsyncIterator[Message]:
"""
Query Claude Code for one-shot or unidirectional streaming interactions.
Expand Down Expand Up @@ -56,6 +58,7 @@ async def query(
- 'acceptEdits': Auto-accept file edits
- 'bypassPermissions': Allow all tools (use with caution)
Set options.cwd for working directory.
cli_path: Optional Path of Claude Code binary.

Yields:
Messages from the conversation
Expand Down Expand Up @@ -98,5 +101,5 @@ async def prompts():

client = InternalClient()

async for message in client.process_query(prompt=prompt, options=options):
async for message in client.process_query(prompt=prompt, options=options, cli_path=cli_path):
yield message
Loading