Write/Edit tools throw EEXIST when parent directory already exists
Bug Description
The Write and Edit tools throw EEXIST: file already exists, mkdir when attempting to write/edit files in directories that already exist. This happens consistently on Windows 11 with any pre-existing directory path.
Steps to Reproduce
- Have an existing directory, e.g.,
C:\Users\user\project\some\existing\dir\ - Use the
Writetool to create a new file in that directory - Or use the
Edittool to modify an existing file in that directory
Error:
EEXIST: file already exists, mkdir 'C:\Users\user\project\some\existing\dir'
Root Cause
The Write/Edit tools internally call fs.mkdirSync(parentDir) without {recursive: true} before writing the file. Node.js mkdirSync without the recursive flag throws EEXIST if the directory already exists.
Proof:
const fs = require('fs');
const p = 'C:/existing/directory';
fs.mkdirSync(p); // THROWS EEXIST
fs.mkdirSync(p, { recursive: true }); // Works fine
Fix
Change the internal mkdirSync(parentDir) call to mkdirSync(parentDir, { recursive: true }), which silently succeeds when the directory already exists.
Environment
- OS: Windows 11 Pro 10.0.26200
- Shell: Git Bash
- Claude Code model: claude-opus-4-6
- Filesystem: NTFS via OneDrive sync (but issue is NOT OneDrive-specific — reproducible on any pre-existing directory)
- Node.js: v22.17.1
Workaround
Use python3 -c "open('path', 'w').write(content)" via the Bash tool instead of the Write tool for affected directories.
Impact
This blocks the Write and Edit tools from working in any pre-existing directory. It's particularly noticeable with deeply nested paths containing spaces/special characters (common in project structures), but it affects ALL pre-existing directories.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗