Auto memory file is not safe for concurrent agent teams

Resolved 💬 4 comments Opened Feb 8, 2026 by wkusnierczyk Closed Mar 8, 2026

Problem

The auto memory directory (~/.claude/projects/<project>/memory/MEMORY.md) is a plain file with no concurrency control. The Edit tool does read-match-replace-write with no locking.

With the new agent teams feature, multiple teammates share the same project-scoped memory file. If two agents try to write to it concurrently, the last write wins and the other's changes are silently lost.

Reproduction

  1. Enable agent teams on a project
  2. Have two teammates independently discover something worth recording
  3. Both attempt to Edit the same MEMORY.md at roughly the same time
  4. One agent's update is lost

Expected behavior

Concurrent memory writes should be safe — either via file-level locking, append-only writes, or a merge strategy.

Possible approaches

  • File lock (flock or equivalent) around memory file reads/writes
  • Append-only log — each agent appends entries; a periodic compaction pass deduplicates
  • Per-agent memory files — each teammate writes to its own file (e.g. memory/<agent-id>.md), with a merged view loaded into the system prompt
  • CAS (compare-and-swap) — re-read before write, retry if content changed since last read

Context

This also affects background agents launched via Task with run_in_background, which can run concurrently with the main session and other background agents.

View original on GitHub ↗

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