MCP server fails to connect when Claude Code runs from directory with spaces/special characters
Description
MCP servers fail to connect when Claude Code is launched from a directory containing spaces or special characters in the path, even when the MCP server's cwd is set to a clean path.
Steps to Reproduce
- Create an
.mcp.jsonin a directory with spaces/special characters (e.g., iCloud path):
````
/Users/user/Library/Mobile Documents/iCloud~md~obsidian/Documents/MyVault/.mcp.json
- Configure an MCP server with explicit
cwdpointing to a clean path:
``json``
{
"mcpServers": {
"myserver": {
"command": "/Users/user/.local/bin/uv",
"args": ["run", "python", "-m", "src.mcp.server"],
"cwd": "/Users/user/Projects/MyServer"
}
}
}
- Run
claudefrom the directory with special characters - Run
/mcp- server shows "Failed to reconnect"
Expected Behavior
MCP server should connect successfully since its cwd is set to a valid path without special characters.
Actual Behavior
MCP server fails to connect with "Failed to reconnect to [server-name]" message.
Workaround
Running Claude Code from a directory without spaces/special characters works:
cd /Users/user/Projects/MyServer && claude
Using the identical .mcp.json configuration from this clean path, the MCP server connects successfully.
Environment
- OS: macOS (Darwin 25.2.0)
- Claude Code version: 2.x
- Path causing issue:
/Users/user/Library/Mobile Documents/iCloud~md~obsidian/Documents/...(contains space in "Mobile Documents" and tildes) - MCP server cwd: Clean path without special characters
Analysis
The issue appears to be in how Claude Code spawns MCP subprocesses. The current working directory of Claude Code itself (not the MCP server's cwd) seems to affect subprocess spawning, possibly due to unescaped path handling.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗