diff --git a/hindsight-integrations/claude-code/scripts/lib/bank.py b/hindsight-integrations/claude-code/scripts/lib/bank.py index ba0bd43b3..91e7b4841 100644 --- a/hindsight-integrations/claude-code/scripts/lib/bank.py +++ b/hindsight-integrations/claude-code/scripts/lib/bank.py @@ -95,9 +95,9 @@ def derive_bank_id(hook_input: dict, config: dict) -> str: # case-sensitive compare silently misses the map and falls through # to the default bank. normcase is a no-op on POSIX, preserving # case-sensitive matching there. - normalized_cwd = os.path.normcase(os.path.normpath(cwd)) + normalized_cwd = os.path.normcase(os.path.realpath(cwd)) for dir_path, bank_id in dir_map.items(): - if os.path.normcase(os.path.normpath(dir_path)) == normalized_cwd: + if os.path.normcase(os.path.realpath(dir_path)) == normalized_cwd: return f"{prefix}-{bank_id}" if prefix else bank_id if not config.get("dynamicBankId", False): diff --git a/hindsight-integrations/claude-code/tests/test_bank.py b/hindsight-integrations/claude-code/tests/test_bank.py index 45dbb512a..4c2b167c7 100644 --- a/hindsight-integrations/claude-code/tests/test_bank.py +++ b/hindsight-integrations/claude-code/tests/test_bank.py @@ -296,3 +296,14 @@ def test_different_banks_each_set_once(self, state_dir): ensure_bank_mission(client, "bank-x", cfg) ensure_bank_mission(client, "bank-y", cfg) assert client.set_bank_mission.call_count == 2 + + @pytest.mark.skipif(not hasattr(__import__("os"), "symlink"), reason="symlinks not supported") + def test_directorybankmap_matches_symlinked_cwd(self, tmp_path): + import os + real = os.path.realpath(tmp_path / "proj") + os.makedirs(real) + link = str(tmp_path / "proj-link") + os.symlink(real, link) + cfg = _cfg(directoryBankMap={real: "myproj"}, bankId="fallback") + assert derive_bank_id({"cwd": real, "session_id": "s"}, cfg) == "myproj" + assert derive_bank_id({"cwd": link, "session_id": "s"}, cfg) == "myproj"