[BUG] [MCP] Working directory reset when server name mismatch workspace

Resolved 💬 4 comments Opened Jan 16, 2026 by codeg-old Closed Jan 19, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When configuring MCP servers in .mcp.json with bash cd commands to set different working directories, the working directory is forcibly reset to the current VSCode workspace path for some servers but not others. The only difference between working and non-working servers is the server name.

Servers whose names do NOT start with the workspace directory name have their cwd reset to the workspace path, while servers whose names do start with the workspace directory name work correctly.

What Should Happen?

All MCP servers should respect the working directory set by the bash cd command in the configuration, regardless of the server name.

Error Messages/Logs

When running `cd /path && claude --version` in terminal, the following message appears:


Shell cwd was reset to /home/user/workspace/main-project


No error is thrown - the cwd is silently reset.

Steps to Reproduce

  1. Open VSCode with workspace at /home/user/workspace/main-project
  2. Create .mcp.json in the workspace root with two MCP servers:
{
  "mcpServers": {
    "other-project": {
      "command": "/bin/bash",
      "args": ["-c", "cd /home/user/workspace/other-project && claude mcp serve"]
    },
    "main-project-sub": {
      "command": "/bin/bash",
      "args": ["-c", "cd /home/user/workspace/sub-project && claude mcp serve"]
    }
  }
}
  1. Restart VSCode
  2. Use each MCP server's Bash tool to run pwd
  3. Observe:
  • other-project reports /home/user/workspace/main-project (wrong - reset to workspace)
  • main-project-sub reports /home/user/workspace/sub-project (correct)

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.7 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

VS Code integrated terminal

Additional Information

Observed Pattern

| Server Name | Starts with Workspace Name? | cwd Result |
|-------------|----------------------------|------------|
| main-project-sub | ✅ Yes | ✅ Correct |
| main-project-api | ✅ Yes | ✅ Correct |
| other-project | ❌ No | ❌ Reset to workspace |
| different-name | ❌ No | ❌ Reset to workspace |

Workaround

Rename MCP servers to start with the workspace directory name:

  • other-projectmain-project-fe (now works)

Attempted Fixes (All Failed)

  1. Using env.PWD in server config
  2. Using cwd field in server config
  3. Using --cwd flag (not supported by claude mcp serve)
  4. Changing server order in .mcp.json
  5. Disabling hooks in target project's .claude/settings.json

Related Issues

  • #5037 - MCP servers in .claude/.mcp.json not loading properly
  • #4938 - Multiple mcpServers sections silently override each other

Suggested Investigation

The MCP server initialization logic may be checking if the server name matches or starts with the workspace name, and if not, forcing the cwd to the workspace path. This appears to be either:

  1. An undocumented security feature
  2. A bug in path resolution

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗