Skip to content

Fix memories indexing in non-git projects and harden the sync hook#11

Merged
bguidolim merged 1 commit into
mainfrom
bruno/fix-memories-indexing-non-git
Jul 9, 2026
Merged

Fix memories indexing in non-git projects and harden the sync hook#11
bguidolim merged 1 commit into
mainfrom
bruno/fix-memories-indexing-non-git

Conversation

@bguidolim

@bguidolim bguidolim commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Why

Memories weren't indexed for anyone running Claude in a plain (non-git) folder: the sync hook resolved the project through git and bailed out immediately when there was no repo, so nothing was ever scraped and the search interface showed no libraries. Separately, a single failed index — or an externally cleared store — could permanently mark the project as "indexed" and leave the library stuck at zero.

Now the hook anchors to the git repo root when there is one — so launching from any subdirectory of a repo resolves to the same memories and library — and otherwise falls back to where Claude was launched, so non-git folders index correctly. Indexing is recorded only after content is verified present, and a missing library is re-added at session start, so failures and cleared stores recover instead of sticking.

Test plan

  • In a non-git folder containing .claude/memories/*.md with Ollama running, start a session → expect the library to appear in docs-mcp-server and the last-indexed marker to be written.
  • Edit a memory mid-session → expect a re-index on the next prompt; with nothing changed → expect no re-index.
  • Delete the docs-mcp-server store, then start a new session → expect the library re-added.

- Resolve the project root without requiring a git repo (git toplevel when present, else launch dir), so memories in a plain folder are indexed
- Mark indexed only on verified success and re-index when the library is missing, so a failed or cleared index no longer sticks at zero
- Add a session-scoped, best-effort diagnostic log (gitignored)
@bguidolim bguidolim force-pushed the bruno/fix-memories-indexing-non-git branch from 47bc21e to 7abfae7 Compare July 9, 2026 16:00
@bguidolim bguidolim requested a review from Copilot July 9, 2026 16:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the memories sync hook so .claude/memories/*.md are indexed into docs-mcp-server even when running in non-git directories, and makes indexing more resilient to partial failures or cleared stores.

Changes:

  • Resolve project_root without requiring a git repo, add per-session logging, and gate “indexed” state on verified document presence.
  • Add recovery behavior on SessionStart when the docs-mcp-server store is missing/empty.
  • Extend ignore rules to exclude the new indexing log, and add a repo .gitignore with common macOS ignores.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

File Description
techpack.yaml Ignores the new .claude/.memories-index.log file from version control via the pack’s gitignore component.
hooks/sync-memories.sh Reworks root resolution and indexing logic; adds logging and validates index success via document count.
.gitignore Adds macOS-specific ignore entries for this repository.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread hooks/sync-memories.sh
Comment on lines +19 to +23
project_root=$(git rev-parse --show-toplevel 2>/dev/null)
if [ -z "$project_root" ]; then
cwd=$(printf '%s' "$hook_input" | jq -r '.cwd // empty' 2>/dev/null)
project_root="${CLAUDE_PROJECT_DIR:-${cwd:-$PWD}}"
fi
Comment thread hooks/sync-memories.sh
Comment on lines +72 to +77
# --- Decide whether to (re)index ---
# The cheap local checks (timestamp vs. file mtimes) run every invocation. The
# store-existence probe spawns npx, so it runs only at SessionStart — enough to
# re-add a library whose store was cleared while its timestamp lingered, without
# paying npx on every prompt. Anything changed, or no timestamp yet, => index.
should_index=1
Comment thread hooks/sync-memories.sh
printf '%s %s\n' "$(date '+%Y-%m-%dT%H:%M:%S')" "$1" 2>/dev/null >>"$LOG_FILE" || true
}

repo_name=$(basename "$project_root")
Comment thread hooks/sync-memories.sh
}

repo_name=$(basename "$project_root")
memories_url="file://$MEMORIES_DIR"
@bguidolim bguidolim merged commit 330aa3a into main Jul 9, 2026
1 check passed
bguidolim added a commit that referenced this pull request Jul 9, 2026
… hook (#11)" (#12)

- Reverts hooks/sync-memories.sh and techpack.yaml from commit 330aa3a
- Keeps the .gitignore added in that PR
@bguidolim bguidolim deleted the bruno/fix-memories-indexing-non-git branch July 9, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants