session history orphaned when session ends inside EnterWorktree worktree

Status Open
Reported on v2.1.220
Maintainer reply None cached
Activity 0 comments · opened Aug 5, 2026

Bug

A session started in the main repo checkout that uses the EnterWorktree tool gets its history jsonl re-keyed to a project directory derived from the worktree path. If ExitWorktree is never called, the file stays there permanently. The session remains visible in the extension's conversation list only while the window is open (held in memory) — after a window reload the list is rebuilt from the workspace's project dir on disk, and the session silently disappears from both the VSCode extension list and the --resume picker.

Repro

  1. Start a session in /path/to/repo (VSCode extension or CLI)
  2. Ask for work in a separate worktree — agent calls EnterWorktree, cwd switches to <repo>/.claude/worktrees/<branch>
  3. Session jsonl moves from ~/.claude/projects/-path-to-repo/ to ~/.claude/projects/-path-to-repo--claude-worktrees-<branch>/
  4. Session ends without ExitWorktree
  5. Reload VSCode window → session gone from conversation list. No workspace maps to the worktree-slug dir, so it's unreachable from any list

Expected

Session started in the main checkout should remain resumable from there — either keep history keyed to the origin cwd, or re-key back on session end when ExitWorktree wasn't called.

Workaround

Copy the jsonl back into the origin project dir, or claude --resume <session-id>.

Version: 2.1.220, Linux
Related: #15776 (same class of problem for manually-created worktrees).

View original on GitHub ↗