Repository navigation
Description
Summary
After #127 (key memory to the main checkout for git worktree sessions), the
after_save/50-git-backup.sh hook misidentifies an ordinary legacy-mode
setup as external git-backup mode whenever a session runs in a linked git
worktree. It then deletes the protective .remember/.gitignore (*), commits
the entire .remember/ folder onto whatever branch the main checkout happens
to have checked out, and pushes it to the project's origin.
Session memory (potentially sensitive notes) ends up on the team's shared
remote, mixed into an unrelated feature branch.
Environment
- Plugin version 0.8.3 from the
claude-plugins-officialmarketplace — but the
cached code contains the fix: key memory to the main checkout for git worktree sessions (#56) #127 worktree fix (see plugin.json version was never bumped for v0.8.4 — 'claude plugin update' reports 'already at the latest version (0.8.3)', so marketplace users never receive #123/#127 #133: the version was never
bumped for v0.8.4), i.e.scripts/lib-memory-dir.shresolvesREMEMBER_DIR
to the main checkout for worktree sessions. - Legacy (default) mode: memory lives at
<main-checkout>/.remember. - macOS, project repo on Azure DevOps.
Root cause
#127 deliberately keeps PROJECT_DIR = the worktree path while REMEMBER_DIR
now points into the main checkout. But the legacy-mode guard in
hooks.d/after_save/50-git-backup.sh still assumes they share a parent:
REPO_ROOT=$(dirname "$REMEMBER_DIR") # = main checkout
[ "$REPO_ROOT" = "$PROJECT_DIR" ] && exit 0 # PROJECT_DIR = worktree → guard passes
TOPLEVEL=$(git -C "$REPO_ROOT" rev-parse --show-toplevel ...)
[ "$TOPLEVEL" = "$REPO_ROOT" ] || exit 0 # main checkout IS a toplevel → passesBoth activation checks pass, so the hook proceeds as if .remember's parent
were a dedicated external backup repo:
- Deletes
<repo>/.remember/.gitignore(*) — logged as
removed per-slug .gitignore (legacy bootstrap artifact)— removing the
exact safety net that keeps.rememberuntracked in legacy mode. git add -- .remember/+ commitauto: .remember HH:MMin the project
repo, on the branch the main checkout is on (unrelated to the worktree
branch the session works on).git pushto the project's origin (the remote-URL state file
.git-backup-remoteand.last-git-backup-tsare also dropped into the
project root).
Observed impact
Six auto: .remember commits (hundreds of files, mostly empty
logs/autonomous/save-*.log) committed to and pushed onto an active feature
branch of our product repo while sessions ran in a sibling worktree. Required a
history rewrite + force-push to clean up.
Repro
- Legacy-mode project with
.remember/inside the repo; repo has a remote. git worktree add ../repo-wt some-branch, start a Claude Code session in
the worktree, let a save triggerafter_save.- Main checkout gets an
auto: .remember …commit pushed to origin;
.remember/.gitignoreis gone.
Suggested fix
In 50-git-backup.sh, treat "REPO_ROOT is the main checkout of PROJECT_DIR"
as legacy mode too — e.g. resolve PROJECT_DIR's main checkout with the same
--git-common-dir logic lib-memory-dir.sh uses (or compare
git -C "$PROJECT_DIR" rev-parse --path-format=absolute --git-common-dir
against REPO_ROOT's) and exit 0 on match. External mode should only activate
when .remember's parent is a repo dedicated to memory backup, never the
project repo itself.
Activity
fix: sanitize git env before the #138 guard; scope the #125 claim hon…
fix: never git-backup into the project's own repository (#138)
release: 0.8.5 — bump the manifest so marketplace installs actually u…
fix: sanitize git env before the #138 guard; scope the #125 claim hon…
release: 0.8.5 — manifest bump, worktree backup safety, fork-storm ga…
fdaviddpt commentedon Jul 25, 2026
Fixed in v0.8.5.
Your suggested direction was right, with one widening: instead of resolving PROJECT_DIR's main checkout and comparing, the hook now compares git common dirs on both sides. Every worktree of a repo shares one common dir, so the plain, worktree and sibling-worktree layouts collapse into a single invariant — external mode activates only when
.remember's parent is a repo genuinely dedicated to memory backup.Review afterwards caught a second defect worth flagging here, since it was in the same blast radius: the new guard ran before
unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE(that unset lived inside the worker subshell). A leakedGIT_DIRoverridesgit -C, which would have collapsed both sides of the comparison onto the same value and silently disabled every backup, legitimate external ones included. Sanitization now runs before the guards, with a regression test.Three regression tests cover the reported scenario (legacy memory + worktree session → project repo untouched,
.gitignoreintact), a sibling-worktree variant, and non-regression for real external backups.Sorry about the history rewrite — that's a bad way to find out, and the trace you wrote made it a 20-minute fix instead of a hunt.
— Max
fix: keep resolve-paths loud by default, soft-fail only for the hooks
fix: 7 more Windows glob/pattern-match sites, same class as #487 (#517)…
Fix #1134: git-backup #138 guard fails closed when PROJECT_DIR is gon…