Skip to content

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

Merged
nicoloboschi merged 2 commits into
vectorize-io:mainfrom
365diascollaboration-prog:fix/claude-code-directorybankmap-symlink
Jun 23, 2026
Merged

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

Conversation

@365diascollaboration-prog

Copy link
Copy Markdown
Contributor

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

@nicoloboschi nicoloboschi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed and verified locally.

Correct, minimal fix for #2312. realpath resolves symlinks before normalizing on both sides of the comparison, so a mapped directory and any symlink to it canonicalize to the same string. normcase is preserved for Windows drive-letter folding, and realpath is cross-platform.

Verified:

  • New test_directorybankmap_matches_symlinked_cwd is a genuine regression test — fails (routes to fallback) on the old normpath code, passes with realpath.
  • Full suite green locally: 40 passed.
  • No JS counterpart in this integration (pure-Python), so no parity gap.

Nit (non-blocking): the inline import os / __import__("os") in the test is a touch unidiomatic vs. a module-level import, but it works and keeps the diff focused.

@nicoloboschi
nicoloboschi merged commit 0672fba into vectorize-io:main Jun 23, 2026
81 checks passed
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