claude-code - 💡(How to fix) Fix Session resume does not restore worktree: confusing state mismatch for users

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…

When a Claude Code session is started inside a git worktree (e.g. one created by an agent with isolation: \"worktree\"), suspending and resuming that session via claude resume does not restore the worktree context. The resumed session runs in whatever directory the shell is currently in, which may be a different branch or the main repo checkout entirely.

Error Message

Resuming a session should place the user in the same working directory and git state (branch, worktree path) that was active when the session was suspended, or at minimum warn the user that the filesystem context has changed.

  1. Record the working directory and branch at session start; on resume, warn if the current directory or branch differs

Root Cause

  • Users who rely on worktrees for isolation (e.g. parallel agent tasks, feature branches) have no guarantee that a resumed session is operating on the intended code
  • Claude may read or edit files on the wrong branch without either party realizing it
  • The system prompt message "This is a git worktree" remains accurate in wording but misleading in practice — it reflects the session-start context, not the current context
RAW_BUFFERClick to expand / collapse

Summary

When a Claude Code session is started inside a git worktree (e.g. one created by an agent with isolation: \"worktree\"), suspending and resuming that session via claude resume does not restore the worktree context. The resumed session runs in whatever directory the shell is currently in, which may be a different branch or the main repo checkout entirely.

Expected behavior

Resuming a session should place the user in the same working directory and git state (branch, worktree path) that was active when the session was suspended, or at minimum warn the user that the filesystem context has changed.

Actual behavior

The session conversation history is restored, but the working directory and branch are determined entirely by the shell environment at resume time. If the original worktree has been cleaned up (which happens automatically for agent-created worktrees), there is no indication that the filesystem context has changed. The user may believe they are operating on the same branch/worktree as before.

Why this matters

  • Users who rely on worktrees for isolation (e.g. parallel agent tasks, feature branches) have no guarantee that a resumed session is operating on the intended code
  • Claude may read or edit files on the wrong branch without either party realizing it
  • The system prompt message "This is a git worktree" remains accurate in wording but misleading in practice — it reflects the session-start context, not the current context

Suggested fix

One or more of:

  1. Record the working directory and branch at session start; on resume, warn if the current directory or branch differs
  2. For agent-created worktrees, persist the worktree (or a pointer to its branch) so it can be restored or recreated on resume
  3. Surface a clear warning at resume time when the git context has changed since the session was created

Environment

Reported by a user during an active Claude Code session on darwin (macOS).

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

Resuming a session should place the user in the same working directory and git state (branch, worktree path) that was active when the session was suspended, or at minimum warn the user that the filesystem context has changed.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Session resume does not restore worktree: confusing state mismatch for users