Repository navigation
<
8000
div class="prc-PageHeader-TitleArea-2n2J0" data-component="TitleArea" data-size-variant="medium">
fix(claude): write project MCP servers to the local scope in ~/.claude.json - #23
Merged
Merged
Conversation
…e.json ClaudeApplyAdapter passed the project path as the Claude home for project scope, so ClaudeAdapter wrote mcpServers with resolved secrets to <project>/.claude.json. Claude Code never reads that file, and the secret landed in the repository. For project scope the servers now go to ~/.claude.json under projects["<project path>"].mcpServers (Claude Code's private local scope). The file is read, merged and written back, so every other key survives and --override replaces only that project's servers. A new file is created with mode 0600, and an unparsable file is left untouched instead of being replaced by an empty document. fileChanges now names the real file. Closes #15
This was referenced Oct 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #15
Problem
profile apply claude <profile>(project scope) wrote MCP servers, with secrets already resolved, to<project>/.claude.json. Claude Code never reads that file, so the servers did not load, and the secret sat in the working tree where a commit could pick it up.Cause: for project scope
ClaudeApplyAdapterpassed the project path as the Claude home, soClaudeAdapterbuilt its MCP path as<project>/.claude.json.Change
~/.claude.json→projects["<project path>"].mcpServers. Claude Code reads that location, and it stays out of the repository.~/.claude.jsonis kept.--overridereplaces only this project's servers.~/.claude.jsongets mode0600. An existing file keeps its mode.~/.claude.json. Now a missing file starts empty; a file that cannot be parsed, or is not a JSON object, makes the apply fail and leaves the file untouched. This also covers user scope.apply claude) still writes top-levelmcpServers, unchanged.The second point in the issue (the
ENV_FILE_MISSINGwarning only visible with-v) already works on current main; this PR adds a regression test for it.Verification
ClaudeAdapter.test.ts, 2 inapply-profile.test.ts. 6 failed before the fix and pass after; the warning test passes before and after.bun test: 1102 pass, 0 fail.scripts/lint.sh(tsc, ESLint, ShellCheck), Prettier on changed files andbun run buildpass.AGENT_CTRL_CLAUDE_HOMEat a temp dir; I checked that the real~/.claude.jsongained no test entries.~/.claude.jsonsurvived; the server landed underprojects[<path>].mcpServers; file mode was kept; no secret anywhere in the project tree; without.envand without-vtheENV_FILE_MISSINGwarning shows.Not in this PR
<project>/.claude.jsonwritten by older versions is neither deleted nor reported. Remove it by hand if it holds secrets.