From 4611f8ba4c0f3c74fab4cb6e9569550178183e8a Mon Sep 17 00:00:00 2001 From: anish Date: Tue, 19 May 2026 01:54:22 +0000 Subject: [PATCH] fix(transport): prioritize system-wide CLI over bundled binary in _find_cli Changed the CLI discovery order in `SubprocessCLITransport._find_cli()` to search for system-wide installations (via PATH and common locations) before falling back to the bundled binary. This allows users to work around protocol incompatibilities in older bundled binaries by installing a newer version globally, without requiring an SDK upgrade. Signed-off-by: anish --- .../_internal/transport/subprocess_cli.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/claude_agent_sdk/_internal/transport/subprocess_cli.py b/src/claude_agent_sdk/_internal/transport/subprocess_cli.py index 833cba4c..20132ee4 100644 --- a/src/claude_agent_sdk/_internal/transport/subprocess_cli.py +++ b/src/claude_agent_sdk/_internal/transport/subprocess_cli.py @@ -79,13 +79,14 @@ def __init__( self._write_lock: anyio.Lock = anyio.Lock() def _find_cli(self) -> str: - """Find Claude Code CLI binary.""" - # First, check for bundled CLI - bundled_cli = self._find_bundled_cli() - if bundled_cli: - return bundled_cli + """Find Claude Code CLI binary. - # Fall back to system-wide search + Searches in priority order: + 1. System-wide PATH (allows users to override bundled binary) + 2. Common installation locations + 3. Bundled CLI (fallback) + """ + # First, check for system-wide CLI (PATH and common locations) if cli := shutil.which("claude"): return cli @@ -102,6 +103,11 @@ def _find_cli(self) -> str: if path.exists() and path.is_file(): return str(path) + # Fall back to bundled CLI if no system-wide installation found + bundled_cli = self._find_bundled_cli() + if bundled_cli: + return bundled_cli + raise CLINotFoundError( "Claude Code not found. Install with:\n" " npm install -g @anthropic-ai/claude-code\n"