Repository navigation
Conversation
…sessions in one project (#481) REMEMBER_BRANCH is process environment, inherited once at launch: every session of one $PROJECT_DIR shares the same value, and so does the git branch fallback it wraps. Several Claude Code sessions running at once in one project therefore write the same "| <branch>" identity slot into every entry, which is the exact failure the slot exists to prevent, reached through the branch that is supposed to be safe. Add REMEMBER_BRANCH_CMD, an executable invoked as `$REMEMBER_BRANCH_CMD "$SESSION_ID"` and checked after REMEMBER_BRANCH, before the git fallback. $SESSION_ID is already in scope at save time and differs per session, so a site can map it to a name of its own choosing. A non-zero exit or empty stdout falls through to the existing git/unknown chain rather than writing a broken slot. Co-Authored-By: Max <noreply>
…not configured" Self-review (oss:auditor) on 9be452e found the new fall-through path (a configured REMEMBER_BRANCH_CMD that exits non-zero or prints nothing) indistinguishable from REMEMBER_BRANCH_CMD never having been set at all -- no log line, stderr discarded. Every comparable fallback in this script logs on failure (torn now.md read, unreadable entry, unrecognised envelope); this one didn't. Restructure the BRANCH-resolution block so a configured-but-failing resolver logs a WARNING naming the command and the session before falling through to the git/unknown chain, while an unconfigured one stays silent as before. Also note in the README that the command is exec'd directly (no shell reparsing), so a Windows Git Bash user needs a forward-slash/PATH-resolvable path, not a native backslash one. Co-Authored-By: Max <noreply>
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.
Closes #481.
What
Adds
REMEMBER_BRANCH_CMD, an env var naming an executable invoked as$REMEMBER_BRANCH_CMD "$SESSION_ID", whose stdout resolves the| <branch>identity slot of each## HH:MM | <branch>memory-log header inscripts/save-session.sh. It is checked afterREMEMBER_BRANCHand before the existinggit branch --show-currentfallback; a non-zero exit or empty stdout falls through to that fallback (now with a WARNING logged naming the command and the session, see below).Why
REMEMBER_BRANCHis process environment, inherited once at launch, and the git-branch fallback it wraps resolves off$PROJECT_DIR-- both are therefore identical for every session of one project. With several Claude Code sessions running concurrently in one project (a real, previously-established case: #212, andpost-tool-hook.sh's own header), every entry collapses to the same identity slot, which is exactly the failureREMEMBER_BRANCHwas added to prevent, reached through the branch of the original fallback expression that was supposed to be safe (a real git repo, resolving successfully).$SESSION_IDis already computed earlier insave-session.shand differs per session, so it is the value handed to the new command.Self-review follow-up (second commit)
An
oss:auditorpass on the first commit found the new fall-through path completely silent: a configured-but-brokenREMEMBER_BRANCH_CMD(typo'd path, permission denied, a resolver that starts failing) was indistinguishable fromREMEMBER_BRANCH_CMDnever having been set, with stderr discarded and no log call -- inconsistent with three other fallback paths in this same file, which each log an ERROR/WARNING specifically so a fault doesn't silently read as the ordinary case. Below-bar item, tooling and platform notes, and the raw finding text are in the sections below.Tests
tests/test_save_session_branch_override.py-- rewritten, now 12 cases: the originalREMEMBER_BRANCHtruth table (env wins, git fallback,unknownfallback, empty-string-treated-as-unset, the:-operator guard) plus the newREMEMBER_BRANCH_CMDcases (env wins over the command, command wins over git, command receives$SESSION_IDas$1, non-zero exit falls through and logs, empty stdout falls through and logs, success does not log, unset leaves old behavior unchanged and logs nothing -- both a negative assertion and its positive control for each fall-through case).Red confirmed both times by reverting just
scripts/save-session.shviagit stashand re-running: 11 failed before the first commit's block existed, 2 failed before the second commit's logging existed (both fixed once the code landed).Full suite (
pytest) run twice, once per commit: 1923 passed / 43 skipped (566s), then 1924 passed / 43 skipped (483s) -- run becausescripts/save-session.shis referenced by roughly 50 other test files by grep count, not because anything narrower looked risky.Docs
README.md"Environment variables" table: newREMEMBER_BRANCH_CMDrow, including a note that the command is exec'd directly (no shell reparsing) so a Windows Git-Bash path needs to be forward-slash/PATH-resolvable, not a native backslash path -- added in response to the auditor's platform finding below.changelog.d/481.added.mdadded.Below-bar and reported-for-filing items
See the accompanying agent report's
adjacent/review.findingsfor the full text; anchors quoted here so both sides of the receipt exist in one place:REMEMBER_BRANCH_CMDthrough Git Bash was judged a design decision (conditional test vs. separate fixture file vs. docs-only) rather than something to decide solo mid-lane -- reported-for-filing, not fixed, and it is a real gap:pytestmark = pytest.mark.skipif(sys.platform == "win32", ...)covers the whole test module (pre-existing, unchanged by this PR) so none of the 12REMEMBER_BRANCH_CMDtests run on the Windows CI leg.