Repository navigation
feat(cli): note when a Claude Code session keeps searching without the graph - #2817
Merged
Merged
Conversation
…e graph The search hook gives each Grep, Glob or Bash search the matching graph symbols, but a session can keep searching text for questions the graph answers in one call (#509). Once a session has run three searches with no codebase-memory-mcp tool call, the next augmentation now adds one factual line saying so. The next note comes after six searches, then twelve, and any graph tool call resets the count. - State: a per-session counter in the process that runs hook requests (the daemon), keyed by the payload's session_id, in a bounded 64-slot table that evicts the least recently used session, behind a spin lock. Only searches that reach the graph lookup count. A search without an augmentation still counts, and the note waits for the next augmentation. - Reset: Claude's managed PostToolUse entry now matches "Read|mcp__.*codebase-memory-mcp__.*", covering plain and plugin server names. The previous Read-only entry, as installs up to v0.12 wrote it, is recognized as owned, so install replaces it in place and uninstall removes either. - Scope: Claude Code only. Codex sends the same event payload with a turn_id but has no reset hook, so its sessions are not tracked, and payloads without a session_id are not tracked either. - Cost: a graph tool call now runs one hook round-trip to the daemon for the reset, about 130 ms on a local build. Refs #509 Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
… tools
Smoke check 8d required Claude's PostToolUse matcher to be exactly Read. The
drift note widens it on purpose to Read|mcp__.*codebase-memory-mcp__.*, so a
graph tool call can reset the search count, and the macOS PR smoke failed on
it. 8d now requires exactly the new matcher, and besides a Search matcher it
also refuses a catch-all ("*" or empty) matcher, as its comment promised.
Checked against real installs: the previous binary's Read-only settings fail
8d, the new install passes, and the new install plus a catch-all PostToolUse
entry fails.
Refs #509
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
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.
Why
The search hook gives each Grep, Glob or Bash search the matching graph symbols, but a Claude Code session can keep searching text for questions the graph answers in one call (#509). A drift note that fires only when the drift is visible, after repeated searches with no graph call, is the counter variant chosen for this (a counter rather than a timer, as Serena moved to for the same problem).
What changes
[codebase-memory] This session has run N searches since its last codebase-memory-mcp tool call. Questions about callers, callees, call paths and definitions are one graph call each.The next note comes after six searches, then twelve. A search without an augmentation still counts, and the note waits for the next augmentation. The line carries no repository-derived value.session_id, in a bounded 64-slot table that evicts the least recently used session, behind a spin lock (theatomic_flagpattern frompipeline.c). Only searches that reach the graph lookup count. The combined text is built in a bounded stack buffer, so no allocation is added.PostToolUseentry now matchesRead|mcp__.*codebase-memory-mcp__.*, which covers the plain (mcp__codebase-memory-mcp__trace_path) and plugin (mcp__plugin_..._codebase-memory-mcp__...) tool names. A graph tool call resets the session. The previousRead-only entry, as installs up to v0.12 wrote it, is recognized as owned, so install replaces it in place and uninstall removes either.turn_idbut has no reset hook, so its sessions are not tracked, and payloads without asession_idare not tracked either.Proof on real output
Built binaries, isolated
HOME/cache/runtime, live daemon, each payload a separatehook-augmentprocess:["Read"]Read|mcp__.*codebase-memory-mcp__.*mcp__codebase-memory-mcp__trace_pathhook-augmentleft insettings.jsonTests
cli_hook_augment_drift_reminder_counts_searches. Covers the note at the 3rd, 6th and 12th search with an interleaved second session, reset by plain and plugin graph tool names, another server's tool not resetting, a search without an augmentation deferring the note, and Codex (turn_id) and session-less payloads untracked.cli_claude_post_hook_matcher_migrates_from_read. Covers install, the previousReadentry replaced by exactly one current entry, and uninstall of the previous entry.Read-only settings fail 8d, the new install passes, and a catch-all entry fails.scripts/smoke-local.sh, macOS arm64): 164 OK. The pypi and go package-wrapper steps of 13w fail on this machine ("archive must contain only the exact root files"); this diff does not touch packaging, and CI's macos-14 smoke passed 13w on feat(cli): give Copilot searches graph context through a PostToolUse hook #2801, so CI is the gate for that step.Read: the migration test and the six updated assertions fail.cli372 passed / 0 failed (1 Windows-only skip),agent_clients39 / 0,daemon_application87 / 0,daemon_bootstrap28 / 0.Refs #509