Agent loops on Read tool when saving memory — re-reads same file repeatedly
Bug description
Claude Code enters a loop calling the Read tool on the same file repeatedly without making progress, before eventually writing memory. This happens when the agent intends to update a memory file but gets stuck re-reading an unrelated code file.
Steps to reproduce
- Have a long coding session where Claude reads several source files
- At the end of the session, Claude decides to save/update a memory file
- Claude says "Đủ rồi. Ghi memory..." (or equivalent "I have enough context, writing memory now") but then calls
Readon a source file again instead - This repeats many times (10+
Readcalls on the same file) before the agent finally callsWriteon the memory file
Expected behavior
Once the agent has determined it has enough context to write memory, it should call Write directly without re-reading source files it already read earlier in the session.
Actual behavior
The agent re-reads the same file (e.g. arrange-grouping.service.ts) over and over, each time saying it has enough context but then reading again. The tool caching system returns "File unchanged since last read" on some calls but the agent continues anyway.
Impact
Significant token waste for the user — in this case 10+ unnecessary Read calls on a ~190-line file, each consuming context and billing cost.
Environment
- Claude Code CLI
- Model: claude-sonnet-4-6
- Platform: macOS
Suggested fix
The agent should check whether a file has already been read in the current session before re-reading it when the intent is to write memory, not gather new information.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗