Feature request: Share sessions across git worktrees
Summary
Claude Code currently stores sessions based on the directory path. However, when using git worktrees, multiple directories share the same underlying .git directory and repository history. It would be valuable if Claude Code could detect this relationship and share sessions across worktrees.
Problem
Git worktrees allow developers to check out multiple branches simultaneously in different directories while sharing the same .git directory. Currently, each worktree directory is treated as a completely separate project by Claude Code, meaning:
- Sessions started in one worktree are not accessible from another worktree of the same repository
- Context about the codebase built up in one worktree cannot be leveraged when switching to work in another
- Developers must re-establish context when moving between worktrees
Proposed Solution
Claude Code could detect when a directory is part of a git worktree setup by checking for the .git file (which points to the main worktree's .git directory) or by using git rev-parse --git-common-dir. Sessions could then be keyed by the common git directory rather than the working directory path, allowing them to be shared across all worktrees of the same repository.
Use Case
When working on multiple features in parallel using git worktrees, it is common to:
- Have a main worktree on
mainbranch for reference - Have separate worktrees for different feature branches
- Switch between them frequently while developing
Being able to share session context across these worktrees would significantly improve the development workflow, as Claude Code would retain understanding of the codebase architecture, coding conventions, and ongoing discussions regardless of which worktree is currently active.
Additional Context
git worktree listcan enumerate all worktrees for a repositorygit rev-parse --git-common-dirreturns the shared git directory- This feature would be opt-in or could be enabled by default with an option to disable
Thank you for considering this enhancement.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗