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
12 changes: 12 additions & 0 deletions src/claude_agent_sdk/_internal/transport/subprocess_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,18 @@ async def _handle_stderr(self) -> None:
except Exception:
pass # Ignore other errors during stderr reading

@property
def pid(self) -> int | None:
"""Return the PID of the underlying CLI subprocess, or ``None`` if no
process is currently running.

This is exposed as a public property so callers that need to clean up
the spawned ``claude`` CLI process out-of-band (e.g. on hard timeouts
or shutdown signals) can do so without walking SDK internals.
See anthropics/anthropic-sdk-python#1370.
"""
return self._process.pid if self._process is not None else None

async def close(self) -> None:
"""Close the transport and clean up resources."""
if not self._process:
Expand Down