Edit tool fails with 'File has been unexpectedly modified' when PreToolUse hook is active
Resolved 💬 2 comments Opened Dec 27, 2025 by sirSUPA013 Closed Dec 27, 2025
Version
Claude Code 2.0.76, Windows 11
Description
When a PreToolUse hook is configured, the Edit tool frequently fails with "File has been unexpectedly modified. Read it again before attempting to write it." even when the file hasn't actually changed.
Steps to reproduce
- Configure a PreToolUse hook in settings.json (any command, even a simple echo)
- Use Read tool to read a file
- Immediately use Edit tool to modify the same file
- Error occurs
Expected behavior
Edit should succeed if the file content hasn't changed.
Actual behavior
Edit fails with modification error. The PreToolUse hook execution between Read and Edit appears to trigger false positive modification detection.
Workaround
Disable PreToolUse hook, or use Bash with Python/sed for file edits instead of the Edit tool.
Additional Notes
- Moving hook output files to a different directory (AppData) did not resolve the issue
- The file being edited is not touched by the hook
- Issue does not occur when PreToolUse hook is disabled
- The hook runs between the Read and Edit tool calls, which seems to trigger the false positive
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗