File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
src/claude_code_sdk/_internal/transport Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,11 @@ async def connect(self) -> None:
141141 self ._stderr_stream = TextReceiveStream (self ._process .stderr )
142142
143143 except FileNotFoundError as e :
144+ # Check if the error comes from the working directory or the CLI
145+ if self ._cwd and not Path (self ._cwd ).exists ():
146+ raise CLIConnectionError (
147+ f"Working directory does not exist: { self ._cwd } "
148+ ) from e
144149 raise CLINotFoundError (f"Claude Code not found at: { self ._cli_path } " ) from e
145150 except Exception as e :
146151 raise CLIConnectionError (f"Failed to start Claude Code: { e } " ) from e
Original file line number Diff line number Diff line change @@ -132,3 +132,21 @@ def test_receive_messages(self):
132132 # So we just verify the transport can be created and basic structure is correct
133133 assert transport ._prompt == "test"
134134 assert transport ._cli_path == "/usr/bin/claude"
135+
136+ def test_connect_with_nonexistent_cwd (self ):
137+ """Test that connect raises CLIConnectionError when cwd doesn't exist."""
138+ from claude_code_sdk ._errors import CLIConnectionError
139+
140+ async def _test ():
141+ transport = SubprocessCLITransport (
142+ prompt = "test" ,
143+ options = ClaudeCodeOptions (cwd = "/this/directory/does/not/exist" ),
144+ cli_path = "/usr/bin/claude" ,
145+ )
146+
147+ with pytest .raises (CLIConnectionError ) as exc_info :
148+ await transport .connect ()
149+
150+ assert "/this/directory/does/not/exist" in str (exc_info .value )
151+
152+ anyio .run (_test )
You can’t perform that action at this time.
0 commit comments