Edit tool: 'File has not been read yet' error persists after multiple Read calls in long conversations
Bug Description
The Edit tool repeatedly returns File has not been read yet. Read it first before writing to it. even after the file has been successfully read multiple times in the same conversation.
Steps to Reproduce
- Start a long conversation with many tool calls (50+ tool uses across multiple files)
- Read a file with the Read tool (confirmed successful - contents are returned)
- Immediately attempt to Edit the same file
- Error:
File has not been read yet. Read it first before writing to it. - Read the file again - contents returned successfully
- Attempt Edit again - same error
- This cycle repeats indefinitely for the specific file
Expected Behavior
After a successful Read of a file, the Edit tool should recognize the file as read and allow edits.
Actual Behavior
The Edit tool's internal read-tracking appears to lose state for certain files in long conversations. The file in question is a long older language file (Somefile.cfc) was read at least 3 times with full contents returned each time, but every Edit attempt was rejected.
Other files in the same conversation were editable without issues. The problem seemed specific to this one file and may be related to context window pressure or message compaction in very long sessions.
Environment
- Claude Code CLI (VS Code extension)
- Model: claude-opus-4-6
- Very long conversation with 50+ tool calls, multiple file reads/edits across ~20 files
- The conversation had been compacted/summarized at least once due to context limits
Workaround
None found within the Edit tool. User had to fall back to using sed via Bash (which is explicitly discouraged in the tool guidelines).
🤖 Generated with Claude Code
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗