claude-code - 💡(How to fix) Fix [BUG] MCP servers from .mcp.json not loaded when using --worktree flag

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…
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 using claude --worktree, MCP servers defined in a committed .mcp.json file are not available in the session, even though the file is physically present in the worktree checkout.

It appears MCP config discovery and server initialization happens based on the original repo directory before the worktree is set up, and doesn't re-run after the worktree becomes the working directory.

Steps to Reproduce

  1. Have a repo with a committed .mcp.json (e.g. demo-app/.mcp.json)
  2. Run claude --worktree
  3. The file exists in the worktree (confirmed via ls), but the MCP server is not configured/available

Example repo: https://github.com/mxschmitt/aicouncil-talk-e2e-testing-with-ai/blob/main/demo-app/.mcp.json

Expected Behavior

MCP servers defined in .mcp.json files should be discovered and initialized relative to the worktree's working directory, so they work the same as when running claude directly in the repo.

Actual Behavior

MCP servers are not loaded. The .mcp.json is ignored despite being present in the worktree.

Related Issues

  • #32220 — MCP servers should reinitialize when session enters a git worktree (closed as stale, not fixed)
  • #12885 — working directory mismatch with worktrees

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