Skip to content

git-backup hook misfires after #127: worktree sessions commit & push .remember/ into the project repo #138

Closed

Description

@jaco2716

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

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 → passes

Both activation checks pass, so the hook proceeds as if .remember's parent
were a dedicated external backup repo:

  1. Deletes <repo>/.remember/.gitignore (*) — logged as
    removed per-slug .gitignore (legacy bootstrap artifact) — removing the
    exact safety net that keeps .remember untracked in legacy mode.
  2. git add -- .remember/ + commit auto: .remember HH:MM in the project
    repo
    , on the branch the main checkout is on (unrelated to the worktree
    branch the session works on).
  3. git push to the project's origin (the remote-URL state file
    .git-backup-remote and .last-git-backup-ts are 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

  1. Legacy-mode project with .remember/ inside the repo; repo has a remote.
  2. git worktree add ../repo-wt some-branch, start a Claude Code session in
    the worktree, let a save trigger after_save.
  3. Main checkout gets an auto: .remember … commit pushed to origin;
    .remember/.gitignore is 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.

Related: #56, #127, #133.

Activity

  1. added
    bug
    on Jul 24, 2026
  2. fdaviddpt commented on Jul 25, 2026

    @fdaviddpt
    Contributor

    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 leaked GIT_DIR overrides git -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, .gitignore intact), 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

  3. added a commit that references this issue on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions