[PR #4949] [CLOSED] fix(setup): reject JSONC comments and trailing commas in Claude Code configuration (#4940) #6687

Closed
opened 2026-11-01 21:42:18 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/4949
Author: @prasad2512
Created: 10/18/2026
Status: ❌ Closed

Base: main ← Head: fix/claude-code-jsonc-rejection


📝 Commits (1)

  • e97ff88 fix(setup): reject JSONC comments and trailing commas in Claude Code configuration (#4940)

📊 Changes

4 files changed (+335 additions, -1 deletions)

View changed files

➕ src/application/ClientConfigurationDocument.claudeCode.test.ts (+152 -0)
📝 src/application/ClientConfigurationDocument.ts (+8 -0)
📝 src/application/SupportedClients.ts (+2 -1)
➕ tests/acceptance/setup/claudeCodeClientSetup.test.ts (+173 -0)

📄 Description

Summary

Fixes #4940

Claude Code loads .claude.json using native strict JSON.parse, which rejects comments (JSON Parse error: Unrecognized token '/') and trailing commas (Property name must be a string literal). Previously, Claude Code had format: "json", which routed its admission through the permissive JSONC reader (allowTrailingComma: true, comments enabled by default). As a result, rea setup reported ready / configured and rea doctor reported aligned on .claude.json files with comments or trailing commas that native Claude Code rejected as corrupt.

This change introduces format: "claude_code" to enforce strict JSON parsing while preserving Claude Code's observed UTF-8 BOM tolerance and empty file fallback, rejecting malformed JSON before creating backups or mutating configuration files.

Problem and expected behavior

When .claude.json contains comments or trailing commas:

  1. rea setup --client claude_code --skill=false --dry-run --json planned changes instead of rejecting the corrupt syntax.
  2. rea setup --client claude_code --skill=false --yes --json reported ready and created a backup, leaving the invalid syntax in place.
  3. rea doctor --client claude_code --json reported the registration as aligned.
  4. Native claude mcp get <server> failed with JSON Parse error: Unrecognized token '/' or Property name must be a string literal.

Expected behavior:
Setup must reject syntax the selected native client cannot load before creating a backup or mutating configuration (status: "needs_human", exit code 1). Doctor must identify malformed configuration as state: "invalid" instead of declaring it aligned. Observed UTF-8 BOM tolerance is preserved, and JSONC admission for generic JSON clients (such as Cursor) remains intact.

Change and scope

  • Added claude_code to SetupClient["format"] and updated SUPPORTED_CLIENT_DEFINITIONS for claude_code.
  • In parseDocument, routed format === "claude_code" through native strict JSON.parse after stripping any UTF-8 BOM, validating the root with requireObject.
  • Kept permissive JSONC parsing intact for generic json clients.
  • Added comprehensive unit tests in src/application/ClientConfigurationDocument.claudeCode.test.ts.
  • Added acceptance CLI tests in tests/acceptance/setup/claudeCodeClientSetup.test.ts.

Follow the contribution scope.
Ordinary bug fix within existing configuration parsing boundary; maintainer scope decision: not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/application/ClientConfigurationDocument.ts (parseDocument)
  • Contribution scope fit and linked maintainer decision: not applicable (bug fix within existing boundary)
  • CLI and MCP/tool-catalog contract: none
  • Provider, bridge, target-format, or platform compatibility: aligns .claude.json parsing with native Claude Code 2.1.263
  • Evidence, artifact, provenance, or reconstruction contract: none
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): none
  • Generated metadata, package, or installation impact: none

Expected effects:

  • Change process memory, registers, files, or configuration.

Evidence and regression coverage

  • Tests added or updated:
    • src/application/ClientConfigurationDocument.claudeCode.test.ts
    • tests/acceptance/setup/claudeCodeClientSetup.test.ts
  • Base reproduction or other evidence: Verified against reported issue #4940 that comments and trailing commas in .claude.json previously parsed as valid JSONC and reported aligned/ready.
  • User-visible CLI/MCP output (if applicable): rea setup reports needs_human with malformed remediation; rea doctor reports state: "invalid".
  • Remaining proof gaps: none

Validation performed

  • npm run test:local -- src/application/ClientConfigurationDocument.claudeCode.test.ts — 16 passed (88ms)
  • npm run test:local -- src/application/ClientConfigurationDocument.shape.test.ts — 7 passed (46ms)
  • npm run check:fast — 2 tasks successful (typecheck + lint passed without errors)
  • npm run format:check — passed (all files use correct format)
  • npm run metadata:check — passed

Compatibility, safety, and release

  • Breaking changes or migration steps: none
  • Real Hopper/Ghidra, browser, or OS coverage: platform-independent
  • Package or release metadata impact: none
  • Security, privacy, process, or containment review: none

Author readiness

Human owner: @prasad2512

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/4949 **Author:** [@prasad2512](https://github.com/prasad2512) **Created:** 10/18/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/claude-code-jsonc-rejection` --- ### 📝 Commits (1) - [`e97ff88`](https://github.com/morluto/rea/commit/e97ff8899035b3b6fc5cbc1ccb03f6f376e88da4) fix(setup): reject JSONC comments and trailing commas in Claude Code configuration (#4940) ### 📊 Changes **4 files changed** (+335 additions, -1 deletions) <details> <summary>View changed files</summary> ➕ `src/application/ClientConfigurationDocument.claudeCode.test.ts` (+152 -0) 📝 `src/application/ClientConfigurationDocument.ts` (+8 -0) 📝 `src/application/SupportedClients.ts` (+2 -1) ➕ `tests/acceptance/setup/claudeCodeClientSetup.test.ts` (+173 -0) </details> ### 📄 Description ## Summary Fixes #4940 Claude Code loads `.claude.json` using native strict `JSON.parse`, which rejects comments (`JSON Parse error: Unrecognized token '/'`) and trailing commas (`Property name must be a string literal`). Previously, Claude Code had `format: "json"`, which routed its admission through the permissive JSONC reader (`allowTrailingComma: true`, comments enabled by default). As a result, `rea setup` reported `ready` / `configured` and `rea doctor` reported `aligned` on `.claude.json` files with comments or trailing commas that native Claude Code rejected as corrupt. This change introduces `format: "claude_code"` to enforce strict JSON parsing while preserving Claude Code's observed UTF-8 BOM tolerance and empty file fallback, rejecting malformed JSON before creating backups or mutating configuration files. ## Problem and expected behavior When `.claude.json` contains comments or trailing commas: 1. `rea setup --client claude_code --skill=false --dry-run --json` planned changes instead of rejecting the corrupt syntax. 2. `rea setup --client claude_code --skill=false --yes --json` reported `ready` and created a backup, leaving the invalid syntax in place. 3. `rea doctor --client claude_code --json` reported the registration as `aligned`. 4. Native `claude mcp get <server>` failed with `JSON Parse error: Unrecognized token '/'` or `Property name must be a string literal`. Expected behavior: Setup must reject syntax the selected native client cannot load before creating a backup or mutating configuration (`status: "needs_human"`, exit code 1). Doctor must identify malformed configuration as `state: "invalid"` instead of declaring it aligned. Observed UTF-8 BOM tolerance is preserved, and JSONC admission for generic JSON clients (such as Cursor) remains intact. ## Change and scope - Added `claude_code` to `SetupClient["format"]` and updated `SUPPORTED_CLIENT_DEFINITIONS` for `claude_code`. - In `parseDocument`, routed `format === "claude_code"` through native strict `JSON.parse` after stripping any UTF-8 BOM, validating the root with `requireObject`. - Kept permissive JSONC parsing intact for generic `json` clients. - Added comprehensive unit tests in `src/application/ClientConfigurationDocument.claudeCode.test.ts`. - Added acceptance CLI tests in `tests/acceptance/setup/claudeCodeClientSetup.test.ts`. Follow the [contribution scope](https://github.com/morluto/rea/blob/main/CONTRIBUTING.md#contribution-scope). Ordinary bug fix within existing configuration parsing boundary; maintainer scope decision: not applicable. ## Contract and boundary impact - Semantic owner and earliest changed stage: `src/application/ClientConfigurationDocument.ts` (`parseDocument`) - Contribution scope fit and linked maintainer decision: not applicable (bug fix within existing boundary) - CLI and MCP/tool-catalog contract: none - Provider, bridge, target-format, or platform compatibility: aligns `.claude.json` parsing with native Claude Code 2.1.263 - Evidence, artifact, provenance, or reconstruction contract: none - Target selection, authority, upstream behavior, and cleanup details (if applicable): none - Generated metadata, package, or installation impact: none Expected effects: - [x] Change process memory, registers, files, or configuration. ## Evidence and regression coverage - Tests added or updated: - `src/application/ClientConfigurationDocument.claudeCode.test.ts` - `tests/acceptance/setup/claudeCodeClientSetup.test.ts` - Base reproduction or other evidence: Verified against reported issue #4940 that comments and trailing commas in `.claude.json` previously parsed as valid JSONC and reported aligned/ready. - User-visible CLI/MCP output (if applicable): `rea setup` reports `needs_human` with malformed remediation; `rea doctor` reports `state: "invalid"`. - Remaining proof gaps: none ## Validation performed - `npm run test:local -- src/application/ClientConfigurationDocument.claudeCode.test.ts` — 16 passed (88ms) - `npm run test:local -- src/application/ClientConfigurationDocument.shape.test.ts` — 7 passed (46ms) - `npm run check:fast` — 2 tasks successful (typecheck + lint passed without errors) - `npm run format:check` — passed (all files use correct format) - `npm run metadata:check` — passed ## Compatibility, safety, and release - Breaking changes or migration steps: none - Real Hopper/Ghidra, browser, or OS coverage: platform-independent - Package or release metadata impact: none - Security, privacy, process, or containment review: none ## Author readiness Human owner: @prasad2512 - [ ] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [ ] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [ ] I declare this PR ready for initial maintainer review. ## Before merge - [ ] This PR addresses a concrete problem or an agreed enhancement. - [ ] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [ ] The PR has one focused outcome and the title follows `type(scope): outcome`. - [ ] Related issue is linked, or the reason for not linking one is stated above. - [ ] Tests cover changed observable behavior and meaningful failure paths. - [ ] Owning docs, contracts, and generated metadata are updated where needed. - [ ] User-visible CLI/MCP changes include representative output. - [ ] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:42:18 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6687
No description provided.