Skip to content

fix(projectTree): nest by real cwd path, not the opaque directory-name key - #265

Open
delexw wants to merge 1 commit into
mainfrom
fix-issue-259
Open

fix(projectTree): nest by real cwd path, not the opaque directory-name key#265
delexw wants to merge 1 commit into
mainfrom
fix-issue-259

Conversation

@delexw

@delexw delexw commented Aug 23, 2026

Copy link
Copy Markdown
Owner

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:

  • Session discovery/enumeration (Rust) was already safe — it only enumerates existing directories and never recomputes a directory name from a path for the active flow. Entry.cwd is parsed straight from the JSONL cwd field and is already the authoritative source used for project identity.
  • The one real gap was in the sidebar tree builder (shared/projectTree.ts). buildTree decided 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

buildTree now prefers the real cwd-derived path relationship (each ProjectNode already carries an origin, 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/backend and /home/user/backend-v2 are 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

  • Added regression tests in shared/projectTree.test.ts covering: 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.
  • Updated 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: clean
  • npx vitest run: 502/502 passed
  • cargo fmt --check, cargo clippy -- -D warnings, cargo test: clean, 687/687 passed (no Rust files changed)
  • Deep-read and updated specs/11-project-tree.md and specs/07-data-types.md to document the new real-path-first nesting rule

…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
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.

[Compat] Claude Code v2.1.234: CLAUDE_CODE_PROJECT_DIR_NAME lets hosts rename the per-project transcript directory

1 participant