[BUG] Session history doesn't surface worktree sessions started via EnterWorktree, despite activeWorktreeSession linking them to the parent project
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Environment
Claude Code: 2.1.220
VS Code: 1.130.0
OS: Linux 7.0.0-28-generic (Ubuntu 24.04), x86_64
Description
When a session uses EnterWorktree to switch into a git worktree, all subsequent transcript entries are logged under a project keyed by the worktree's path (e.g. ~/.claude/projects/-<repo-path>--claude-worktrees-<name>/), not the parent repo's project. That part is expected, since project storage is keyed by cwd.
However, ~/.claude.json records a pointer from the parent project back to that session:
"projects": {
"<repo-root>": {
"activeWorktreeSession": {
"sessionId": "f5497063-a590-4041-86e8-3a79a6d19c55",
"worktreePath": "<repo-root>/.claude/worktrees/<worktree-name>",
"worktreeName": "<worktree-name>",
"worktreeBranch": "worktree-<worktree-name>",
"originalBranch": "<feature-branch>",
"originalHeadCommit": "<sha>",
...
}
}
}
This shows the harness tracks the relationship between a worktree session and the repo it was launched from. But neither the CLI's --resume picker nor the VS Code extension's session-history panel uses this pointer — opening session history from the parent repo shows no trace of the worktree session, even though it's an active/relevant continuation of work started in that repo.
Steps to reproduce
Open a Claude Code session in a git repo.
Use EnterWorktree to switch into a worktree (e.g. for isolated feature work).
Continue working and end the session (e.g. after opening a PR).
Back in the original repo folder, open session history (VS Code extension panel, or claude --resume from the repo root).
Expected: The worktree session appears in the parent repo's history, or is at least surfaced as a related/child session (the activeWorktreeSession metadata makes this possible).
Actual: The worktree session is invisible from the parent repo. It's only visible if you separately open/cd into the worktree's own path.
Suggested fix
Have the session-history listing (both CLI and VS Code extension) also check projects[cwd].activeWorktreeSession and surface that session — ideally labeled as "worktree: <name>" — when browsing history for the parent repo.
Impact
Worktree sessions become effectively orphaned/hard-to-find from the user's normal working context. A session that opened a PR was invisible from history until it was located by hand via ~/.claude.json and ~/.claude/projects/.
What Should Happen?
Expected: The worktree session appears in the parent repo's history, or is at least surfaced as a related/child session (the activeWorktreeSession metadata makes this possible).
Error Messages/Logs
Steps to Reproduce
Open a Claude Code session in a git repo.
Use EnterWorktree to switch into a worktree (e.g. for isolated feature work).
Continue working and end the session (e.g. after opening a PR).
Back in the original repo folder, open session history (VS Code extension panel, or claude --resume from the repo root).
Claude Model
Not sure / Multiple models
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.220
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
VS Code integrated terminal
Additional Information
_No response_