Repository navigation
fix: key memory to the main checkout for git worktree sessions (#56) - #127
Conversation
…al-Process-Tools#56) Claude Code sets CLAUDE_PROJECT_DIR to the worktree path for worktree sessions, so REMEMBER_DIR resolved inside the worktree. In the default layout memory landed in <worktree>/.remember — gitignored with `*`, so a plain `git worktree remove` deleted it silently (no --force, no warning) and never migrated it to the main checkout. In external mode the {slug} was computed from the worktree path, producing an orphaned ~/.remember/<slug-of-worktree> the main checkout's sessions never load. Resolve REMEMBER_DIR through git's common dir: when PROJECT_DIR is a linked worktree, memory is keyed to the repo's main checkout, so it survives `worktree remove` and is shared across worktrees. PROJECT_DIR is left as the worktree path so session recovery still resolves transcripts under the worktree slug. Fail-safe: only redirects on a positively-identified linked worktree whose main checkout is a real work tree — ordinary checkouts, non-git dirs, bare-repo worktrees, and git without --path-format all behave exactly as before. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Thanks for this, @jeongph — really clean fix. 🙏 Reviewed and verified the core logic rather than just reading it:
The fail-safe design (common-dir ≠ git-dir + main-checkout-is-worktree guard) is exactly right, and the tests using real One minor, non-blocking follow-up (in LGTM. 👍 |
After #127 keyed memory to the main checkout, a session running in a linked worktree keeps PROJECT_DIR on the worktree while REMEMBER_DIR points into the main checkout. The legacy guard in 50-git-backup.sh compares those two paths, so it stopped matching: the hook mistook the project repo for a dedicated backup repo, deleted the protective .remember/.gitignore (`*`), committed the whole memory tree onto whatever branch the main checkout had out, and pushed it to the project's origin — private session notes on a shared remote, on an unrelated feature branch. Compare git *common dirs* instead of paths. Every worktree of a repo shares one common dir, so the plain, worktree and subdirectory layouts are all covered at once, while a repo genuinely dedicated to memory backup keeps a different common dir and still activates. Old git without --path-format falls back to resolving the relative form; if even that fails, previous behaviour is untouched. Co-Authored-By: Max <noreply>
…pdate (#133) Claude Code's plugin updater compares .claude-plugin/plugin.json versions, not source SHAs. The 0.8.4 release shipped without bumping the manifest, so every marketplace install kept answering "already at the latest version (0.8.3)" and silently never received #122/#123 (a silent, self-reinforcing consolidation stall) or the #127 worktree fix. Users had no signal they were stale — the updater actively told them they were current. Bump the manifest to 0.8.5 (carrying #56/#127, #125 and #138), and add tests/test_version_manifest.py so CI fails whenever the manifest drifts from the newest released CHANGELOG heading. The bump can no longer be forgotten silently. Co-Authored-By: Max <noreply>
Summary
Fixes #56 — memory built up during a git worktree session was thrown away instead of being kept with the repository.
Claude Code sets
CLAUDE_PROJECT_DIRto the worktree path for worktree sessions, and the plugin derivesREMEMBER_DIRfrom it. So:<worktree>/.remember, physically inside the worktree. Because the plugin gitignores it with*, a plaingit worktree remove(no--force, no warning) deletes everynow.md/today-*.md/remember.mdfrom that session, and none of it is migrated to the main checkout.{slug}was computed from the worktree path, producing an orphaned~/.remember/<slug-of-worktree>subtree the main checkout's sessions never load.This matches the observation and fix direction in #56 (thanks @KrzysztofKasprowicz for the report and @dewet22 for the diagnosis).
Fix
REMEMBER_DIRresolution now routes through git's common dir. WhenPROJECT_DIRis a linked worktree, memory is keyed to the repo's main checkout, so it:git worktree remove, andCLAUDE_PROJECT_DIR/PROJECT_DIRis left untouched — session recovery still resolves transcripts under the worktree slug Claude Code computed, exactly as @dewet22 flagged.Fail-safe by design
The redirect only fires when a linked worktree is positively identified (git's common-dir ≠ git-dir) and the computed main checkout is a real work tree. These all fall through to the unchanged
PROJECT_DIR:--path-format(< 2.31)So non-worktree and non-git users see byte-for-byte identical behavior.
Changes
scripts/lib-memory-dir.sh— new_resolve_memory_project_dir();REMEMBER_DIRis resolved against it and it is exported asMEMORY_PROJECT_DIR.scripts/bootstrap-dirs.sh— the one-shot legacy→external migration and the.gitignorewrite are keyed toMEMORY_PROJECT_DIRso they stay consistent with whereREMEMBER_DIRnow resolves.tests/test_worktree_memory.py— new: legacy + external resolution in a real worktree, regression guards for non-worktree / non-git, the shared-dir invariant, and that session-start emits=== HANDOFF ===pointing at the main checkout (the existingREMEMBER_ROOT != PROJECT_DIRguard already covers this onceREMEMBER_DIRis redirected).CHANGELOG.md,README.md— document the behavior (new "Git worktrees" section).Handoff interaction (no extra code needed)
In legacy mode the
=== HANDOFF ===hint is normally suppressed (#118) because the/rememberskill's fallback{project}/.remember/remember.mdalready matches. Inside a worktree that fallback would be wrong — but session-start's existingREMEMBER_ROOT != PROJECT_DIRguard now fires (sinceREMEMBER_ROOTis the main checkout ≠ the worktreePROJECT_DIR), so the hint is emitted and the skill writes the handoff to the main checkout. A test locks this in.Testing
pytestwith coverage): 500 passed, 43 skipped, 98.24% coverage.tests/test_worktree_memory.pyuses realgit worktreelayouts.git worktree removeand lands in the main checkout's.remember/.🤖 Generated with Claude Code