fix(projectTree): nest by real cwd path, not the opaque directory-name key - #265
Open
delexw wants to merge 1 commit into
Open
fix(projectTree): nest by real cwd path, not the opaque directory-name key#265delexw wants to merge 1 commit into
delexw wants to merge 1 commit into
Conversation
…e key Claude Code v2.1.234 added CLAUDE_CODE_PROJECT_DIR_NAME, letting a host assign an arbitrary short name to a project's ~/.claude/projects/<dir> transcript folder instead of the usual path-derived name. Session discovery/grouping (Rust) was already safe: it only enumerates existing directories and always resolves project identity from cwd in the JSONL content. The sidebar tree builder, however, decided worktree nesting purely by string-prefix-matching the directory-name key, which assumes the key encodes the real path. Under an arbitrary host-assigned name that assumption breaks: unrelated projects with coincidentally similar names could get nested together, or related projects with unrelated names would fail to nest at all. buildTree now prefers the real cwd-derived path relationship (already tracked per session) over the key when both are known, falling back to the key heuristic only when real path data is unavailable. This also fixes the same latent bug for ordinary paths (e.g. /home/user/backend vs /home/user/backend-v2, which are siblings, not nested). Fixes #259
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.
Fixes #259
Problem
Claude Code v2.1.234 added
CLAUDE_CODE_PROJECT_DIR_NAME, letting a host assign an arbitrary short name to a project's~/.claude/projects/<dir>transcript folder instead of the usual path-derived (sanitized-path) name.I audited the whole path from directory discovery through to the UI:
Entry.cwdis parsed straight from the JSONLcwdfield and is already the authoritative source used for project identity.shared/projectTree.ts).buildTreedecided worktree/parent-child nesting purely by string-prefix-matching the opaque~/.claude/projects/<dir>name, which silently assumes that name encodes the real path. Under an arbitrary host-assigned name that assumption breaks: two unrelated projects with a coincidentally similar name could get nested together in the sidebar, or two genuinely related projects (a repo and its real worktree) with unrelated names would fail to nest at all.Fix
buildTreenow prefers the real cwd-derived path relationship (eachProjectNodealready carries anorigin, the real filesystem path it's anchored at) over the directory-name key when both are known, falling back to the existing key-prefix heuristic only when real path data is unavailable (e.g. synthesized orphan-worktree nodes that have no session of their own).This also fixes the same latent bug for ordinary filesystem paths —
/home/user/backendand/home/user/backend-v2are sibling directories, not nested, but the old key-prefix check nested them anyway. Updated the one existing test that had encoded that incorrect expectation.Testing
shared/projectTree.test.tscovering: nesting via real cwd when keys share no prefix (arbitrary host-assigned names), NOT nesting when keys coincidentally share a prefix but real paths are unrelated, and falling back to key-prefix matching when origin is unknown.src/components/ProjectTree.test.tsx's sibling-directory test to assert the corrected (no false nesting) behavior.npx oxfmt --check,npx oxlint,npx tsc --noEmit: cleannpx vitest run: 502/502 passedcargo fmt --check,cargo clippy -- -D warnings,cargo test: clean, 687/687 passed (no Rust files changed)specs/11-project-tree.mdandspecs/07-data-types.mdto document the new real-path-first nesting rule