Sessions should stay keyed to their launch directory — EnterWorktree relocates session history, making renamed/resumed sessions unfindable

Status Open
Reported on v2.1.259
Maintainer reply None cached
Activity 0 comments · opened Sep 3, 2026

Summary

Session history is bucketed by the CLI's current cwd, not the directory a session was actually launched from. Anything that changes the session's cwd mid-session — most concretely the EnterWorktree tool — silently moves later transcript files into a different project bucket (~/.claude/projects/<slugified-new-cwd>/). The session becomes invisible from --resume//resume run in the directory the user actually launched it from, with no indication anything moved.

This is the same root cause as #52113 ("Sessions are keyed by cwd, so worktrees fragment session history"), which was auto-closed as stale rather than resolved. Filing a fresh issue per that closing bot's own instructions, with a concrete repro and a proposed fix direction.

What happened

  1. Launched an interactive session from /path/to/repo (the main checkout).
  2. During the session, a skill (using-git-worktrees) invoked the native EnterWorktree tool with path: /path/to/repo/.worktrees/<branch>. cwd in the transcript switches to the worktree path from that point on.
  3. Renamed the session (-n/rename) once it was well underway.
  4. Exited Claude Code.
  5. Later, ran claude --resume from /path/to/repo (where the session was originally launched) to pick it back up. The renamed session did not appear in the picker at all.

Root cause, confirmed by inspecting ~/.claude/projects/ directly: the session's transcript files live under ~/.claude/projects/-path-to-repo--worktrees-<branch>/, a completely separate bucket from ~/.claude/projects/-path-to-repo/ where the session began and where the user was looking. Nothing in the CLI's resume picker, claude agents, or session-rename flow indicated the session had "moved."

Why this is worse than a cosmetic quirk

  • EnterWorktree is invoked by built-in/marketplace skills (e.g. using-git-worktrees) as an implementation detail — a user does not choose to "enter a worktree," an agent decides to on their behalf, often several turns into a task.
  • Once it fires, the session is effectively unresumable from the directory the user launched it from and remembers. The only way to find it again is to already know (or guess) the exact worktree path and either cd there or pass the session UUID directly to --resume.
  • Renaming a session (giving it a memorable custom title, specifically to find it again later) does nothing to help — the custom title is stored inside the new, hidden project bucket (~/.claude/projects/<new-bucket>/<session-id>/custom-title.json), so even a deliberately-named session is effectively lost.
  • This compounds with related open issues in this area, e.g. #86020 (EnterWorktree intermittently moves the working directory but not the session root) — the cwd/session-bucket relationship is evidently fragile in more than one direction.

Proposed fix

A session's launch directory should be its permanent identity for history/resume purposes, for the life of that session — independent of any cwd changes (via EnterWorktree, plain cd, or anything else) that happen afterward.

Concretely, something like:

  • Key session storage/listing by session ID (with the launch cwd recorded once, immutably, as metadata) rather than by whatever the live cwd happens to be when a transcript is written — matching the direction #52113 itself suggested ("session metadata could be keyed by session ID with cwd tracked as a mutable property").
  • Whatever directory a resumable session is filed under, --resume//resume run from the session's original launch directory should always find it, regardless of how many times cwd changed inside the session.

Happy to help validate a fix or provide the full transcript metadata (session IDs, timestamps) privately if that's useful for the team.

Environment

  • Claude Code 2.1.259, native install, Linux
  • Worktree entered via the superpowers:using-git-worktrees skill's native-tool path (EnterWorktree), not a manual cd

View original on GitHub ↗