Claude Code Session History Lost After Deleting a Git Worktree
Deleted a git worktree and lost your Claude Code conversation? Why it happens, how to resume by session id, and what to save before you clean up.
GuideUpdated 6 min read
On this page
You merged the branch, removed the worktree, and now the conversation is gone. Or /resume shows a long list of sessions from other folders and not the one you want.
We know of no official fix or setting for this. The steps below are workarounds, not a documented feature. Users report this behavior on Claude Code's issue tracker, but we have not confirmed the storage location ourselves, so check Anthropic's current documentation for anything newer.
Why the history disappears with the worktree
According to those reports, Claude Code stores session state under the worktree folder. Delete the folder after merging and the conversation goes with it. Merging the branch does not delete anything; removing the folder does.
Two related symptoms are reported:
/resumeshows a global history instead of filtering by directory.- History seems to vanish after you
cdsomewhere else.
Together these suggest the history is tied to the folder where the session started. Treat that as the likely cause, not a certainty.
| Symptom | Likely cause | What to do |
|---|---|---|
| Conversation gone after removing the worktree | Session state lived under that folder | Keep the worktree, or save a summary first |
/resume lists other folders' sessions | Reported global listing | Resume by session id |
History missing after cd | History tied to the starting folder | Run Claude Code from the original worktree |
Fix 1: keep the worktree until you are done
This is the only method that does not depend on resume behavior.
Merge the branch, but leave the worktree folder in place.
List your worktrees from any folder in the repo. This only lists and changes nothing:
bash git worktree listIf you might have a follow-up ("why did you change that file?"), start Claude Code from inside the same worktree and ask it there.
Remove the worktree only when you no longer need the conversation.
The cost is disk space for a few extra checkouts. If you want a worktree to survive a tidy-up, git can lock it. A locked worktree is not removed by git worktree prune and needs --force twice to remove:
git worktree lock --reason "keep Claude session" ../my-worktreeUndo it with git worktree unlock ../my-worktree. Replace the path with your worktree's path.
Fix 2: resume by session id before you clean up
If you need the space now, capture what you need first.
Open a terminal in the worktree.
If you have the session id, run:
bash claude --resume <id>Without an id,
claude --resumeopens a picker, andclaude --continuecontinues the most recent conversation in the current folder.Check that the earlier history appears. If it does not, stop here and do not remove anything yet.
Ask the agent for a short handoff summary: what it changed, why, what it tried and dropped, and what is left.
Paste the summary into the PR description or a notes file outside the worktree, for example in your home folder or the repo's docs.
Only then remove the worktree.
Check git state before you remove anything
Conversation history is one loss; uncommitted work is another. Merged commits are safe in your repo, but files that were never committed vanish with the folder.
Check the worktree for changes (replace the path with yours):
bash git -C ../my-worktree status --shortNo output means nothing is uncommitted.
Commit what you want to keep, or stash it with
git stashfrom inside the worktree. Stashes live in the shared repo, so they survive removal.Confirm the branch is merged or pushed.
Remove the worktree with git rather than by hand, so git's records stay clean:
bash git worktree remove ../my-worktreeBy default git refuses if there are uncommitted changes. That refusal is a useful safety net, so do not add
--forcecasually.
What Sledbot covers, and what it doesn't
Sledbot covers part of this and does not fix the underlying problem. It does not move or copy Claude Code's session store, so deleting a worktree can still cost you the conversation.
What it does:
- Stopped agents can be restarted. A stopped agent keeps its terminal so you can read it, and Restart brings it back with its conversation where possible. That depends on Claude Code still having the session, so don't count on it once the folder is gone.
- Resume uses Claude Code's own command. After a crash or reboot, Sled Core runs the agent's resume command (
claude --resume <id>for Claude Code) in the original folder. If resuming fails, it opens a shell. - Closing an agent keeps its worktree. Closing a running agent asks "Stop
<name>?" and says the worktree and files stay. - Cleanup is your call. Clean up worktrees… on a space and the Cleanup tab in Insights are user-initiated. Local items go to the Trash unless you choose Delete permanently….
- Automatic cleanup can remove merged worktrees. It is off by default, apart from purging
~/.sled-trashafter 7 days. If you enable the merged-worktrees rule (7 days by default), keep in mind it will delete worktrees whose conversations you may still want. - Archive instead of delete.
sled thread archivestops the agent and keeps its worktree plus a checkpoint ref.sled thread restorebrings the thread back. We can't confirm that restoring reopens the Claude conversation.
Agents started from New task get a worktree at <repo>/.sledbot/worktrees/<branch with / replaced by ->. See Start an agent on a task and Insights, Resources and Cleanup.
Checklist before you remove a worktree
- The branch is merged or pushed.
git status --shortin the worktree prints nothing.- You have the session id, or you ran
claude --continuefrom the worktree. - A handoff summary is saved outside the worktree.
- You no longer need to ask follow-up questions.
If it already got deleted
- Removed from the command line. Assume the folder is gone for good. Rebuild context from the merged commits and the PR description.
- Deleted through Finder or a Sledbot local cleanup. The folder may be in the Trash. You can copy it out, but whether Claude Code then finds the old history is unverified, so treat any recovery as a bonus.
- You don't know the session id. We have no verified place to look it up. Run
claude --resumeorclaude --continuefrom the worktree if it still exists. - Sledbot's Restart opens a shell or says "Can't restart
<name>with its conversation". The resume failed or the folder is gone. Start a new task in a folder that exists and paste in your summary.
If nothing works
Contact Anthropic through Claude Code's official support channels. Include your Claude Code version, macOS version, how you removed the worktree, and what /resume shows.
Claude Code lost its conversation after I removed a git worktree.
Claude Code version: (output of claude --version)
macOS version: (your version)
How the worktree was removed: (git worktree remove / Finder / other)
What I tried: claude --resume <id>, claude --continue
Result: (history empty / session not found)
Is there a supported way to keep or recover session history after a worktree is deleted?Common questions
Does merging the branch delete the history?
According to the reports, no. Removing the worktree folder is what loses it.
Is there a setting to keep history somewhere permanent?
We found none. Until one exists, the handoff summary is the durable record.
Why does /resume show sessions from other folders?
That matches the reported behavior. Resume by session id instead of picking from the list.