Write tool fails with EEXIST on Windows when parent directory already exists
Bug Report
Environment:
- OS: Windows 11 Pro (10.0.26200)
- Shell: bash (Git Bash)
- Platform: win32
Description
The Write tool fails with EEXIST: file already exists, mkdir when attempting to create a file inside a directory that already exists on Windows.
Steps to Reproduce
- Have an existing directory (e.g.
docs/stories/active/) that already contains files - Use the
Writetool to create a new file inside that directory (e.g.docs/stories/active/13.1.story.md) - Observe the error
Error
Error: EEXIST: file already exists, mkdir 'C:\Users\markm\OneDrive\Documentos\GitHub\aios-core\docs\stories\active'
Root Cause
The Write tool internally calls mkdir on the parent directory before writing the file, but does not pass { recursive: true } to the Node.js fs.mkdirSync / fs.mkdir call.
On Windows, calling mkdir on an already-existing directory throws EEXIST instead of silently succeeding. On Linux/macOS this may behave differently due to OS-level differences.
Expected Behavior
The Write tool should create the parent directory using { recursive: true }:
// Current (broken on Windows)
fs.mkdirSync(parentDir)
// Fix
fs.mkdirSync(parentDir, { recursive: true })
This is the standard Node.js pattern to ensure idempotent directory creation and is already used in the rest of the codebase.
Workaround
Use Bash tool with shell redirection as a fallback when Write fails on existing directories.
Impact
Blocks any Write operation targeting files in pre-existing directories on Windows. Affects all Windows users working in repositories where directories already exist.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗