Skip to content

fix: Claude Code registrations invisible to CheckStatus (duplicate path-variant keys, git worktrees)#1280

Open
crowdedfire wants to merge 2 commits into
CoplayDev:betafrom
conjoyco:fix/claude-config-key-matching
Open

fix: Claude Code registrations invisible to CheckStatus (duplicate path-variant keys, git worktrees)#1280
crowdedfire wants to merge 2 commits into
CoplayDev:betafrom
conjoyco:fix/claude-config-key-matching

Conversation

@crowdedfire

@crowdedfire crowdedfire commented Jul 20, 2026

Copy link
Copy Markdown

Description

Using claude multi-agent, I often have worktrees open in Unity while also having changes to a branch. In these circumstances, ReadUserScopeConfig can report NotConfigured for a working claude mcp add --scope local registration — claude mcp list shows UnityMCP Connected, but the MCP for Unity window says Claude Code isn't configured. Two independent causes, both observed live on Windows 11 on 2026-07-20:

  1. Duplicate path-variant keys shadow the real registration. ~/.claude.json accumulates duplicate projects keys for the same directory in different separator forms (D:/Dev/X vs D:\Dev\X). The reader merges duplicates last-entry-wins on the assumption the last is most recent, but JSON property order is not correlated with recency across variants — a stale variant without mcpServers can shadow the real entry.
  2. Git-worktree projects register under an unreachable key. claude mcp add --scope local keys the registration by the git main repo root. For a Unity project in a linked worktree (e.g. C:/Dev/stay-booping → repo C:/Dev/stay) that key is a sibling path, so the reader's ancestor walk can never reach it. The CLI resolves worktrees symmetrically, so the registration genuinely works — only the status check is blind.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Test update

Changes Made

All in MCPForUnity/Editor/Clients/McpClientConfiguratorBase.cs:

  • Merge duplicate normalized project keys by preferring the entry that actually carries a UnityMCP registration (new RegistrationRank: UnityMCP > any mcpServers > none; last-wins preserved among equal ranks).
  • After the ancestor walk finds nothing, parse the main repo root from a linked worktree's .git pointer file (gitdir: <root>/.git/worktrees/<name>, relative paths resolved) and retry the walk from there (new GetGitMainRepoRoot). Regular checkouts (.git directory) are unaffected.
  • The walk itself is extracted into FindUnityServerFromWalk so both starting points share it; existing semantics preserved, including "stop at the first project entry found even without UnityMCP".

Compatibility / Package Source

  • Unity version(s) tested: 2022.3.62f2 and 6000.4.1f1 (both editors running simultaneously against one local HTTP server)
  • Package source used (#beta, #main, tag, branch, or file:): https://github.com/conjoyco/unity-mcp.git?path=/MCPForUnity#v10.1.0-conjoyco.1 (branch fix/claude-config-key-matching, cut from v10.1.0)
  • Resolved commit hash from Packages/packages-lock.json (if using a Git package URL): 2d00ed2e877fdeb103fa64e3b0ed72f5c112a857

Testing/Screenshots/Recordings

  • Python tests (cd Server && uv run pytest tests/ -v)
  • Unity EditMode tests
  • Unity PlayMode tests
  • Package import/compile check
  • Not applicable (explain why in Additional Notes)

Live verification against both original failures (details in Additional Notes):

  • Worktree: CheckStatus on the worktree project returned NotConfigured before the patch and Configured after, with identical inputs (claude mcp list Connected throughout).
  • Duplicate keys: deliberately re-injected the observed failure configuration (stale backslash-variant key with empty mcpServers ordered after the real forward-slash key) — patched reader still reports Configured. No regression on a project with a single clean key.

Documentation Updates

  • I have added/removed/modified tools or resources
  • If yes, I have updated all documentation files using:
    • The LLM prompt at tools/UPDATE_DOCS_PROMPT.md (recommended)
    • Manual review of the generated changes

Related Issues

Relates to #664 (the --scope local registration path this reader parses).

Additional Notes

  • Changes are C#-only in the Claude config reader; Python server untouched, hence no Python tests. No EditMode coverage exists for this path today — happy to add a small test for RegistrationRank/GetGitMainRepoRoot if you'd like it as part of this PR.
  • Branch is cut from v10.1.0; happy to rebase onto beta if preferred — both commits are self-contained in one file and should cherry-pick cleanly.
  • Both failure modes arise naturally on Windows: separator-variant duplicates accumulate from tools writing ~/.claude.json with different cwd string forms, and worktree-based Unity projects are common in multi-branch workflows.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved Claude CLI configuration discovery when duplicate project entries exist.
    • Improved Unity MCP detection for linked Git worktrees and nested project directories.
    • Added more reliable handling of project configuration precedence and fallback lookup.

crowdedfire and others added 2 commits July 20, 2026 13:34
ReadUserScopeConfig merged duplicate normalized project keys from
~/.claude.json ("D:/Dev/X" vs "D:\Dev\X") last-entry-wins, on the
assumption the last is most recent. JSON property order is not
correlated with recency across variants: when the last duplicate is a
stale entry without mcpServers it shadows the real registration, and
CheckStatus reports NotConfigured despite a working
`claude mcp add --scope local` setup (observed live 2026-07-20).

Merge by preferring the entry that actually carries a UnityMCP
registration (then any mcpServers, then last-wins as before).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
`claude mcp add --scope local` keys the registration in ~/.claude.json
by the git MAIN repo root. When the Unity project is a linked worktree
(e.g. C:/Dev/stay-booping -> repo C:/Dev/stay) that key is a sibling
path, so ReadUserScopeConfig's ancestor walk never finds it and
CheckStatus reports NotConfigured while the CLI itself resolves the
worktree fine (`claude mcp list` shows Connected). Parse the main root
from the worktree's .git pointer file and retry the walk from there.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 258cc6e0-7212-478d-85a8-bd92d1911cb5

📥 Commits

Reviewing files that changed from the base of the PR and between bd72241 and 2d00ed2.

📒 Files selected for processing (1)
  • MCPForUnity/Editor/Clients/McpClientConfiguratorBase.cs

📝 Walkthrough

Walkthrough

Claude user-scope configuration lookup now ranks duplicate project entries, stops searches at configured project boundaries, and supports linked git worktrees by retrying from the main repository root.

Changes

Claude configuration resolution

Layer / File(s) Summary
Duplicate project merging
MCPForUnity/Editor/Clients/McpClientConfiguratorBase.cs
ReadUserScopeConfig merges duplicate project entries using RegistrationRank, prioritizing entries containing UnityMCP.
Registration lookup and worktree fallback
MCPForUnity/Editor/Clients/McpClientConfiguratorBase.cs
FindUnityServerFromWalk searches normalized project paths and GetGitMainRepoRoot enables fallback lookup for linked worktrees.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: scriptwonder

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: Claude Code registrations becoming invisible in CheckStatus for duplicate keys and worktrees.
Description check ✅ Passed The description follows the template well and includes the required sections, testing notes, compatibility details, and related issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Warning

⚠️ This pull request shows signs of AI-generated slop (defensive_cruft). It has been flagged by CodeRabbit slop detection and should be reviewed carefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant