claude -p does not wait for --mcp-config MCP servers before the first turn (async connect → tools missing); regression 2.1.110→2.1.119

Resolved 💬 2 comments Opened Jun 3, 2026 by undead1 Closed Jun 7, 2026

Summary

In headless/print mode (claude -p / --print), MCP servers configured via --mcp-config connect asynchronously / non-blocking, and the turn begins before they finish connecting. On the first (and often only) turn the model therefore has no tools and emits tool calls as text instead of executing them — nothing runs.

Regression: works on 2.1.110, broken by 2.1.119 (also 2.1.120 / 2.1.154 / 2.1.160 / 2.1.161). 2.0.77 also works.

Environment

  • Linux (Ubuntu 24.04), 2 vCPU; claude-code installed globally via npm.
  • A long-running worker spawns claude -p once per task with ~9 stdio MCP servers via --mcp-config <file> --strict-mcp-config --allowedTools <list> --tools "", prompt via stdin, --output-format stream-json --verbose --no-session-persistence.

Evidence

  • --debug log: [MCP] --mcp-config servers running fully async (nonblocking).
  • Per-server MCP log shows the server does connect (Successfully connected (transport: stdio) in 927ms) — but the turn has already finished (SIGINT ~1s later).
  • The system/init event lists every server "status":"failed" (emitted before the async connect completes) and "tools":[].
  • With more servers (slower aggregate connect, esp. on 2 cores) the race is lost every time → tools:[] on every turn.

Repro

echo "Use <mcp_tool> to do X now." | claude -p \
  --output-format stream-json --verbose --no-session-persistence \
  --system-prompt-file sp.txt --tools "" \
  --allowedTools mcp__server__tool \
  --mcp-config servers.json --strict-mcp-config
  • 2.1.110: servers connect, model emits a real tool_use, the tool runs.
  • 2.1.119+: init shows servers failed / tools:[]; the model emits the tool call as literal text (<invoke …> or a {"type":"tool_use",…} blob) — nothing executes.

Notes

  • MCP_TIMEOUT=120000 does not help (it's the connect timeout, not a wait-before-turn gate).
  • Per-server "alwaysLoad": true (docs say it blocks until connect) did not restore tools on 2.1.161 with the full set.

Expected

In --print mode the first prompt should not be built until --mcp-config / --strict-mcp-config servers have connected (at least alwaysLoad ones), or provide a flag/env to block on MCP startup. Otherwise headless agents that spawn claude -p per turn silently lose all MCP tools.

Workaround

Pin to 2.1.110 + DISABLE_AUTOUPDATER=1.

View original on GitHub ↗

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