Skip to content

feat: delete_session() cascades subagent transcript dir#805

Open
qing-ant wants to merge 1 commit intomainfrom
qing/delete-session-subagent-cascade
Open

feat: delete_session() cascades subagent transcript dir#805
qing-ant wants to merge 1 commit intomainfrom
qing/delete-session-subagent-cascade

Conversation

@qing-ant
Copy link
Copy Markdown
Contributor

@qing-ant qing-ant commented Apr 9, 2026

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 existing FileNotFoundError when the .jsonl itself is missing is unchanged.

Adds a regression test under TestDeleteSession.

Copy link
Copy Markdown
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

IgorTavcar added a commit to IgorTavcar/claude-agent-sdk-python that referenced this pull request Apr 10, 2026
- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant