MCP server fails to connect when Claude Code runs from directory with spaces/special characters

Resolved 💬 3 comments Opened Jan 20, 2026 by egecemkirci Closed Jan 20, 2026

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

  1. Create an .mcp.json in a directory with spaces/special characters (e.g., iCloud path):

``
/Users/user/Library/Mobile Documents/iCloud~md~obsidian/Documents/MyVault/.mcp.json
``

  1. Configure an MCP server with explicit cwd pointing 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"
}
}
}
``

  1. Run claude from the directory with special characters
  2. 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.

View original on GitHub ↗

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