Skip to content

feat(setup): support private Claude Code project registrations - #2414

Open
dev-zaib wants to merge 8 commits into
morluto:mainfrom
dev-zaib:codex/2187-claude-local-registration
Open

dev-zaib wants to merge 8 commits into
morluto:mainfrom
dev-zaib:codex/2187-claude-local-registration

Conversation

@dev-zaib

@dev-zaib dev-zaib commented Oct 12, 2026 •

Copy link
Copy Markdown

Closes #2187.

Claude Code setup currently registers REA for every project. rea setup --client claude_code --scope local [--project DIR] now writes only the selected private project registration. Its plan identifies the project and profile, and local setup skips personal skills and Hopper. Setup and uninstall retain their user-scope defaults.

Doctor checks the current project's effective registration, supports --project DIR, and reports source scope and project context. rea uninstall --scope local [--project DIR] removes only the owned entry in that project, preserving peer servers, user registrations, other projects, personal skills and shared data. Writes reuse backups, readback verification and rollback.

The parser selects local data before interpreting unrelated global tables. Physical Git roots and worktree metadata select the project; exact native Windows keys preserve inactive aliases. Unresolved project identity fails explicitly. Shared .mcp.json and managed-policy registrations are outside this change.

Latest update: 5d0264e merges main 70cd4cb, resolves integration conflicts, rejects empty local client selection and preserves local guidance for package-version drift. The review response explains the findings, fixes and native evidence for retaining exact drive casing and Git pointer paths.

Validation on the latest revision (Windows, Node 24.18.0/npm 11.16.0):

  • Two focused runs across 15 files: 258 passed, 3 skipped, 2 failed. All 19 compiled configuration CLI tests passed. Both failures reproduce in an unchanged main 70cd4cb checkout: Doctor's canonical Hopper install fixture and Claude Desktop's directory-symlink EPERM.
  • Typecheck, lint, formatting, knip, metadata, module boundaries, architecture guards, test discovery, generated-doc/license checks and five README consistency tests passed. Pre-push check passed.
  • Native Claude Code 2.1.296: linked-worktree setup/doctor/uninstall, byte-idempotence, peer preservation, inactive drive-case aliases and separate Git directories passed in isolated profiles. Native Windows npx.cmd/bunx.cmd launch tests passed.
  • npm pack --dry-run passed (1,665 entries).

The full suite, full package verifiers, authenticated Claude model use and Linux/macOS verification were not run for this revision. Earlier OCR reviews ran; further OCR remains skipped at the user's request after the configured account returned HTTP 402. No personal Claude profile was edited during verification.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@matbrgz

matbrgz commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Technical Review & Findings

1. Scope Leak on Failed Local Discovery (claudeCodeLocalClients in SetupHost.ts & Uninstall.ts)

In claudeCodeLocalClients (src/application/ClaudeCodeProjectDirectory.ts):

return clients
  .filter(({ name }) => name === "claude_code")
  .map((client) => ({ ...client, claudeProjectDirectory }));

However, in systemSetupHost:

const scopedClients = () => {
  const clients = supportedClients(homeDirectory, platform, environment);
  if (options.claudeProjectDirectory === undefined)
    return Promise.resolve(clients);
  return (localClients ??= claudeCodeLocalClients(
    clients,
    options.claudeProjectDirectory,
    resources,
  ));
};

If an error is thrown inside claudeCodeProjectDirectory (e.g., non-existent directory or invalid git metadata), claudeCodeLocalClients catches and throws an AnalysisInputError. However, if options.claudeProjectDirectory is passed to systemUninstallHost or systemSetupHost and clients.filter(({ name }) => name === "claude_code") finds no matching client or fails to resolve, claudeCodeLocalClients does not handle the case where supportedClients did not contain claude_code (e.g. unsupported platform or config path missing), potentially resulting in an unhandled empty candidates list with no diagnostics.

2. Windows Drive Letter Normalization Mismatch in Project Keys (claudeCodeRegistrationConfiguration)

In src/application/ClientConfigurationDocument.ts:

const selectedDirectory =
  platform === "win32"
    ? projectDirectory.replaceAll("\\", "/")
    : projectDirectory;
if (!Object.hasOwn(projects, selectedDirectory) && !exactLocal) return parsed;

On Windows, realpath and resolve may return paths with drive letters varying in casing depending on how Node resolved them (e.g., C:/Users/... vs c:/Users/...).
Claude Code's project dictionary indexing is case-sensitive JSON key matching (projects[selectedDirectory]). If Claude Code recorded the project with lowercase c:/... and realpath returned C:/... (or vice-versa), Object.hasOwn(projects, selectedDirectory) will evaluate to false. On non-exact local lookups (mode: "effective" in doctor), this causes doctor to miss the local registration and fall back to user scope or report the project as unconfigured even when registered in Claude Code.
Normalizing the drive letter casing (e.g. canonicalizing Windows drive letter to uppercase C:/ or lowercase) before matching against Object.keys(projects) prevents this mismatch.

3. Unchecked Worktree Pointer Leading/Trailing Whitespace in gitFileProjectDirectory

In gitFileProjectDirectory (src/application/ClaudeCodeProjectDirectory.ts):

const pointer = await readGitPath(join(directory, ".git"), resources);
if (!pointer.startsWith("gitdir: ") || pointer.length === 8)
  throw new TypeError("Invalid Claude Code project Git directory pointer");
const gitDirectory = resolve(directory, pointer.slice(8));

In git worktree files, git allows and sometimes generates trailing spaces or tabs, or Windows CRLF before gitdir: or around the path. While readGitPath strips trailing CRLF (.replace(/\r?\n$/u, "")), it does not .trim() trailing whitespace on pointer.slice(8). On Windows or Git configurations with trailing space in .git files, resolve(directory, pointer.slice(8)) includes the trailing whitespace in the path, leading to ENOENT during stat(gitDirectory) and aborting local setup with a TypeError.
Adding .trim() to pointer.slice(8).trim() avoids spurious resolution failures.

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

@greptileai review

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[High impact] The reviewed changes appear safe to merge; no new actionable issue remains.

Summary

Adds private Claude Code project registrations while keeping setup and uninstall in user scope by default.

  • Claude Code setup can register REA in one private project.
  • Doctor checks Claude Code’s registration for the selected project.
  • Local uninstall removes REA from one Claude Code project.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  CLI["Setup, doctor or uninstall"] --> Project["Resolve physical project and Git metadata"]
  Project --> Profile["Read configured Claude profile"]
  Profile --> Mode{"Requested operation"}
  Mode -->|Doctor| Effective["Select local REA entry, otherwise user entry"]
  Effective --> Status["Report registration, policy and project context"]
  Mode -->|Local setup or uninstall| Exact["Select exact project server table"]
  Exact --> Checks["Check policy, ownership and write safety"]
  Checks --> Backup["Preserve backup"]
  Backup --> Write["Write selected entry"]
  Write --> Readback{"Readback matches?"}
  Readback -->|Yes| Done["Complete"]
  Readback -->|No| Restore["Restore original profile"]
Loading

Reviews (8) · Last reviewed commit: "fix(setup): address project scope review..." · Reviewed by Greptile

@dev-zaib
dev-zaib requested a review from morluto October 13, 2026 13:00
@morluto morluto added enhancement New feature or request area: setup Setup, packaging, upgrade, install, Doctor, and client registration area: cli CLI adapter and one-shot commands area: domain Domain logic, errors, and pure functions P2: medium Medium priority issue labels Oct 13, 2026
@CassieFox23

CassieFox23 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: The private project registration works on Node 22, 24 and 26. Setup writes only the chosen project, and uninstall removes only that entry. I did not run rea setup or rea doctor, so the CLI flags are untested.

Edit: I reran the edge cases on the new head 5d0264e, here. The conflict note below no longer applies.

I tested head aa2e7c2 as pushed. GitHub says it conflicts with main b7dcf78. I used the writer and status code directly, with a throwaway home folder for each run.

Results

Check Node 22.23.1 Node 24.18.0 Node 26.11.1
The 3 test files this PR changes that run without setup (71 tests) pass pass pass
5 nearby client-config test files (72 tests, 2 skipped) pass pass pass
Writer script below, head same output same output same output

Before and after (Node 24.18.0)

Each run starts from the same .claude.json. It holds one user server, and two projects that each hold one server of their own.

Step Main b7dcf78 Head aa2e7c2
Setup for project A adds rea to the user servers adds rea to project A only
Run setup twice second run changes nothing second run changes nothing
Status for project A no scope shown scope local, project folder shown
Status for project B shows the user entry no entry
Setup with no project adds to user servers same as main
Local uninstall no project option removes only the entry in A; all other servers stay
Project key finder not there right key for four layouts

Status read stale on both builds. My fixture command was rea mcp, not the npx default, and I did not rerun with the default to confirm that is why. The four layouts are a plain folder, a nested folder, a symlink and a linked worktree. Two edge cases on head. A missing folder fails with a plain ENOENT in the finder (the setup path wraps it, which I did not run). A Git pointer with a trailing space fails the same way, which matches matbrgz's third review point. I did not check whether Git ever writes that space.

Not run

  • rea setup --scope local and rea doctor --project, because setup always runs Doctor.
  • The acceptance file for setup and Doctor, and two other test files that call the setup host or Doctor.
  • Windows, and the drive-letter point from matbrgz.
  • A real Claude Code session reading the files.
  • Head merged onto main. My file-level merge check found 20 conflict regions in 9 files (an estimate from a three-way diff, not Git's own merge).
  • The full suite, and macOS.

Thanks, dev-zaib, for the PR and its clear notes.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head: aa2e7c2
  • Base: 090b454
  • Other: main b7dcf78; scratch home folders under /tmp
Commands
npm ci && npm run build && npm run test:prepare
node scripts/run-development-tests.mjs focused tests/boundary/filesystem/clientConfigurationTransactions.test.ts tests/boundary/filesystem/clientRegistrationStatus.test.ts src/application/ClientConfigurationDocument.shape.test.ts
node scripts/run-development-tests.mjs focused <5 nearby files>
node e2e.mjs <dist folder> <work folder>

The script calls configureClientConfiguration, systemUninstallHost, readClientRegistrationStatuses and claudeCodeProjectDirectory from the compiled output. Each run sat under systemd-run --user --scope -p MemoryMax=6G.

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

Copy link
Copy Markdown
Author

@morluto, pushed 5d0264e and would appreciate another review. This merges main at 70cd4cb and resolves the nine conflicted files while retaining the newer source-layer, ZCode fallback, timeout and provider-budget behavior.

I reviewed matbrgz's findings and CassieFox23's verification report:

  1. Empty local client selection: the catalog currently always includes Claude Code, so I could not reproduce a user-scope leak. The shared local selector now rejects a missing Claude client with a structured AnalysisInputError instead of returning an empty list. Added a boundary regression; setup and uninstall share this owner.
  2. Windows drive casing: retained exact native key matching. With native Claude Code 2.1.296, moving its entry from C:/... to c:/... makes both native claude mcp remove --scope local rea and REA doctor report no active local entry. Case-insensitive matching would falsely report the inactive entry as ready. REA setup creates the canonical entry without altering the alias, and native Claude then removes that new entry successfully. Added a producer regression covering the inactive drive-case alias.
  3. Git pointer whitespace: retained exact path bytes rather than trimming. A real separate-git-dir checkout with spaces in its metadata path works; appending a space to its pointer makes Git itself fail with exit 128. Added coverage for rejecting the altered pointer and accepting CRLF metadata with spaces in its path. A missing project remains a structured CLI failure with no writes; the low-level resolver's filesystem error is wrapped by its setup/diagnostic owners.

The merge also exposed a new version-drift message that would direct a local registration into user setup. The remediation owner now retains local scope, and disabled entries retain their /mcp guidance. Added both regressions. No related ownership cleanup remains.

Validation on this revision (Windows, Node 24.18.0/npm 11.16.0):

  • Two focused runs: 258 passed, 3 skipped, 2 failed across 15 files, including all 19 compiled configuration CLI tests. Both failures reproduce unchanged on main 70cd4cb: Doctor's canonical Hopper user-install fixture and Claude Desktop's directory-symlink EPERM. Neither is changed here.
  • Typecheck, lint, formatting, knip, metadata, module boundaries, architecture guards, test discovery, generated-doc/license checks and five README consistency tests passed. Pre-push check passed.
  • Native Claude linked-worktree setup/doctor/uninstall, byte-idempotence, peer preservation, drive-case alias behavior and separate Git directories passed in isolated profiles.
  • npm pack --dry-run passed. Full package verifiers, the full suite, authenticated Claude model use and Linux/macOS verification were not run for this revision.

Thank you for the Linux multi-version verification and the earlier inline fixes.

@CassieFox23

Copy link
Copy Markdown
Contributor

I reran my check on head 5d0264e. GitHub now shows no conflicts, so my old conflict note no longer applies.

  • Writer script: same output as on aa2e7c2.
  • Missing project folder: fixed in the setup path. It now fails with a clear message. The low-level finder still throws ENOENT, as you said.
  • Git pointer with a trailing space: the same clear message through setup. The finder still reports ENOENT.
  • Tests: the 2 changed files that skip setup and Doctor pass, 64 of 64.

Still not run

rea setup, rea doctor, the acceptance file, Node 22 and 26, Windows, macOS.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 24.18.0
  • Head: 5d0264e

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@IvenKooLab

Copy link
Copy Markdown
Contributor

The branch has drifted into conflicts with current main again (10 files). I test-merged and verified where a straightforward resolution ends, in case it saves you a pass:

Eight files union cleanly. The registrations/catalog layer (ClientConfigurationFiles.ts, ClientRegistrationStatus.ts, clientRegistrationStatus.test.ts, doctorRuntime.ts), Uninstall.ts and setupCommands.ts are mostly parallel additions — keep both sides, and take main's newer call shapes (state-first signatures, the publication/recovery machinery). Two spots need hand-stitching after the mechanical union: the import block in ClientConfigurationDocument.shape.test.ts (merge into one import with all four symbols) and Doctor.ts's clientRegistrations callback (keep main's resolveProviderRequestBudget spread and add this branch's workspaceDirectory spread beside it).

Two files are re-fit work, not text merges. SetupClientConfiguration.ts and SetupHost.ts interleave this branch's project-scoped paths with main's publication/recovery refactor and the Hopper installer changes in the same regions; after the union, typecheck still fails in five spots across them. The workable approach there is to start from main's version and re-apply the branch's functional diff (the claudeProjectDirectory readback/validation arguments and the host project-scope hooks), rather than resolving hunk by hunk.

I verified the union through tsc --noEmit: with the two hand-stitches above, every error is confined to those two files; everything else typechecks. No branch was pushed — the recipes are yours.

@morluto

morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

@dev-zaib thanks for the PR — this branch has merge conflicts with main. Could you merge or rebase onto the latest main and resolve them? Once it's clean and CI is green we can take another look.
cc @gensokyo-dev @dandgabr

This branch has not been deployed

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

Labels

area: cli CLI adapter and one-shot commands area: domain Domain logic, errors, and pure functions area: setup Setup, packaging, upgrade, install, Doctor, and client registration enhancement New feature or request P2: medium Medium priority issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Let setup register Claude Code for one project (--scope local)

5 participants