claude-code - ✅(Solved) Fix --resume shows no sessions when cwd is a bare repo root with worktrees [1 pull requests, 1 participants]

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…
GitHub stats
anthropics/claude-code#48110Fetched 2026-04-15 06:32:54
View on GitHub
Comments
0
Participants
1
Timeline
7
Reactions
0
Author
Participants
Timeline (top)
labeled ×4cross-referenced ×2referenced ×1

When running Claude Code from the root of a bare git repository that uses linked worktrees, claude --resume (interactive picker) shows "No conversations found to resume" — even though sessions exist and claude --resume <UUID> works fine.

Version: Claude Code 2.1.108, macOS (Darwin, arm64)

Root Cause

When multiple worktrees are detected, loadSameRepoMessageLogsProgressive discovers worktrees via git worktree list --porcelain, hashes each worktree path, then scans ~/.claude/projects/ for matching directories.

The bare repo root is not listed as a worktree by git:

$ git worktree list --porcelain
worktree ~/work/myrepo/.bare
bare

worktree ~/work/myrepo/develop
HEAD abc123
branch refs/heads/develop
...

Notice ~/work/myrepo/ (the actual cwd) is absent — only .bare appears.

Session creation uses getProjectDir(cwd) which hashes the cwd directly:

  • cwd ~/work/myrepo/ → project dir -work-myrepo

Session listing searches project dirs matching worktree paths:

  • .bare-work-myrepo--bare
  • develop/-work-myrepo-develop
  • featureA/-work-myrepo-featureA

The project dir -work-myrepo (where sessions are stored) doesn't match any worktree-derived path, so it is never searched. Sessions are created but invisible to --resume.

Fix Action

Fixed

PR fix notes

PR #48151: fix: include cwd project dir in multi-worktree session discovery

Description (problem / solution / changelog)

Summary

  • Fixes --resume showing no sessions when the cwd is a bare repo root with linked worktrees
  • Adds the cwd's own project directory to the multi-worktree scan set when it isn't already matched

Fixes #48110

Problem

In a bare-repo + worktree layout (git clone --bare with git worktree add), git worktree list --porcelain does not include the bare root as a worktree entry — only .bare and linked worktrees appear:

worktree /home/user/repo/.bare
bare

worktree /home/user/repo/develop
HEAD abc123
branch refs/heads/develop

Session creation uses getProjectDir(cwd) which hashes the cwd directly, so sessions for /home/user/repo are stored in ~/.claude/projects/-home-user-repo/.

Session listing (getSessionFilesForWorktrees) discovers worktrees via git worktree list, hashes each path, and scans ~/.claude/projects/ for matching directories. Since /home/user/repo is not in the worktree list, its project directory -home-user-repo is never matched — making all its sessions invisible to --resume.

Fix

After the worktree-matching loop in getSessionFilesForWorktrees, always include getProjectDir(getCwd()) in the scan set if it wasn't already matched:

const cwdProjectDir = getProjectDir(cwd);
const cwdDirName = isWindows
  ? basename(cwdProjectDir).toLowerCase()
  : basename(cwdProjectDir);

if (!matched.has(cwdDirName)) {
  matchedDirs.push({ projectDir: cwdProjectDir, wtPath: cwd });
}

This is safe because deduplicateBySessionId() already handles overlapping session IDs, and it's a no-op when the cwd is itself a worktree (already matched by the loop).

Reconstruction note

The attached file is a readable reconstruction of getSessionFilesForWorktrees (minified as HaK in the v2.1.108 bundle) with the fix applied. Since the product source is not in this repo, the file includes placeholder type declarations for the functions it calls. The actual change is the 6-line block marked // FIX.

Test plan

  • git clone --bare <url> .bare && echo "gitdir: .bare" > .git && git worktree add develop develop
  • Run claude from the bare root, send a message, exit
  • Run claude --resume — session should appear in the picker
  • Run claude --resume from a linked worktree — sessions from both the worktree and bare root should appear
  • Verify no regression for normal (non-bare) repos with and without worktrees

Changed files

  • src/services/session/getSessionFilesForWorktrees.ts (added, +146/-0)

Code Example

~/work/myrepo/           ← bare repo root (cwd when launching claude)
~/work/myrepo/.bare/     ← actual git database
~/work/myrepo/.git       ← file containing: gitdir: ~/work/myrepo/.bare
~/work/myrepo/develop/worktree (branch: develop)
~/work/myrepo/featureA/worktree (branch: feature/A)

---

$ git worktree list --porcelain
worktree ~/work/myrepo/.bare
bare

worktree ~/work/myrepo/develop
HEAD abc123
branch refs/heads/develop
...

---

# Set up a bare repo with worktrees
mkdir myrepo && cd myrepo
git clone --bare <repo-url> .bare
echo "gitdir: $(pwd)/.bare" > .git
git worktree add develop develop

# Start a session from the bare root
cd ~/work/myrepo
claude   # creates session in ~/.claude/projects/-work-myrepo/

# Try to resume
claude --resume   # → "No conversations found to resume"

# But direct resume by UUID works:
claude --resume <session-uuid>   # → works fine
RAW_BUFFERClick to expand / collapse

Description

When running Claude Code from the root of a bare git repository that uses linked worktrees, claude --resume (interactive picker) shows "No conversations found to resume" — even though sessions exist and claude --resume <UUID> works fine.

Version: Claude Code 2.1.108, macOS (Darwin, arm64)

Setup

A bare repo with linked worktrees using the common "bare + worktree" pattern:

~/work/myrepo/           ← bare repo root (cwd when launching claude)
~/work/myrepo/.bare/     ← actual git database
~/work/myrepo/.git       ← file containing: gitdir: ~/work/myrepo/.bare
~/work/myrepo/develop/   ← worktree (branch: develop)
~/work/myrepo/featureA/  ← worktree (branch: feature/A)

Root cause

When multiple worktrees are detected, loadSameRepoMessageLogsProgressive discovers worktrees via git worktree list --porcelain, hashes each worktree path, then scans ~/.claude/projects/ for matching directories.

The bare repo root is not listed as a worktree by git:

$ git worktree list --porcelain
worktree ~/work/myrepo/.bare
bare

worktree ~/work/myrepo/develop
HEAD abc123
branch refs/heads/develop
...

Notice ~/work/myrepo/ (the actual cwd) is absent — only .bare appears.

Session creation uses getProjectDir(cwd) which hashes the cwd directly:

  • cwd ~/work/myrepo/ → project dir -work-myrepo

Session listing searches project dirs matching worktree paths:

  • .bare-work-myrepo--bare
  • develop/-work-myrepo-develop
  • featureA/-work-myrepo-featureA

The project dir -work-myrepo (where sessions are stored) doesn't match any worktree-derived path, so it is never searched. Sessions are created but invisible to --resume.

Reproduction

# Set up a bare repo with worktrees
mkdir myrepo && cd myrepo
git clone --bare <repo-url> .bare
echo "gitdir: $(pwd)/.bare" > .git
git worktree add develop develop

# Start a session from the bare root
cd ~/work/myrepo
claude   # creates session in ~/.claude/projects/-work-myrepo/

# Try to resume
claude --resume   # → "No conversations found to resume"

# But direct resume by UUID works:
claude --resume <session-uuid>   # → works fine

Expected behavior

claude --resume should list sessions for the current working directory regardless of whether the cwd appears in git worktree list output.

Suggested fix

In the multi-worktree branch of loadSameRepoMessageLogsProgressive, always include getProjectDir(getOriginalCwd()) in the set of directories to scan, even if it doesn't match any discovered worktree path. This ensures the cwd's own sessions are always visible.

extent analysis

TL;DR

Modify the loadSameRepoMessageLogsProgressive function to include the project directory of the current working directory in the set of directories to scan for sessions.

Guidance

  • Identify the loadSameRepoMessageLogsProgressive function and locate the section where it discovers worktrees via git worktree list --porcelain.
  • Modify the function to always include getProjectDir(getOriginalCwd()) in the set of directories to scan, regardless of whether the cwd appears in the git worktree list output.
  • Verify that the modified function correctly lists sessions for the current working directory by running claude --resume after making the change.
  • Test the fix by creating a new session from the bare root and attempting to resume it using claude --resume.

Example

# Modified loadSameRepoMessageLogsProgressive function
function loadSameRepoMessageLogsProgressive() {
  # ...
  local worktreeDirs=($(git worktree list --porcelain | awk '{print $2}'))
  local cwdProjectDir=$(getProjectDir $(getOriginalCwd()))
  worktreeDirs+=($cwdProjectDir)
  # ...
}

Notes

The suggested fix assumes that the getProjectDir and getOriginalCwd functions are correctly implemented and return the expected values. Additionally, this fix may need to be adapted to fit the specific implementation details of the loadSameRepoMessageLogsProgressive function.

Recommendation

Apply the suggested workaround by modifying the loadSameRepoMessageLogsProgressive function to include the project directory of the current working directory in the set of directories to scan. This should ensure that sessions created from the bare root are visible when running claude --resume.

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…

FAQ

Expected behavior

claude --resume should list sessions for the current working directory regardless of whether the cwd appears in git worktree list output.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING