[BUG] Write tool fails with EEXIST on Windows + OneDrive for longer file paths
Preflight Checklist
- [x] 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?
Describe the bug
The Write tool fails with an EEXIST error when creating files at moderately long paths (~90+ characters absolute) on Windows with
OneDrive. The error comes from the mkdirSync({recursive: true}) call that ensures the parent directory exists before writing the file.
The parent directory already exists. The mkdir call should succeed silently but instead throws EEXIST.
Affected tool
Write tool only. Read and Edit work fine on the same paths — they skip the mkdir step.
Environment
- OS: Windows 11
- Shell: cmd.exe (Windows Terminal); Claude Code internally uses Git Bash/MSYS2
- Workspace location: Inside OneDrive sync folder (C:\Users\<user>\OneDrive\...\)
- Claude Code version: Observed across multiple recent versions
Suggested fix
Catch EEXIST from the mkdir call in the Write tool and continue — the directory existing is the success case, not an error. Something
like:
try {
fs.mkdirSync(parentDir, { recursive: true });
} catch (err) {
if (err.code !== 'EEXIST') throw err;
}
Workaround
Write to a short temp path (e.g. C:/tmp/file.ext) then move the file to the real location via Bash mv.
Related but distinct issues
- #31185, #30960, #30924, #31030 — EEXIST during startup on config/auth paths (different codepath, same underlying Node.js bug)
- #29153 — OneDrive .claude.json corruption (different symptom)
What Should Happen?
Expected behavior
mkdirSync(parentDir, {recursive: true}) should succeed silently when the directory already exists, as documented in the Node.js API.
Actual behavior
The call throws EEXIST. This appears to be a known Node.js edge case on Windows where recursive: true mkdir can throw EEXIST instead of
succeeding, exacerbated by OneDrive's file system overlay (reparse points / cloud placeholders).
Error Messages/Logs
EEXIST: file already exists, mkdir
Steps to Reproduce
- Run Claude Code from a workspace inside an OneDrive-synced directory with a moderately long base path
- Ask Claude to write a file where the absolute path is ~90+ characters (e.g. C:\Users\<user>\OneDrive\Personal\AI
workspace\projects\some-project\workflows\some-file.md)
- The parent directory already exists
- Write tool fails with EEXIST: file already exists, mkdir
Claude Model
Opus
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.1.71
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Windows Terminal
Additional Information
_No response_
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗