Skip to content

fix(claude-code): use realpath for directoryBankMap symlink resolution#2324

Open
365diascollaboration-prog wants to merge 2 commits into
vectorize-io:mainfrom
365diascollaboration-prog:fix/claude-code-directorybankmap-symlink
Open

fix(claude-code): use realpath for directoryBankMap symlink resolution#2324
365diascollaboration-prog wants to merge 2 commits into
vectorize-io:mainfrom
365diascollaboration-prog:fix/claude-code-directorybankmap-symlink

Conversation

@365diascollaboration-prog

Copy link
Copy Markdown

Problem

directoryBankMap entries are matched against the session cwd using os.path.normpath, which does not resolve symlinks. When the cwd is a symlink to a mapped directory (or when the map key itself is a symlink), the comparison silently fails and memory is routed to the wrong bank with no error.

Reported in #2312.

Fix

Replace os.path.normpath with os.path.realpath on both sides of the comparison in derive_bank_id(). realpath resolves symlinks before normalizing, so a directory and any symlink pointing to it produce the same canonical path string.

# Before
normalized_cwd = os.path.normcase(os.path.normpath(cwd))
if os.path.normcase(os.path.normpath(dir_path)) == normalized_cwd:

# After
normalized_cwd = os.path.normcase(os.path.realpath(cwd))
if os.path.normcase(os.path.realpath(dir_path)) == normalized_cwd:

os.path.realpath is available on all platforms (POSIX and Windows). normcase is preserved for Windows drive-letter case-folding.

Test

Added test_directorybankmap_matches_symlinked_cwd to TestDirectoryBankMap — creates a real directory and a symlink to it, verifies both paths resolve to the mapped bank. The test is skipped on platforms that don't support symlinks.

Affected scope

  • hindsight-integrations/claude-code/scripts/lib/bank.py — 2-line change
  • hindsight-integrations/claude-code/tests/test_bank.py — 1 new test

os.path.normpath does not resolve symlinks, so a cwd reached via a symlink
silently fails to match a directoryBankMap entry and falls through to the
fallback bank. Replace normpath with realpath on both sides of the comparison
so that a symlinked cwd correctly matches its canonical directory.

Fixes vectorize-io#2312
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.

1 participant