[BUG] Bash tool permanently fails with EEXIST on session-env mkdir (Windows) — triggers after context compression and spontaneously
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
The Bash tool becomes permanently broken mid-session on Windows. Every Bash invocation fails before the command even runs:
EEXIST: file already exists, mkdir 'C:\Users\<user>\.config\claude-agenty\session-env\<session-id>'
This happens in two distinct scenarios:
- After context compression — the most reliable trigger. The same session ID is reused post-compression, but the Bash subsystem re-initializes and tries to
mkdira directory that already exists from earlier in the session. - Spontaneously during long sessions — without compression, after Bash has been idle for a period, it appears to restart internally and hits the same non-idempotent
mkdiron the already-existing session dir.
Once triggered, every subsequent Bash call fails identically for the rest of the session. No self-recovery is possible from inside Claude Code.
What Should Happen?
Bash commands should continue working normally throughout the session, including after context compression and after idle periods. The session-env directory creation should be idempotent.
Error Messages/Logs
EEXIST: file already exists, mkdir 'C:\Users\asafe\.config\claude-agenty\session-env\d7ab5c75-4ec3-4e4f-92fd-6af08657825b'
The error appears as the tool result for every Bash call after the trigger event. The session ID in the path is the same session ID assigned at session start.
Steps to Reproduce
Trigger 1 (compression — most reliable):
- Start a Claude Code session on Windows with enough work to trigger auto-compression (long conversation with many tool calls)
- Wait for context compression to complete
- Attempt any Bash command, e.g.
echo hi - Observe: EEXIST error instead of command output
- Retry — same error every time for the rest of the session
Trigger 2 (spontaneous):
- Start a long session on Windows
- Use Bash actively early in the session, then leave it idle for a period
- Later in the same session, invoke Bash again
- Observe: same EEXIST error, permanent for rest of session
Workaround (requires external terminal):
Remove-Item -Recurse -Force "$env:USERPROFILE\.config\claude-agenty\session-env\<session-id>"
Must be repeated each time the bug fires.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
N/A
Claude Code Version
2.1.112 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Other
Additional Information
- Custom config dir:
~/.config/claude-agenty/(set viaCLAUDE_CONFIG_DIR). Expect identical behavior with the default~/.claude/session-env/path. - Shell inside Claude Code is bash (MSYS2/Git Bash via the Bash tool), not PowerShell.
- Read, Edit, Glob, Grep, and MCP tools are unaffected — only Bash is broken.
- In agentic/automated workflows this silently blocks git, deploys, and any CLI tool mid-task.
Suspected root cause: The Bash subsystem re-initializes after compression (and possibly after shell idle timeout), calling something equivalent to fs.mkdirSync(sessionEnvDir) without { recursive: true }. First init succeeds; any re-init on the same session ID crashes on the existing dir.
Suggested one-line fix:
fs.mkdirSync(sessionEnvDir, { recursive: true });
Previously filed as #56191 (bot account) and #56591 (malformed) — this is the canonical report.
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗