claude-code - 💡(How to fix) Fix [BUG] claude --resume picker pulls in sessions from sibling projects whose encoded folder name shares the cwd's prefix

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Error Messages/Logs

(none — no error is produced; the picker just lists the wrong sessions)

Root Cause

The picker's "worktrees of this project" enumeration appears to do startsWith(encodedCwd) over ~/.claude/projects/*, which legitimately matches -home-me-work-foo--claude-worktrees-<branch> but also wrongly matches -home-me-work-foobar because the latter just continues the name.

Fix Action

Fix / Workaround

Workaround: resume by explicit session UUID instead of using the picker — claude --resume <uuid>, picking the UUID from ~/.claude/projects/<encoded-cwd>/.

Code Example

/home/me/work/foo
/home/me/work/foobar

---

~/.claude/projects/-home-me-work-foo
~/.claude/projects/-home-me-work-foobar

---

(none — no error is produced; the picker just lists the wrong sessions)

---

mkdir -p ~/work/foo ~/work/foobar
   cd ~/work/foo && git init && echo x > a && git add a && git commit -m init
   cd ~/work/foobar && git init && echo x > a && git add a && git commit -m init

---

cd ~/work/foo    && claude "say OK"
   cd ~/work/foobar && claude "say OK"

---

cd ~/work/foo && claude --worktree some-branch
   # type one message, then exit

---

cd ~/work/foo && claude --resume
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

When claude --resume is invoked from a project directory that has worktree-style sibling folders under ~/.claude/projects/ (e.g. <encoded-cwd>--claude-worktrees-<branch>), the picker also pulls in sessions from unrelated projects whose encoded folder name happens to start with the same prefix as the current cwd. This makes the picker show conversations that belong to a different project entirely.

Concretely, given two sibling directories where one name is a string-prefix of the other:

/home/me/work/foo
/home/me/work/foobar

Their encoded forms are:

~/.claude/projects/-home-me-work-foo
~/.claude/projects/-home-me-work-foobar

The picker's "worktrees of this project" enumeration appears to do startsWith(encodedCwd) over ~/.claude/projects/*, which legitimately matches -home-me-work-foo--claude-worktrees-<branch> but also wrongly matches -home-me-work-foobar because the latter just continues the name.

The session .jsonl files on disk are correctly tagged — their cwd fields point to the right project — so the only thing wrong is which folders the picker decides count as "this project + its worktrees."

What Should Happen?

claude --resume from /home/me/work/foo should only list sessions whose cwd is /home/me/work/foo or a real worktree of it (i.e. project folders matching <encodedCwd>--claude-worktrees-… or equal to <encodedCwd>). Sessions from /home/me/work/foobar should not appear.

A safe rule: after stripping the encodedCwd prefix from a candidate folder name, the remainder must be either empty (exact match) or start with the explicit worktree separator --claude-worktrees-. A bare character continuation should not qualify.

Error Messages/Logs

(none — no error is produced; the picker just lists the wrong sessions)

Steps to Reproduce

  1. Create two sibling directories where one name is a strict prefix of the other:
    mkdir -p ~/work/foo ~/work/foobar
    cd ~/work/foo && git init && echo x > a && git add a && git commit -m init
    cd ~/work/foobar && git init && echo x > a && git add a && git commit -m init
  2. Open a Claude Code session in each, exchange one message, exit:
    cd ~/work/foo    && claude "say OK"
    cd ~/work/foobar && claude "say OK"
  3. Make foo have at least one Claude Code worktree, so the picker enters its "all worktrees" view:
    cd ~/work/foo && claude --worktree some-branch
    # type one message, then exit
  4. From foo, open the resume picker:
    cd ~/work/foo && claude --resume
  5. Observe: the picker footer shows Ctrl+W show all worktrees and the listed sessions include entries from ~/work/foobar (different branches, different content), not just foo and its real worktrees.

A minimal repro with foo + foobar and no worktrees on foo does not leak — the bug only manifests once the picker enters worktree-aware mode.

Claude Model

Not sure / Multiple models

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.1.145 (Claude Code)

Platform

Anthropic API

Operating System

Other Linux

Terminal/Shell

WSL (Windows Subsystem for Linux)

Additional Information

Workaround: resume by explicit session UUID instead of using the picker — claude --resume <uuid>, picking the UUID from ~/.claude/projects/<encoded-cwd>/.

On-disk evidence is fine: the session .jsonl files inside each project folder correctly carry their own cwd. The bug is purely in the picker's folder enumeration; no data has to move to fix it.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING