feat(plugin): git-aware-history — fix session fragmentation across git worktrees#58646
Open
ilanp-ob wants to merge 2 commits into
Open
feat(plugin): git-aware-history — fix session fragmentation across git worktrees#58646ilanp-ob wants to merge 2 commits into
ilanp-ob wants to merge 2 commits into
Conversation
Adds a plugin that fixes Claude Code session history fragmentation across git worktrees. All worktrees of a repo share one history directory, keyed by the git root (via `git rev-parse --git-common-dir`) rather than the CWD. Components: - PATH wrapper script (~/.local/bin/claude) for ongoing session routing - consolidate-git-history.sh for retroactive migration of existing history - /consolidate-history command for end-to-end setup Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was referenced May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Claude Code keys session history by the raw CWD path (
~/.claude/projects/<slug>/). When you use git worktrees, each worktree gets its own isolated history directory. Deleting a worktree orphans its history —/resumecan't find it, and there is no way to see all sessions for a repo in one place.Active worktree users end up with dozens of orphaned history directories after a sprint.
Solution
git rev-parse --git-common-dirreturns the same.gitpath for any worktree of a repo. This plugin uses that as the canonical project identity, so all worktrees of a repo share one history directory.Components
1. PATH wrapper script — ongoing routing
A
claudewrapper script installed to~/.local/bin/claude(before the real binary on PATH). No shell function, no.zshrcsourcing, no alias needed — works in every shell, terminal, and IDE integration out of the box.Gated by a flag file (
~/.claude/git-aware-history.enabled) so users can disable it without removing the script.2. Consolidation script — retroactive migration
consolidate-git-history.sh(~430 lines, bash, macOS/Linux, no extra deps beyondgitandpython3).Dry-run by default;
--executeto apply.3.
/consolidate-historycommandEnd-to-end setup in one command: installs the PATH wrapper, creates the flag file, shows dry-run preview, runs migration, verifies PATH ordering.
Proposed upstream fix (for reference)
Two parts:
A. New setting
{ "gitAwareHistory": true }Default
true(strictly better for worktree users, no-op outside git repos).B. One function change in project-path computation
Uses
execFile(fixed argument array, no shell injection risk). Non-git users are completely unaffected.Test plan
/consolidate-historyfrom a worktree~/.local/bin/claudeis created and executable~/.claude/git-aware-history.enabledflag file is created~/.claude/projects/<root-slug>/directoryconsolidate-git-history.sh --dry-runagainst existing history (no changes written)--executein a temp dir:PROJECTS_DIR=$(mktemp -d) bash consolidate-git-history.sh --executeTracked in: #52113
🤖 Generated with Claude Code