claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Short-lived SDK/headless sessions leave empty ~/.claude/session-env/<uuid> dirs (and state/, bridge-spawn, .cc-writes) behind

Open voidfreud opened this issue 1 month ago • 0 comments

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

  1. Note the contents of ~/.claude/session-env/ and ~/.claude/backups/.
  2. Run 20–30 sequential Agent SDK query() calls with a trivial prompt and wait for each to finish.
  3. 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).

voidfreud avatar Oct 20 '26 17:10 voidfreud