Bash tool fails with EEXIST on session-env mkdir — occurs after context compression AND spontaneously (Windows)

Resolved 💬 2 comments Opened May 6, 2026 by a5af Closed May 6, 2026

Summary

The Bash tool becomes permanently unusable mid-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>'

This happens in two distinct scenarios:

  1. After context compression — the most common trigger. The same session-id is reused post-compression, but Bash re-init tries to mkdir a dir that already exists.
  2. Spontaneously, mid-session without compression — occurs during long sessions where Bash is idle for a period, then re-invoked. The Bash subsystem appears to restart (possibly due to shell timeout or process death), hits the same mkdir path, and fails identically.
My install uses a custom config dir: .config/claude-agenty/. Standard path would be .claude/session-env/<session-id>. Same bug either way.

Impact

  • Bash tool is dead for the remainder of the session — every call fails identically
  • No self-recovery possible — Bash itself is broken, so the agent can't rmdir the directory from inside
  • User must manually delete the conflicting dir from an external terminal, or restart the session
  • Read, Edit, Glob, Grep, MCP tools continue working — anything shell-dependent (git, deploys, CLIs) is blocked
  • In agentic workflows this silently breaks long-running tasks mid-execution

Reproduction

Trigger 1 (compression):

  1. Start a session on Windows, do enough work to trigger auto-compression
  2. After compression, attempt any Bash command (echo hi)
  3. EEXIST error — permanent for rest of session

Trigger 2 (spontaneous):

  1. Start a long session with periods of Bash inactivity
  2. After an idle period, invoke Bash again
  3. Same EEXIST error — suggests the shell process died and re-init is attempted

Suspected Root Cause

The per-session scratch dir is created with a non-idempotent mkdir. On first init it succeeds. On any subsequent re-init (compression, shell restart, idle timeout) the dir already exists → EEXIST crash.

The shell process appears to restart without first checking whether the session dir already exists.

Suggested Fix

One-line fix — make the mkdir idempotent:

// Option A (preferred Node.js idiom)
fs.mkdirSync(sessionEnvDir, { recursive: true });

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

Environment

  • Platform: win32 (Windows 11 Pro 10.0.26200)
  • Shell: bash (MSYS2 / Git Bash)
  • Claude Code version: latest (2026-05)
  • Custom config dir: ~/.config/claude-agenty/ (same bug expected at ~/.claude/)

Workaround

From an external terminal:

Remove-Item -Recurse -Force "$env:USERPROFILE\.config\claude-agenty\session-env\<session-id>"

Then retry the Bash command. This must be repeated each time the bug fires.

---

Previously filed as #56191 by a bot account — refiling as a human with the additional spontaneous-trigger context.

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗