Repository navigation
fix(setup): admit only strict JSON for Claude Code configuration - #4944
Conversation
Claude Code shared the generic `json` client format, which the shared configuration reader admits through JSONC parsing with comments and trailing commas enabled. Native Claude Code reads `.claude.json` with a strict JSON parser (after a UTF-8 BOM), so setup reported `ready`, wrote a registration into a file the client rejects as corrupt, and doctor reported it `aligned`. Give Claude Code its own `claude_code` configuration format and parse it at the owning boundary with strict JSON.parse after removing a leading BOM. Setup, doctor, and uninstall all consume that parser, so comment or trailing-comma documents are now refused as malformed before any backup or write, while plain and BOM-prefixed JSON still configure. Clients that natively accept JSONC keep the `json` format and its behavior. Fixes #4940 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The PR appears safe to merge; no actionable defects were found. SummaryClaude Code now uses strict JSON parsing through the shared configuration reader.
No actionable defects or security issues were found. Tests were inspected, not run. Whether another PR supersedes this one could not be checked because GitHub access required authentication. Reviews (1) · Last reviewed commit: "fix(setup): admit only strict JSON for C..." · Reviewed by Greptile |
Summary
Fixes #4940. Claude Code setup reported
readyfor a.claude.jsonwith a comment or trailing comma, kept that syntax in the file it wrote, and doctor then reported the registrationaligned. The issue reporter found that native Claude Code rejects such a file as corrupt JSON. With this change, setup, doctor and uninstall refuse those files as malformed before writing anything or creating a backup. Plain JSON and BOM-prefixed JSON still configure.Problem and expected behavior
Trigger:
.claude.json={ // comment\n "mcpServers": {...} }(or a trailing comma). Claude Code shared the genericjsonclient format.parseDocumentreads that format throughjsonc-parserwith comments and trailing commas enabled. The broken rule: setup must not admit configuration the selected native client cannot load. Expected:needs_humanwith no write or backup, and doctor reporting the registrationinvalidrather thanaligned.Change and scope
SupportedClients.ts: Claude Code now uses its ownclaude_codeconfiguration format instead ofjson.ClientConfigurationDocument.ts(parseDocument): the new format is parsed with strictJSON.parseafter removing a leading UTF-8 BOM. This matches the native behavior described in the issue and follows the existing per-client strict readers (Pi, Kimi, ZCode). Setup, doctor and uninstall already use this parser, so no downstream changes are needed.jsonformat used.json-format clients (Cursor, Claude Desktop, Windsurf, etc.) keep JSONC admission. Their native readers were not re-examined here. Empty-file handling for Claude Code is unchanged.Contract and boundary impact
Semantic owner and earliest changed stage:
parseDocumentinsrc/application/ClientConfigurationDocument.ts, selected by the client's format inSupportedClients.ts.Contribution scope fit and linked maintainer decision: not applicable.
CLI and MCP/tool-catalog contract: setup's
clientStates[].client.formatfor Claude Code changes from"json"to"claude_code". No tool catalog changes.Provider, bridge, target-format, or platform compatibility: none.
Evidence, artifact, provenance, or reconstruction contract: none.
Target selection, authority, upstream behavior, and cleanup details: not applicable.
Generated metadata:
setup_clients[].formatforclaude_codein the generated product catalog becomes"claude_code".npm run docs:checkpasses.Read existing files or captured data.
Change process memory, registers, files, or configuration. (Only refusals change: fewer writes than before.)
Evidence and regression coverage
tests/acceptance/setup/claudeCodeStrictJsonSetup.test.ts(public CLI):--dry-runand--yesreturnneeds_humanwith a "malformed" remediation, doctor reportsinvalid, uninstall reportsfailed, file bytes are unchanged and no.rea.backupexists.configured, the backup is byte-exact, the BOM is kept, the output passesJSON.parse, and doctor reportsaligned.tests/boundary/filesystem/clientConfigurationBom.test.ts: removedclaude_codefrom the comment-preserving JSONC matrix, which encoded the bug.tests/boundary/filesystem/windowsNpxRegistration.test.ts: Claude Code fixtures now use theclaude_codeformat.847472acf,node scripts/rea.mjs setup --client claude_code --skill=false --dry-run --jsonwithHOME/CLAUDE_CONFIG_DIRpointed at an isolated directory holding the issue's fixture returnedplanned, exit 0. With this change it returnsneeds_human, exit 1.Validation performed
npm run test:focused -- tests/acceptance/setup/claudeCodeStrictJsonSetup.test.ts tests/boundary/filesystem/clientConfigurationBom.test.ts tests/boundary/filesystem/windowsNpxRegistration.test.ts tests/acceptance/setup/clientConfigurationDiagnosticsCli.test.ts tests/boundary/filesystem/clientConfigurationDialects.test.ts tests/boundary/filesystem/clientLifecycle.test.ts tests/boundary/filesystem/clientRegistrationStatus.test.ts tests/boundary/filesystem/productCatalog.test.ts: 8 files passed, 167 passed, 2 skipped (Windows-only)npm run check:fast: passednpm run docs:check: passednpx oxfmt --checkon the changed files: passedplanned/exit 0 before,needs_human/exit 1 afterCompatibility, safety, and release
claude_codechanges.Author readiness
Human owner:
Before merge
type(scope): outcome.🤖 Generated with Claude Code