feat: delete_session() cascades subagent transcript dir#805
feat: delete_session() cascades subagent transcript dir#805
Conversation
There was a problem hiding this comment.
LGTM — simple best-effort cascade deletion with proper guard and a regression test.
Extended reasoning...
Overview
Adds a single call at the end of to clean up the sibling subagent transcript directory, aligning Python SDK behavior with the TS SDK. Also updates the docstring and adds one regression test.
Security risks
None. The path is constructed as where both components come from the already-validated session file path — no injection surface. prevents any information leakage via exceptions.
Level of scrutiny
Low. This is a two-line production change (plus docstring + import) that is purely additive and best-effort. The failure mode when the directory is absent is a silent no-op, which is the correct behavior described in the PR.
Other factors
No bugs found. No prior reviews. The new test covers the case where the subagent dir exists and verifies both the and the directory are removed.
- anthropics#806: setting_sources=[] truthiness fix - anthropics#803: betas=[]/plugins=[] truthiness fix - anthropics#786: ThinkingBlock missing signature crash fix - anthropics#790: suppress ProcessError when result already received - anthropics#658: capture real stderr in ProcessError - anthropics#791: suppress stale task notifications between turns - anthropics#763: guard malformed CLAUDE_CODE_STREAM_CLOSE_TIMEOUT env var - anthropics#805: delete_session() cascades subagent transcript dir - anthropics#804: top-level skills option on ClaudeAgentOptions - anthropics#691: PostCompact hook event type support 479 tests passing, mypy clean, ruff clean. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Aligns
delete_session()with the TS SDK filesystem behavior. after removing{session_id}.jsonl, also remove the sibling{session_id}/subdirectory that holds subagent transcripts.The subagent dir is removed best-effort (
shutil.rmtree(..., ignore_errors=True)) since most sessions never spawn subagents. The existingFileNotFoundErrorwhen the.jsonlitself is missing is unchanged.Adds a regression test under
TestDeleteSession.