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"