Session state should persist across git worktrees
Status Fixed / completed
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 6 comments · opened Dec 30, 2025 · closed Aug 17, 2026
When using git worktrees, Claude Code stores session state (.claude/) in the worktree folder rather than the main repository. This causes conversation history to be lost when the worktree is deleted after merging.
Current behavior
- Create worktree for feature branch
- Work with Claude Code (session stored in worktree's
.claude/) - Merge branch to main
- Delete worktree → session history lost
Expected behavior
Session state should be associated with the git repository identity, not the filesystem path. Options:
- Store sessions in the main repo's
.git/directory (shared by worktrees) - Associate sessions by repo remote URL or other repo identifier
- Allow session migration when worktree is removed
Use case
Worktrees are designed to be disposable - you create them for a branch, do work, merge, and delete. Tying session state to the worktree folder works against this workflow pattern.
Showing cached comments. Read the full discussion on GitHub ↗
5 Comments
Found 2 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
I don’t think this is a duplicate
My Specific Use Case
Typical Scenario (Context Loss When Creating Worktree)
git worktree add ../skybridge-worktrees-feature-x -b feature/x
cd ../skybridge-worktrees-feature-x
claude
Why This Is Problematic
Natural development workflow:
What I lose:
Cost of loss:
Current Workaround (Inefficient)
I have to take screenshots or copy-paste parts of the conversation, but:
Expected Solution
Continue parent branch conversation in child worktree:
cd ../skybridge-worktrees-feature-x
claude --resume-from-parent # Or something similar
Or automatically detect and offer:
> claude
Detected you're in a worktree.
Want to continue the parent branch session? [Y/n]
Last session: 337c2b22-... (2 hours ago, 87 messages)
This is a real pain point for me. I use worktrees heavily in my daily workflow — spin up a worktree for a feature branch, work with Claude Code, merge, delete the worktree. Losing all session history every time is really frustrating. I'm now saving all my worktrees and that's a lot of clutter, and it's hard to remember where the history is located and honestly I don't think that's how worktrees are supposed to be used.. 😅
I see that project configs and auto memory are now shared across worktrees (great!), but the session transcripts themselves are still tied to the worktree path. That's the critical missing piece. When the worktree goes away, so does all the conversation context — architecture decisions, trade-off discussions, everything.
Would love to see session storage resolved to the main repo's
.git/directory (or keyed by repo identity) so sessions survive worktree deletion. This would make the worktree workflow fully first-class.Workaround: Preserve sessions when removing git worktrees
Claude Code stores session history in
~/.claude/projects/keyed by the working directory path. Each worktree gets its own project key, so when you remove a worktree, those sessions disappear from/resumein the main repo.Add this function to your
~/.zshrcor~/.bashrc— it copies sessions from the worktree's project dir to the main repo's project dir before removing the worktree:Usage:
After removing, the worktree sessions show up in
/resumefrom the main repo. Verified on macOS.Automatic version: WorktreeRemove hook
You can also automate this with a
WorktreeRemovehook so sessions are preserved automatically when Claude Code cleans up worktrees (e.g., after--worktreesessions).1. Create
~/.claude/scripts/preserve-worktree-sessions.sh:Then
chmod +x ~/.claude/scripts/preserve-worktree-sessions.sh.2. Add to
~/.claude/settings.json:Note: the hook fires on clean exit (
/quit), not on Ctrl+C. The shell function from above still covers manual removal.