Worktree memory changes should be staged, not immediately global
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
- Open a worktree session in Claude Code
- Have Claude make a code change and update memory (e.g. "use
just run-debug-with-logsinstead ofjust run-debug-camera-box") - Switch to a different branch / main session
- 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.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗