claude --bg returns success but the session waits at the .mcp.json approval dialog; check pending project-server approval like workspace trust
Problem
Since 2.1.281, claude --bg checks workspace trust before it dispatches, and when no dialog can appear it exits with Workspace not trusted. It does not check project .mcp.json server approval.
In a trusted repository with unapproved .mcp.json servers, a scripted claude --bg "<task>" therefore prints backgrounded · <id> and returns success. The session then waits at the "N new MCP servers found in this project" selection dialog until someone attaches. The task never starts, and the caller can't tell from the launch result.
Repro (2.1.295, Windows 10, PowerShell; also seen on 2.1.289)
- A git repository whose root is trusted (
hasTrustDialogAccepted: truefor it in~/.claude.json) and has a committed.mcp.jsonwith two servers. Neither is approved: itsprojectsentry hasenabledMcpjsonServers: []anddisabledMcpjsonServers: [], and no settings file approves them. - From a script in that root, run
claude --bg --model haiku --name mcp-probe "Reply with the single word OK." - It prints
backgrounded · 9f327486 · mcp-probeand exits 0. claude logs 9f327486shows the "2 new MCP servers found in this project … Space to select · Esc to reject all" dialog.claude agents --jsonreported"state": "working"45 s after launch and"state": "blocked"about a minute later.
The same happens for a --bg session started in a linked worktree of that repository.
Expected / proposed
Treat pending project-server approval like the trust check that 2.1.281 added:
- When
--bg(or a restart) can't show a dialog, either exit with an error that names the pending servers and the folder to runclaudein, or start the session with those servers left unconnected and a warning. - Report the waiting state as
blocked(needs input) right away, not asworkingfirst.
A read-only way to ask "would this folder start unattended?" (trust plus pending MCP approvals) would also help orchestrators. #79707 asks for something similar for trust.
Notes
-pis no workaround, because it connects unapproved servers without asking (MCP project scope).--strict-mcp-configavoids the wait only by dropping project servers entirely.- The docs mention background sessions waiting on approval only for the pre-2.1.246
--strict-mcp-configcase.
Related: #98006 (pre-trust setting for scripted --bg), #79707.