claude-code - 💡(How to fix) Fix [BUG] Edit tool silently clears file to 0 bytes on Windows [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#55518Fetched 2026-05-03 04:51:17
View on GitHub
Comments
2
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×4commented ×2

Error Message

The Edit tool reported "updated successfully" but actually wrote 0 bytes to the file, completely erasing its content. No error was thrown. The Edit tool should correctly apply the edit and preserve existing file content. If an error occurs, it should report the error instead of silently zeroing

Error Messages/Logs

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

The Edit tool reported "updated successfully" but actually wrote 0 bytes to the file, completely erasing its content. No error was thrown.

Evidence from file-history (path: ~/.claude/file-history/<session-id>/):

  • v3: 1576 bytes (May 1 16:47) — last known good version
  • v4: 0 bytes (May 1 23:43) — Edit tool produced an empty file
  • v5: 1841 bytes (May 2 14:38) — manually restored via Write tool

The affected file was ~/.claude/CLAUDE.md (global user instructions). The Edit tool was adding 3 new lines to the existing content. It claimed success but the file became completely empty.

What Should Happen?

The Edit tool should correctly apply the edit and preserve existing file content. If an error occurs, it should report the error instead of silently zeroing out the file.

Error Messages/Logs

Steps to Reproduce

  1. Have a non-empty file (e.g., ~/.claude/CLAUDE.md with ~1576 bytes)
  2. Use Claude Code Edit tool to make a small modification (e.g., add a few lines to the end)
  3. Edit tool reports success: "updated successfully"
  4. Check file content — it is now empty (0 bytes)

Note: This is intermittent. It happened once during a long session on Windows. Possible triggers:

  • Long session with /compact triggered
  • Windows CRLF/LF encoding edge case
  • Concurrent file access during context compaction

Environment: Windows 11 Pro, bash shell in Windows Terminal, Java project with ~50 Maven modules.

Claude Model

None

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.119

Platform

Other

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

No response

extent analysis

TL;DR

The Edit tool in Claude Code may be experiencing an intermittent issue where it silently overwrites files with empty content, potentially due to encoding or concurrent access issues.

Guidance

  • Verify the file encoding and line endings to ensure consistency, as the issue might be related to Windows CRLF/LF encoding edge cases.
  • Check for any concurrent file access or modifications during the editing process, as this could be a contributing factor to the issue.
  • Test the Edit tool with a small, controlled modification to see if the issue can be reliably reproduced, focusing on the steps to reproduce provided.
  • Consider enabling detailed logging or debugging to capture any potential error messages that might not be visible through the standard interface.

Example

No specific code snippet can be provided without further details on the Claude Code internals, but ensuring that file handling and editing operations are properly synchronized and encoded could be crucial.

Notes

The intermittent nature of the issue and the lack of explicit error messages make it challenging to pinpoint the exact cause. Further investigation into the Claude Code's file handling and editing mechanisms, as well as the specific environment and usage patterns, is necessary.

Recommendation

Apply workaround: Until the root cause is identified and fixed, users might need to manually verify file contents after using the Edit tool, especially in environments where concurrent file access is possible or when working with files that have specific encoding requirements.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] Edit tool silently clears file to 0 bytes on Windows [2 comments, 2 participants]