[FEATURE] Open code history based on that sessions CWD (worktree edge case)
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
Chat history fails to load after a mid-session cwd change (e.g. via EnterWorktree)
What happens: I start a chat in a VSCode workspace, and partway through, a tool call changes that session's working directory to a different path (in my case, a git worktree directory nested inside the same repo, entered via the built-in EnterWorktree tool). The session still shows up in the history list, but opening it does not load its messages — the transcript content fails to load.
Under the hood, the transcript for that session is stored in a project folder keyed by the new cwd (~/.claude/projects/<encoded-new-cwd-path>/<session-id>.jsonl) rather than the original workspace path. I'm guessing the history list is showing an entry for the session (maybe from an index file), but whatever loads the actual messages when you select it is still looking under the original workspace's project folder and finding nothing there.
Repro:
- Open a workspace at path A.
- Start a new chat.
- Trigger a tool call that changes the session's cwd to a subdirectory path B (e.g. entering a git worktree).
- Keep chatting for a while.
- Close Claude Code, reopen it, and select that same chat from the history list.
- Its history does not load.
Expected: Selecting the chat from the history list should load its full transcript, regardless of any cwd change that happened during the session.
Workaround: Open path B itself as its own window, or run claude --resume <session-id> from inside it.
Proposed Solution
Proposed solution: Keep a session's transcript and history-list entry anchored to the workspace/cwd it was opened in, not wherever its cwd happens to be at any given moment. Concretely: write the .jsonl transcript to the project folder for the session's original cwd for its whole lifetime, even after a tool call (like EnterWorktree) changes the live working directory. If there's a reason transcripts need to be split per-cwd, then the history-list loader should at least follow that same redirect — look up transcripts by session ID across any cwd the session touched, not just the workspace's own project folder — so a listed session never resolves to an empty/failed load.
Alternative Solutions
_No response_
Priority
High - Significant impact on productivity
Feature Category
Interactive mode (TUI)
Use Case Example
_No response_
Additional Context
_No response_