claude-code - 💡(How to fix) Fix Worktree memory changes should be staged, not immediately global

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

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.

Root Cause

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.

RAW_BUFFERClick to expand / collapse

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.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

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.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING