Skip to content
Open
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
26 changes: 18 additions & 8 deletions src/claude_agent_sdk/_internal/transport/subprocess_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,19 +813,29 @@ def guard(length: int) -> None:
if data is not None:
yield data

# Check process completion and handle errors
# Check process completion and handle both clean and error exits.
# Explicitly handling clean exit (returncode==0) ensures read_messages
# unblocks promptly when the CLI terminates, triggering proper teardown
# in the caller regardless of exit status.
try:
returncode = await self._process.wait()
except Exception:
returncode = -1

# Use exit code for error detection
if returncode is not None and returncode != 0:
self._exit_error = ProcessError(
f"Command failed with exit code {returncode}",
exit_code=returncode,
stderr="Check stderr output for details",
)
# Raise ProcessError for any process termination to signal the caller
if returncode is not None:
if returncode == 0:
self._exit_error = ProcessError(
"CLI process exited",
exit_code=returncode,
stderr=None,
)
else:
self._exit_error = ProcessError(
f"Command failed with exit code {returncode}",
exit_code=returncode,
stderr="Check stderr output for details",
)
raise self._exit_error

async def _check_claude_version(self) -> None:
Expand Down