Skip to content

Fix: sbx up warns about Claude Code's MCP prompt; doctor names the recovery (#577) - #591

Merged
pdettori merged 1 commit into
mainfrom
fix/577-trust-prompt-expectation
Oct 22, 2026
Merged

pdettori merged 1 commit into
mainfrom
fix/577-trust-prompt-expectation

Conversation

@cwiklik

@cwiklik cwiklik commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the toolless state in #577, and corrects the diagnosis on the way: the issue's premise —
that enabledMcpjsonServers in .claude/settings.json is not consulted — turns out not to hold.

up now says what the first claude will ask, that the highlighted default declines, and where
to start the session. doctor carries the recovery in the problem itself, because up cannot
make that fix.

Why enabledMcpjsonServers alone cannot suppress the prompt

Established empirically against claude 2.1.263 — a stub stdio MCP server named sandbox in
.mcp.json, claude mcp list as the oracle (⏸ Pending approval = the prompt would fire,
✔ Connected = suppressed), isolated HOME, reset between every case.

There are two independent gates, and both must hold:

folder trust (~/.claude.json → projects[cwd].hasTrustDialogAccepted) enable key prompt
absent settings.json enabledMcpjsonServers: [sandbox] fires
absent settings.local.json enabledMcpjsonServers fires
absent settings.json enableAllProjectMcpServers: true fires
absent projects[cwd].enabledMcpjsonServers fires
accepted (none anywhere) fires
accepted any one of the four above suppressed

So enabledMcpjsonServers is consulted and does work — it is necessary but not
sufficient. The second gate is folder trust, which lives in ~/.claude.json, outside the working
tree, and only the user's own answer to the trust dialog puts it there. No in-tree key grants it:
hasTrustDialogAccepted, trustedFolder, trustFolder and autoApproveMcpServers in
.claude/settings.json all leave the prompt firing.

An empty projects[cwd].enabledMcpjsonServers: [] does not override a populated
settings.json, so the ~/.claude.json dump in the issue was not the cause either.

What actually triggered the report: the session's cwd

Both gates are keyed on the directory claude was started in, while .mcp.json is found by
searching upwards. A session started below the config directory therefore finds the server
and has no approval for it:

case cwd prompt
cwd is the dir holding the config git root suppressed (with trust)
cwd is a subdir, config at git root, trust on the subdir repo/pkg/deep fires
cwd is a subdir, trust on subdir and root repo/pkg/deep fires
cwd is a subdir, .mcp.json copied beside cwd repo/pkg/deep fires
cwd is a subdir, projects[<git root>] trust + enable repo/pkg/deep suppressed
cwd is its own git root, nested under another repo nested root suppressed

The 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". up writes at the git root (repoRoot via
git rev-parse --show-toplevel), so a user who starts claude in a subdirectory gets no benefit
from what up wrote, however correct it is.

The upstream issues the report cites (anthropics/claude-code#24657, #16402) are about
settings.local.json and are both closed as duplicates of #5037 (completed); they do not describe
this behaviour.

Approach

This is the issue's own (2) + (3). Option (1) — write the approval to ~/.claude.json — is
not 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) — after configured Claude Code and OpenCode: …, a second stderr line:
    start claude in the root (not a subdirectory), the first session asks about the server, the
    highlighted default declines, choose "Use this MCP server". Only printed when a
    configuration was actually written, so --no-agent-config stays silent.
  • agent-config.ts (checkAgentConfig) — each disabledMcpjsonServers problem now states
    its consequence and its fix. New exported CLAUDE_PROMPT_PICK, so what we tell the user to
    pick reads the same as what Claude Code shows them.
  • doctor.ts (configCheck) — the fix line no longer implies up can repair everything.
  • docs/sbx/user-guide.md — corrected why the prompt appears (trust + cwd, not an ignored
    key), 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 read mocactl sbx up merges it again (anything it names as a conflict is for you to fix by hand). For the settings.local.json rejection that is a dead end: up never
writes that file, and writeAgentConfig throws ConfigConflict rather than merge over the
rejection. So doctor diagnosed the toolless state correctly and then pointed at a remedy
guaranteed to fail. The problem line now carries the real recovery:

Claude Code: .claude/settings.local.json disabledMcpjsonServers rejects the sandbox MCP server,
so the agent has neither the sandbox's tools nor its own; delete .claude/settings.local.json
(mocactl sbx up never writes it) and answer "Use this MCP server" the next time Claude Code asks

and the settings.json variant names its own fix too (remove sandbox from disabledMcpjsonServers in .claude/settings.json), since up refuses that one as well.

Tests

Three new cases and one tightened:

  • up warns about the prompt, the declining default and the root — and says nothing under
    --no-agent-config
  • doctor names deleting settings.local.json as the one fix, asserts the consequence clause,
    and asserts that writeAgentConfig still refuses — so the fix it names is the only one there is
  • the settings.json rejection reports its own remedy

Each new test was verified to fail against unfixed source (source reverted, tests kept), so
they guard the behaviour rather than restate it.

Test Files  70 passed | 2 skipped (72)
     Tests  1462 passed | 4 skipped (1466)

tsc --noEmit clean; prettier --check clean 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

…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 ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ` +

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pdettori
pdettori merged commit 3e3d8c7 into main Oct 22, 2026
15 checks passed
@pdettori
pdettori deleted the fix/577-trust-prompt-expectation branch October 22, 2026 21:56
pdettori added a commit that referenced this pull request Oct 28, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants