Skip to content
Closed
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
4 changes: 2 additions & 2 deletions src/claude_code_sdk/_internal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ def _parse_message(self, data: dict[str, Any]) -> Message | None:
# Map total_cost to total_cost_usd for consistency
return ResultMessage(
subtype=data["subtype"],
cost_usd=data["cost_usd"],
cost_usd=data.get("cost_usd", data.get("total_cost", 0.0)),
duration_ms=data["duration_ms"],
duration_api_ms=data["duration_api_ms"],
is_error=data["is_error"],
num_turns=data["num_turns"],
session_id=data["session_id"],
total_cost_usd=data["total_cost"],
total_cost_usd=data.get("total_cost", 0.0),
usage=data.get("usage"),
result=data.get("result"),
)
Expand Down
7 changes: 5 additions & 2 deletions src/claude_code_sdk/_internal/transport/subprocess_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,13 @@ async def read_stderr() -> None:
raise SDKJSONDecodeError(line_str, e) from e
continue

except anyio.ClosedResourceError:
except (anyio.ClosedResourceError, GeneratorExit):
pass
finally:
tg.cancel_scope.cancel()
try:
tg.cancel_scope.cancel()
except RuntimeError:
pass

await self._process.wait()
if self._process.returncode is not None and self._process.returncode != 0:
Expand Down