From afa07f9c7f557582bb78eb7f72c0633bd604800f Mon Sep 17 00:00:00 2001 From: Bruno Guidolim Date: Thu, 9 Jul 2026 18:53:33 +0200 Subject: [PATCH] Fall back to launch dir when resolving project root outside git - git rev-parse failure in non-git folders no longer aborts the hook - Falls back to CLAUDE_PROJECT_DIR, then $PWD, so memories index correctly - Git-repo resolution (toplevel anchor) is unchanged --- hooks/sync-memories.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hooks/sync-memories.sh b/hooks/sync-memories.sh index 0cc1c85..91b1167 100755 --- a/hooks/sync-memories.sh +++ b/hooks/sync-memories.sh @@ -8,7 +8,12 @@ set -uo pipefail # Consume stdin (hook passes JSON context) cat >/dev/null 2>&1 || true -project_root=$(git rev-parse --show-toplevel 2>/dev/null) || exit 0 +# Resolve the project root. Prefer the git repo toplevel — it's the stable +# anchor so launching from any subdirectory of a repo maps to the same library. +# In a non-git folder git exits non-zero (empty output); fall back to where +# Claude was launched (CLAUDE_PROJECT_DIR, else $PWD). +project_root=$(git rev-parse --show-toplevel 2>/dev/null) +[ -n "$project_root" ] || project_root="${CLAUDE_PROJECT_DIR:-$PWD}" MEMORIES_DIR="$project_root/.claude/memories" TIMESTAMP_FILE="$project_root/.claude/.memories-last-indexed"