[BUG] EEXIST: file already exists, mkdir on Windows when target directory already exists — affects both Write and Edit tools
Preflight Checklist
- [ ] 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?
On Windows, both the Write and Edit tools fail with an EEXIST error when the target file's parent directory already exists. The extension appears to call mkdir on the parent directory path before every file operation (including edits on already-existing files), and does not gracefully handle the case where the directory is already present.
What Should Happen?
Both Write and Edit succeed. If the parent directory already exists, mkdir should be a no-op (equivalent to mkdir -p / fs.mkdir with { recursive: true } and EEXIST suppressed on Windows).
Error Messages/Logs
EEXIST: file already exists, mkdir 'C:\...\views\mca'
Steps to Reproduce
On Windows, open a project in VS Code with the Claude extension
Have a directory already exist at the target path (e.g. views/mca/)
Ask Claude to either:
Write a new file inside that directory, or
Edit an existing file inside that directory
Both operations fail with EEXIST on mkdir
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
sonnet 4.6
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
VS Code integrated terminal
Additional Information
Environment
OS: Windows 11
Tool: Claude VS Code Extension
Bash execution: disabled (org policy)
Root Cause Hypothesis
The extension likely calls fs.mkdir(dirPath, { recursive: true }) before every file operation. On certain Windows + Node.js version combinations, this still throws EEXIST for existing directories instead of silently succeeding. The fix would be to catch and suppress EEXIST specifically on Windows after the mkdir call.
Workaround
None available within the extension when Bash is disabled by org policy. Users are forced to manually paste file content in VS Code.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗