[BUG] "File unexpectedly modified" error when using Edit tool in VSCode

Resolved 💬 5 comments Opened Dec 31, 2025 by eastpak1 Closed Feb 15, 2026

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?

Environment
Claude Code Extension Version: 2.0.76
VSCode Version: 1.107.1
OS: Windows 11
Python: 3.14
Installed Python extensions: ms-python.python, ms-python.vscode-pylance, ms-python.debugpy, ms-python.vscode-python-envs

Issue Description
When using the Edit tool to modify Python files, I frequently receive the error:
File has been unexpectedly modified. Read it again before attempting to write it.

This happens even when:
No manual edits are being made to the file
The file was just read by Claude Code moments before
Only a WebSocket server (separate Python process) is running

What Should Happen?

The Edit tool should reliably modify files without requiring workarounds

Error Messages/Logs

Steps to Reproduce

Have a Python project open in VSCode with Claude Code extension
Have a Python script running (importing modules from the project)
Ask Claude to edit a Python file in the project
Claude reads the file successfully
Claude attempts to edit the file
Error: "File has been unexpectedly modified"
Re-reading and re-attempting the edit often fails again. The workaround is to use a Python script via py -c "..." to do direct file I/O, which works reliably.

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.0.76

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

VS Code integrated terminal

Additional Information

Observations
The issue seems related to VSCode's file watching or the Python/Pylance extensions
Files that are imported by running Python processes seem more likely to trigger this
The issue does not occur (or occurs much less frequently) in Windsurf with similar Claude integration

Suspected Cause
There may be a race condition between:
Claude Code reading and caching file content
VSCode/Pylance/Python extension touching the file (for indexing, validation, etc.)
Claude Code attempting to write the edit
The time gap between read and edit allows other processes to modify file metadata or content.

Workaround
Using Python's direct file I/O bypasses the issue:

py -c "
with open('path/to/file.py', 'r') as f:
content = f.read()
content = content.replace('old_string', 'new_string')
with open('path/to/file.py', 'w') as f:
f.write(content)
"

View original on GitHub ↗

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