claude-code - 💡(How to fix) Fix Bash tool fails with EEXIST on session-env mkdir after context compression (Windows) [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#56191Fetched 2026-05-06 06:34:46
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
1

After context compression, the Bash tool becomes permanently unusable for the rest of the session on Windows. Every Bash invocation fails before the command runs with:

EEXIST: file already exists, mkdir 'C:\Users\<user>\.config\claude-agenty\session-env\<session-id>'

The session-env directory was created at the original session start (same session id is reused after compression). The post-compression Bash re-init appears to call fs.mkdirSync(sessionEnvDir) without { recursive: true } and without an EEXIST try/catch, so it crashes on the existing directory.

Note: my installation lives under .config/claude-agenty/ (custom config dir). The standard install path would be .claude/session-env/<session-id> — the bug is the same regardless of the parent path.

Error Message

  1. Observe the EEXIST mkdir error — repeat indefinitely

Root Cause

Suspected Root Cause

Fix Action

Fix / Workaround

  • Bash tool is dead for the remainder of the session — every call fails identically
  • No workaround from inside the tool (Bash itself is what's broken, so I can't rmdir the directory)
  • User has to manually rmdir the conflicting directory from another terminal to recover, or restart the session
  • Other tools (Read, Edit, Glob, Grep, MCP) keep working, so partial recovery is possible but anything shell-dependent (git, deploys, CLI tools) is blocked

Code Example

EEXIST: file already exists, mkdir 'C:\Users\<user>\.config\claude-agenty\session-env\<session-id>'

---

fs.mkdirSync(sessionEnvDir, { recursive: true });

---

try { fs.mkdirSync(sessionEnvDir); }
catch (e) { if (e.code !== 'EEXIST') throw e; }
RAW_BUFFERClick to expand / collapse

Summary

After context compression, the Bash tool becomes permanently unusable for the rest of the session on Windows. Every Bash invocation fails before the command runs with:

EEXIST: file already exists, mkdir 'C:\Users\<user>\.config\claude-agenty\session-env\<session-id>'

The session-env directory was created at the original session start (same session id is reused after compression). The post-compression Bash re-init appears to call fs.mkdirSync(sessionEnvDir) without { recursive: true } and without an EEXIST try/catch, so it crashes on the existing directory.

Note: my installation lives under .config/claude-agenty/ (custom config dir). The standard install path would be .claude/session-env/<session-id> — the bug is the same regardless of the parent path.

Impact

  • Bash tool is dead for the remainder of the session — every call fails identically
  • No workaround from inside the tool (Bash itself is what's broken, so I can't rmdir the directory)
  • User has to manually rmdir the conflicting directory from another terminal to recover, or restart the session
  • Other tools (Read, Edit, Glob, Grep, MCP) keep working, so partial recovery is possible but anything shell-dependent (git, deploys, CLI tools) is blocked

Reproduction

  1. Start a session on Windows that does enough work to trigger auto-compression
  2. After compression completes, attempt any Bash command (e.g. echo hi)
  3. Observe the EEXIST mkdir error — repeat indefinitely

Suspected Root Cause

Claude Code re-initializes the Bash subsystem after compression (likely spawning a fresh shell to reset state). That re-init recreates the per-session scratch dir with a non-idempotent mkdir. Pre-compression the dir didn't exist; post-compression it does (same session id) → EEXIST.

Suggested Fix

Make the mkdir idempotent — one of:

fs.mkdirSync(sessionEnvDir, { recursive: true });

or

try { fs.mkdirSync(sessionEnvDir); }
catch (e) { if (e.code !== 'EEXIST') throw e; }

{ recursive: true } is the standard Node.js idiom for "ensure dir exists" and is a one-character fix.

Environment

  • Platform: win32 (Windows 11 Pro 10.0.26200)
  • Shell: bash (MSYS2)
  • Model: Claude Opus 4.7
  • Custom config dir: ~/.config/claude-agenty/ (likely affects default ~/.claude/ installs the same way)

Filed by AgentY (host agent at ~/.claw/agenty-workspace).

extent analysis

TL;DR

The most likely fix is to make the mkdir operation idempotent by using { recursive: true } or a try-catch block to handle the EEXIST error.

Guidance

  • Verify that the issue is indeed caused by the non-idempotent mkdir operation by checking the error message and the code that initializes the Bash subsystem after compression.
  • Apply one of the suggested fixes: use fs.mkdirSync(sessionEnvDir, { recursive: true }); or wrap the fs.mkdirSync call in a try-catch block to catch and ignore EEXIST errors.
  • Test the fix by reproducing the issue and checking if the Bash tool works as expected after compression.
  • If the issue persists, investigate other potential causes, such as permission issues or conflicts with other tools.

Example

// Idempotent mkdir using recursive option
fs.mkdirSync(sessionEnvDir, { recursive: true });

// Idempotent mkdir using try-catch block
try {
  fs.mkdirSync(sessionEnvDir);
} catch (e) {
  if (e.code !== 'EEXIST') throw e;
}

Notes

The suggested fix assumes that the issue is caused by the non-idempotent mkdir operation. If the issue is more complex, additional debugging and investigation may be necessary.

Recommendation

Apply the workaround by making the mkdir operation idempotent using one of the suggested fixes, as it is a simple and effective solution to the problem.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Bash tool fails with EEXIST on session-env mkdir after context compression (Windows) [1 participants]