Agent loops on Read tool when saving memory — re-reads same file repeatedly

Resolved 💬 3 comments Opened Apr 26, 2026 by thevuong Closed May 31, 2026

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

  1. Have a long coding session where Claude reads several source files
  2. At the end of the session, Claude decides to save/update a memory file
  3. Claude says "Đủ rồi. Ghi memory..." (or equivalent "I have enough context, writing memory now") but then calls Read on a source file again instead
  4. This repeats many times (10+ Read calls on the same file) before the agent finally calls Write on 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.

View original on GitHub ↗

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