[BUG] Short-lived SDK/headless sessions leave empty ~/.claude/session-env/<uuid> dirs (and state/, bridge-spawn, .cc-writes) behind
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report
- [x] I am using the latest version of Claude Code
What's Wrong?
After about 40 short Agent SDK sessions (each a single prompt and reply, run by a test harness over ~20 minutes), ~/.claude/session-env/ held 30 new empty <session-uuid> directories that were never removed. The same sessions also created ~/.claude/state/ (with mcp-discover-verdicts.json), ~/.claude/bridge-spawn/ and ~/.claude/.cc-writes/, and rotated ~/.claude/backups/.claude.json.backup.*, which pushed out all pre-existing backups.
What Should Happen?
Ending a session, especially a non-persistent SDK session, should remove its empty session-env/<uuid> directory and any per-session scaffolding. Backup rotation shouldn't let a burst of programmatic sessions evict every earlier .claude.json backup.
Steps to Reproduce
- Note the contents of
~/.claude/session-env/and~/.claude/backups/. - Run 20–30 sequential Agent SDK
query()calls with a trivial prompt and wait for each to finish. - List
~/.claude/session-env/: one empty directory per session remains. Compare~/.claude/backups/with step 1.
Is this a regression?
I don't know
Claude Code Version
2.1.304 (claude-agent-sdk 0.2.168)
Platform
Anthropic API
Operating System
macOS (26.x)
Terminal/Shell
Other (Ghostty)
Additional Information
Related: #103797 (filed today: no isolated-config mode, so these land in the user's real ~/.claude).