Repository navigation
Fix: sbx up warns about Claude Code's MCP prompt; doctor names the recovery (#577) - #591
Conversation
…ecovery `enabledMcpjsonServers` cannot suppress Claude Code's first-session prompt, so #577's toolless state is reachable by pressing Enter. Two gates have to hold before the question stops: the enable key AND folder trust, and that trust lives in ~/.claude.json, outside the working tree, where only the user's own answer puts it. Both are recorded against the directory `claude` was started in, while .mcp.json is found by searching upwards, so a session started in a subdirectory asks every time, whatever `up` wrote at the root. `up` therefore cannot pre-approve the server from inside the tree. Instead it now says what is coming, that the highlighted default declines, and to start claude in the root. `doctor` carries the recovery in the problem itself: `up` cannot make this fix (it never writes settings.local.json, and writeAgentConfig refuses to merge over the rejection), so its own "run up again" hint no longer implies it can. - up: after writing the config, name the prompt, the option to pick, and the root - checkAgentConfig: each disabledMcpjsonServers problem states its consequence and its fix (delete settings.local.json, or drop the key from settings.json) - doctor: the agent-config fix line defers to a problem that names its own remedy - user guide: correct why the prompt appears (trust + cwd, not an ignored key) and cover the subdirectory case Tests cover both messages and fail without the change; the suite is 1462 green. Refs #577 Signed-off-by: cwiklik <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
Small, well-scoped fix for #577: sbx up now warns (only when it actually wrote config) that the first claude session asks about the sandbox MCP server and that the highlighted default declines, and doctor's disabledMcpjsonServers problems now carry their own remedy instead of pointing at up, which can't make that fix. The tests are assertive and include the negative case (--no-agent-config, second up). Two nits only.
Author: cwiklik (MEMBER — maintainer)
Areas reviewed: TypeScript (mocactl sbx), tests, docs
Agent/IDE config (.claude/.vscode): none (the code writes .claude/ files at runtime, but the PR adds no such files)
Commits: 1 commit, all signed-off: yes
CI status: passing (all checks green)
| fix: `${UP} merges it again (anything it names as a conflict is for you to fix by hand)`, | ||
| // A problem that states its own remedy is one `up` cannot make (a conflict it refuses to | ||
| // merge over, or settings.local.json, which it never writes): do that by hand instead. | ||
| fix: `${UP} merges it again; where a problem above names its own fix, make that one by hand`, |
There was a problem hiding this comment.
nit: doctor prints this as agent config: <problems joined by '; '> (fix: …) on one line, and the new problem text has its own ; (…nor its own; delete …). So "a problem above" doesn't match the layout, and the problem boundaries blur. Consider joining problems with | or newlines, or rewording to "where a problem names its own fix".
| // highlighted default declines, which leaves the agent with no tools at all. Say so here: | ||
| // by the time it appears, this output is the only place the recovery was ever named. | ||
| c.io.err( | ||
| `start claude in ${root} (not a subdirectory); the first session asks about the ` + |
There was a problem hiding this comment.
nit: this prints root raw, while every other user-facing line in this file goes through say()/sanitizeRemote. It's a local path, so the risk is low, but a repo path containing control characters would reach the terminal unfiltered. Something like sanitizeRemote(root) would keep it consistent.
Claude Code's approval of a project-scoped .mcp.json server lives in ~/.claude.json keyed on the working directory, so sbx up's enabledMcpjsonServers cannot suppress the first-session prompt — and the prompt's highlighted default declines, which together with up's deny list leaves the agent with no tools (#577, #591). Add `mocactl sbx claude [-- CLAUDE_ARGS ...]`, mirroring `sbx codex` (#593): it spawns claude with --mcp-config <inline JSON> and --strict-mcp-config, registering the sandbox's MCP server for that one run. Flag-scoped servers need no approval and write nothing, so no prompt fires from any directory, and a past decline's disabledMcpjsonServers cannot reject the server — the toolless state heals by just starting the session this way. Verified against claude 2.1.308 from the repo root, from a subdirectory, and over a sticky decline; --strict-mcp-config's prompt skip needs claude >= 2.1.246. The trade is the one up's deny list already makes: the session loads no MCP server but the sandbox's. An explicit --sandbox or --control-plane-url is forwarded into the server's argv; the env-var URL case needs no help, as Claude Code passes its whole environment to a stdio server. up's post-config warning and doctor's recovery now name the launcher, and the user guide documents it as the prompt-free way to start Claude Code. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Summary
Fixes the toolless state in #577, and corrects the diagnosis on the way: the issue's premise —
that
enabledMcpjsonServersin.claude/settings.jsonis not consulted — turns out not to hold.upnow says what the firstclaudewill ask, that the highlighted default declines, and whereto start the session.
doctorcarries the recovery in the problem itself, becauseupcannotmake that fix.
Why
enabledMcpjsonServersalone cannot suppress the promptEstablished empirically against
claude2.1.263 — a stub stdio MCP server namedsandboxin.mcp.json,claude mcp listas the oracle (⏸ Pending approval= the prompt would fire,✔ Connected= suppressed), isolatedHOME, reset between every case.There are two independent gates, and both must hold:
~/.claude.json→projects[cwd].hasTrustDialogAccepted)settings.jsonenabledMcpjsonServers: [sandbox]settings.local.jsonenabledMcpjsonServerssettings.jsonenableAllProjectMcpServers: trueprojects[cwd].enabledMcpjsonServersSo
enabledMcpjsonServersis consulted and does work — it is necessary but notsufficient. The second gate is folder trust, which lives in
~/.claude.json, outside the workingtree, and only the user's own answer to the trust dialog puts it there. No in-tree key grants it:
hasTrustDialogAccepted,trustedFolder,trustFolderandautoApproveMcpServersin.claude/settings.jsonall leave the prompt firing.An empty
projects[cwd].enabledMcpjsonServers: []does not override a populatedsettings.json, so the~/.claude.jsondump in the issue was not the cause either.What actually triggered the report: the session's cwd
Both gates are keyed on the directory
claudewas started in, while.mcp.jsonis found bysearching upwards. A session started below the config directory therefore finds the server
and has no approval for it:
repo/pkg/deeprepo/pkg/deep.mcp.jsoncopied beside cwdrepo/pkg/deepprojects[<git root>]trust + enablerepo/pkg/deepThe issue notes the session was launched from a subdirectory — that is the trigger. A nested
directory that is its own git root works fine, so the discriminator is "cwd is not the directory
holding the config", not "nested path".
upwrites at the git root (repoRootviagit rev-parse --show-toplevel), so a user who startsclaudein a subdirectory gets no benefitfrom what
upwrote, however correct it is.The upstream issues the report cites (anthropics/claude-code#24657, #16402) are about
settings.local.jsonand are both closed as duplicates of #5037 (completed); they do not describethis behaviour.
Approach
This is the issue's own (2) + (3). Option (1) — write the approval to
~/.claude.json— isnot available: the missing half is folder trust, so "writing the approval" means recording a trust
decision on the user's behalf, outside the tree. That is a security decision, not a config fix.
What is left is to say the prompt is coming and to make the recovery discoverable.
Changes
sync.ts(cmdUp) — afterconfigured Claude Code and OpenCode: …, a second stderr line:start
claudein the root (not a subdirectory), the first session asks about the server, thehighlighted default declines, choose "Use this MCP server". Only printed when a
configuration was actually written, so
--no-agent-configstays silent.agent-config.ts(checkAgentConfig) — eachdisabledMcpjsonServersproblem now statesits consequence and its fix. New exported
CLAUDE_PROMPT_PICK, so what we tell the user topick reads the same as what Claude Code shows them.
doctor.ts(configCheck) — thefixline no longer impliesupcan repair everything.docs/sbx/user-guide.md— corrected why the prompt appears (trust + cwd, not an ignoredkey), the subdirectory case, and the §3 wording that said Claude Code "may ask once … approve
it" without mentioning that the default declines.
A second bug, not in the issue
doctor's fix line readmocactl sbx up merges it again (anything it names as a conflict is for you to fix by hand). For thesettings.local.jsonrejection that is a dead end:upneverwrites that file, and
writeAgentConfigthrowsConfigConflictrather than merge over therejection. So
doctordiagnosed the toolless state correctly and then pointed at a remedyguaranteed to fail. The problem line now carries the real recovery:
and the
settings.jsonvariant names its own fix too (remove sandbox from disabledMcpjsonServers in .claude/settings.json), sinceuprefuses that one as well.Tests
Three new cases and one tightened:
upwarns about the prompt, the declining default and the root — and says nothing under--no-agent-configdoctornames deletingsettings.local.jsonas the one fix, asserts the consequence clause,and asserts that
writeAgentConfigstill refuses — so the fix it names is the only one there issettings.jsonrejection reports its own remedyEach new test was verified to fail against unfixed source (source reverted, tests kept), so
they guard the behaviour rather than restate it.
tsc --noEmitclean;prettier --checkclean on all changed files.What this does not do
The prompt still appears on a first session — it cannot be suppressed from inside the working
tree. Accepting the folder trust and the server once ends it for good. The remaining gap is the
subdirectory case, which is now documented rather than worked around: an approval given at the
root does not apply below it.
Refs #577
Assisted-By: Claude