Worktree memory changes should be staged, not immediately global

Resolved 💬 2 comments Opened May 25, 2026 by earlye Closed Jun 25, 2026

Summary

When Claude Code operates in a git worktree (isolated copy of a repo), any memory files it writes are immediately visible to agents on other branches. This causes a confusing experience where an agent on main references features or patterns that only exist on an unmerged branch.

Expected behavior

Memory changes made during a worktree session should be staged locally and only persisted to global memory when the user explicitly exits the worktree with intent to keep them (e.g. "remove worktree, persist memories"). Until then, they should be invisible to agents outside that worktree.

Actual behavior

Memory is written immediately to the global memory directory (e.g. ~/.claude/projects/.../memory/), making it visible to all agents regardless of which branch or worktree they are operating in.

Steps to reproduce

  1. Open a worktree session in Claude Code
  2. Have Claude make a code change and update memory (e.g. "use just run-debug-with-logs instead of just run-debug-camera-box")
  3. Switch to a different branch / main session
  4. A new agent will reference the memory-described feature even though the underlying code change hasn't been merged yet

Suggested fix

Worktree sessions should write memory to a staging area local to the worktree. On exit, prompt the user: "Persist memory changes to global memory?" (or expose a remove worktree, persist memories command). Discard staged memory if the worktree is removed without persisting.

View original on GitHub ↗

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