claude-code - 💡(How to fix) Fix [BUG] Worktree-session feature doesn't carry project-scoped MCP config/auth from originalCwd to worktreePath

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…

Root Cause

User-global remote MCP servers (claude.ai family — Gmail, Calendar, Drive) work correctly across worktree transitions because they're not project-scoped. Only project-scoped servers exhibit this.

Code Example

{
     "type": "worktree-state",
     "worktreeSession": {
       "originalCwd": "/home/user/projects/my-repo",
       "worktreePath": "/home/user/projects/my-repo/.claude/worktrees/<name>",
       "originalBranch": "<parent-branch>",
       "sessionId": "<parent-session-uuid>"
     },
     "sessionId": "<child-session-uuid>"
   }
RAW_BUFFERClick to expand / collapse

Preflight

  • Searched existing issues; distinct from #58226 (.mcp.json discovery) and #32220 (EnterWorktree reinit). Both closed without addressing parent-session MCP/auth inheritance.
  • Single bug.
  • Latest version.

What's Wrong

When Claude Code's worktree-session feature spawns a child session (the one with the worktree-state jsonl record), the child is filed under ~/.claude/projects/<sanitized-worktreePath>/ and looks up MCP config via ~/.claude.json.projects[<worktreePath>]. The parent session's MCP config (under .projects[<originalCwd>]) doesn't propagate, and any project-scoped OAuth credentials granted under the originalCwd identity aren't accessible.

Result: MCP servers visible and authenticated in the parent session are missing or unauthenticated in the child worktree session.

Steps to Reproduce

  1. From /home/user/projects/my-repo, run claude; configure a project-scoped OAuth MCP server (e.g. claude mcp add clickup --transport http https://mcp.clickup.com/mcp); complete the OAuth flow.

  2. Verify it works in this parent session via /mcp and a tool call.

  3. From within that session, enter a worktree via Claude Code's worktree-session feature (EnterWorktree tool / /worktree command / equivalent).

  4. The child session's first jsonl record contains:

    {
      "type": "worktree-state",
      "worktreeSession": {
        "originalCwd": "/home/user/projects/my-repo",
        "worktreePath": "/home/user/projects/my-repo/.claude/worktrees/<name>",
        "originalBranch": "<parent-branch>",
        "sessionId": "<parent-session-uuid>"
      },
      "sessionId": "<child-session-uuid>"
    }
  5. /mcp in the child session shows the server is unconfigured/unauthenticated for this scope. Tool calls fail or re-trigger OAuth.

Expected

Worktree-session transitions should treat the originalCwd's .projects[…] entry as the inherited base for MCP config and OAuth state. Either copy on transition, or resolve mcpServers and credentials via worktreeSession.originalCwd rather than current cwd.

Actual

Worktree-session child is keyed by worktreePath. No inheritance from originalCwd. User must reconfigure and re-authenticate per worktree.

Evidence

The session jsonl record type: "worktree-state" ties parent session, worktreePath, and originalCwd together — Claude Code already knows the originalCwd at child-session start. The information needed to do the inheritance is right there in the record; it's just not used for MCP resolution.

Verified locally:

  • Parent session at originalCwd has ~/.claude.json .projects["<originalCwd>"].mcpServers = { clickup: {...} } populated and working.
  • Child worktree session has ~/.claude.json .projects["<worktreePath>"] entry missing entirely.
  • Recent sessions across multiple repos: only the worktree-session child has the divergent project key; all sibling sessions are filed under the main path and work normally.

Impact

For developers using worktrees as their primary parallel-work mechanism (Claude Code's own tooling encourages this), every new worktree-session triggers a re-auth dialog for each project-scoped OAuth MCP server. Scales as O(repos × concurrent worktrees) of redundant OAuth flows.

User-global remote MCP servers (claude.ai family — Gmail, Calendar, Drive) work correctly across worktree transitions because they're not project-scoped. Only project-scoped servers exhibit this.

Related

  • #58226 (closed) — .mcp.json discovery in worktree checkout; distinct from this issue.
  • #32220 (closed) — EnterWorktree mid-session reinit for path-sensitive MCPs; related but doesn't cover parent-session MCP/auth inheritance specifically.
  • Both leave the worktree-session ⇄ originalCwd inheritance gap untouched, which is the root cause for project-scoped MCP servers.

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

claude-code - 💡(How to fix) Fix [BUG] Worktree-session feature doesn't carry project-scoped MCP config/auth from originalCwd to worktreePath