Write tool fails with EEXIST on Windows when parent directory already exists

Resolved 💬 4 comments Opened Mar 6, 2026 by MarkmanAi Closed Apr 4, 2026

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

  1. Have an existing directory (e.g. docs/stories/active/) that already contains files
  2. Use the Write tool to create a new file inside that directory (e.g. docs/stories/active/13.1.story.md)
  3. 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.

View original on GitHub ↗

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