Write/Edit tools throw EEXIST when parent directory already exists

Resolved 💬 3 comments Opened Mar 5, 2026 by Shinghid Closed Mar 9, 2026

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

  1. Have an existing directory, e.g., C:\Users\user\project\some\existing\dir\
  2. Use the Write tool to create a new file in that directory
  3. Or use the Edit tool 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.

View original on GitHub ↗

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