Skip to content

feat: use your existing Claude Code sign-in with an isolated native Gateway - #2394

Draft
Fly-onlyone wants to merge 2 commits into
openclaw:mainfrom
Fly-onlyone:feat/share-claude-cli-with-isolated-gateway
Draft

Fly-onlyone wants to merge 2 commits into
openclaw:mainfrom
Fly-onlyone:feat/share-claude-cli-with-isolated-gateway

Conversation

@Fly-onlyone

@Fly-onlyone Fly-onlyone commented Nov 28, 2026 •

Copy link
Copy Markdown

Related: #2112

Update after review (head a85bae93). The review found that picking the Gateway's already detected Claude Code choice also ran the share step and replaced the agent account's own Claude sign-in. Fixed in a second commit: the share step now runs only for the explicit "Anthropic Claude CLI" sign-in choice, shares nothing when the agent account already has a Claude sign-in, and the agent-side step no longer overwrites one. The ownership and consent questions below are unchanged and still need a maintainer decision. No new guest run was made for this commit.

Draft: this is a design proposal. It deliberately crosses the isolated agent boundary, so it needs a maintainer decision before it is worth polishing further. The plain bug fixes for #2112 are in #2393 (fix: show why AI provider setup failed and let it be run again) and do not depend on this.

What Problem This Solves

On a native Store Gateway, the setup choice "Anthropic Claude CLI: Keep using an existing Claude Code CLI login on this host" cannot work. The Gateway runs under its own isolated agent account with its own profile and PATH, so Claude Code that is installed and signed in for the Windows user is invisible to it. The Gateway answers "Claude CLI (claude) was not found on PATH" even though the user did everything the option asks for. The only way through today is to open clawctl pwsh and install and sign in Claude Code by hand inside the agent account.

User Impact

User impact: with Claude Code installed and signed in for the Windows user, choosing "Anthropic Claude CLI" in Companion setup on an isolated native Gateway now works on the first click. Nothing changes for other providers, for a Gateway that runs as the user, when the user has no native Claude Code install with a saved sign-in, or when the agent account already has a Claude sign-in of its own.

Risks and limits that a reviewer and a user should know:

  • An existing agent sign-in is never replaced. If the agent account already has .credentials.json, nothing is shared and that account keeps its sign-in. Switching the agent to another Claude account is not offered here.
  • The agent account receives the user's Claude sign-in. Companion copies the user's .credentials.json into the agent profile. That is what "keep using an existing Claude Code CLI login" means on this Gateway, but it is a real widening of what the isolated account holds.
  • Two holders of one sign-in. Reports say Claude refresh tokens rotate. Whichever copy refreshes first may force the other side to sign in again. Not observed in testing, which covered minutes, not days.
  • No new consent text. The user's click on the option is the only consent. If this direction is accepted, a short explanation on that row is probably warranted and would need all six locales.
  • Only the native claude.exe install is found. An npm install is not shared.
  • The program is refreshed only when its size differs from the agent's copy.

Why This Change Was Made

ClaudeCliAgentBridge (new, in OpenClaw.SetupEngine) runs only when the user explicitly picks the Gateway's Claude CLI sign-in choice (anthropic-cli, or its deprecated id claude-cli) on an isolated session. It does not run for a detected claude-cli candidate, which already works on the agent's own sign-in:

  1. Find the user's claude.exe (%USERPROFILE%\.local\bin, then PATH) and .credentials.json (CLAUDE_CONFIG_DIR or %USERPROFILE%\.claude). If either is missing, do nothing.
  2. Ask clawctl status --json for the agent's shared folder, and clawctl pwsh --command for the size of the agent's copy and whether the agent already has a sign-in. If it has one, stop here.
  3. Copy the program (only when the size differs) and then the sign-in into a one-time folder in the shared folder.
  4. clawctl pwsh --command copies them into the agent account (the sign-in only if none is there): the program into the agent's %LOCALAPPDATA%\Microsoft\WindowsApps, which is already on the running Gateway's PATH, so no Gateway restart is needed. An agent without that PATH entry falls back to .local\bin, a user PATH update, and a Gateway restart.
  5. Remove the one-time folder. Leftovers of an interrupted share are swept at the start of the next one.

A failed share never blocks the choice: the Gateway then reports what it is missing, as before.

Open questions for maintainers:

  • Is Companion the right owner, or should clawctl or the Gateway offer a supported "use the host's Claude Code" operation that Companion calls? The packaging guide says the agent account owns its PATH, and this change writes into that account through clawctl pwsh.
  • Would a separate sign-in inside the agent (driving claude auth login there) be preferred over copying the user's sign-in? It avoids two holders of one token at the cost of an extra step for the user.

Evidence

Real behavior proof. Clean Hyper-V guest restored from a checkpoint, Windows 11 Pro 26H2 build 26300.9974, Gateway OpenClawFoundation.OpenClawGateway_2026.11.11081.0 from the Store (isolated session), Claude Code 2.1.332 installed and signed in for the Windows user only. Unsigned local installers. The final-build screenshots come from one build with this PR and #2393 together (installer sha256 986A70A7...2E21BE22).

Before (build without this change): Claude Code installed and signed in for the user, the Gateway still cannot see it. before
After (final build): one click on "Anthropic Claude CLI", no manual step in the agent account. after
End of setup on an earlier revision of this branch (before the review hardening listed below): "AI ready: anthropic/claude-opus-5-5". The Gateway log of that run showed three successful openclaw.setup.verify calls, each with cli turn: provider=claude-cli model=claude-opus-5-5. all set

In the run that reached "All set", the agent's shared folder afterwards contained no one-time folder and no sign-in file, and the guest event log showed no Companion crash. Those two checks were not captured for the final-build run.

Tests (ClaudeCliAgentBridgeTests): the bridge applies to the sign-in choice and never to a detected candidate; first share stages program and sign-in and leaves nothing behind; an agent that already has this program receives only the sign-in; an agent with its own sign-in keeps it and nothing is staged; restart requirement is passed on; nothing is shared and clawctl is never called without a user program or sign-in; program found on PATH and relocated config directory; a failed agent step and an interrupted earlier share both leave no sign-in in the shared folder; unusable shared-folder reports stop before any copy; PowerShell literal quoting for all four quote characters. One test runs the real agent-side scripts in Windows PowerShell against a throwaway profile and checks that the program replaces the old one, the sign-in lands in the profile, the probe then reports that sign-in, and a second agent step with another account's file leaves the first sign-in in place.

Validation at head a85bae93 (this branch alone, clean tree, Windows 11 x64):

Command Result
./build.ps1 exit 0
dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore 6180 passed, 0 failed, 28 skipped
dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore 7081 passed, 0 failed, 0 skipped
dotnet test ./tests/OpenClaw.SetupEngine.Tests/OpenClaw.SetupEngine.Tests.csproj --no-restore 2699 passed, 0 failed, 4 skipped
dotnet test ./tests/OpenClaw.Tray.UITests/OpenClaw.Tray.UITests.csproj -r win-x64 --no-restore --filter "(FullyQualifiedName~OnboardingAiPageTests|FullyQualifiedName~NativeSharedFlowTests)&<CI lane category exclusions>" 143 passed, 0 failed, 0 skipped

On the previous head 78621a9d the first Shared run had two failures that passed on a rerun of the whole suite: ExecApprovalsStoreTests.Changed_TwoOriginFilteredSubscribers_ReceiveOtherWriterExactlyOnce (IOException: exec-approvals.json in use by another process) and OpenClawGatewayClientTests.AuthenticatedSigningIdentity_ComesFromConnectNotOptionalHelloEcho(spoofEcho: False, useManagedWebSocket: False) (TimeoutException after 15 s). This branch does not touch OpenClaw.Shared. The host was under memory pressure at the time. I did not investigate them further. They did not recur on this head.

Independent review. A separate review agent read the diff and its owners. Its findings are addressed in this revision: quoting covers every character that ends a PowerShell single-quoted string, the sign-in is copied last and swept on the next share, the program is replaced by copy-then-move so a program in use keeps its old file, file probes run off the UI thread, and a failed share no longer blocks the choice.

Not verified / blocked

  • All guest screenshots above predate commit a85bae93. The keep-existing-sign-in behavior is covered by tests only, including the real PowerShell script run, not by a guest run.
  • The end-of-setup screenshot predates the review hardening. The final build was verified in the guest up to "Claude CLI auth detected" and to a successful activation, not to "All set": in that run Companion's existing finalization step (openclaw config set gateway.nodes.commands.allow ...) was refused by the Gateway CLI with "Gateway lock owner identity could not be verified. No local mutation was attempted." not ready A direct test showed the same refusal 2 times out of 10 in the first minute after a Gateway restart with no clawctl pwsh involved, so it is not caused by this change, but it does stand between this feature and a finished setup on a slow machine. It is not addressed here.
  • In the one run that reached "All set", the first automatic readiness check reported "not ready" while node pairing was settling, and "Check readiness again" then succeeded.
  • Long-term behavior of the shared sign-in (token refresh on either side).
  • The fallback path (agent without the WindowsApps PATH entry, Gateway restart) was not exercised in the guest or by the script test.
  • The page hook and the session wrapper have no dedicated test.
  • Native proof and accessibility test categories, ARM64, signed or Store Companion builds.

Required proof pools

  • windows-winui-interactive: first-run AI setup behavior changed for the Claude CLI choices. Screenshots from a clean Windows 11 guest are under Evidence.

…tive Gateway

An isolated native Gateway runs under its own agent account, so Claude Code
installed and signed in for the Windows user is invisible to it and the
"Anthropic Claude CLI" choice fails with "claude was not found on PATH".

When the user picks a Claude CLI route on an isolated Gateway, Companion now
copies the user's claude.exe and .credentials.json through a one-time folder
in the agent's shared folder and has `clawctl pwsh` place them in the agent
account, in a folder the running Gateway already has on its PATH. The
one-time folder is removed afterwards, leftovers of an interrupted share are
swept on the next one, and a failed share never blocks the choice.

Nothing is shared for other providers, for a Gateway that runs as the user,
or when the user has no native Claude Code install with a saved sign-in.

Related: openclaw#2112
@clawsweeper

clawsweeper Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P1 Urgent regression or broken agent/channel workflow affecting real users now. impact:auth-provider This issue is about auth, provider routing, model choice, or SecretRef resolution. impact:security This issue is about security boundaries, credentials, authz, sandboxing, or sensitive data. clawsweeper:intake:feature Preliminary submission classification; full source review pending. merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 28, 2026
@clawsweeper

clawsweeper Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge.

What this changes

This PR copies the Windows user's Claude Code executable and saved sign-in into an isolated native Gateway account during explicit Claude CLI setup.

Example: Claude Code 2.1.332 is installed and signed in for the Windows user, but absent from the isolated Gateway account.

  • Before: Choosing Anthropic Claude CLI reports that claude was not found on PATH.
  • After: The setup choice imports the executable and credentials before asking the Gateway to activate Claude CLI.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Relevant historical runtime evidence and reported Windows suite results support the proposal, but current proof, persisted-state compatibility, product approval, and staging cleanup remain unresolved.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Feature · Worth it: Needs a maintainer decision · Fix scope: Partial
User problem: A Windows user already signed into Claude Code cannot reuse that installation from an isolated native Gateway.
Reason: The convenience is concrete, but automatic cross-account credential import changes the isolation contract and lacks an owner decision.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep this draft open for a maintainer decision on credential sharing; the previous account-replacement finding is fixed, but a new cleanup defect remains.

Reviewed head: a85bae93a4961ecedaeffe4b490bac7c59b63ff5
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should explicit Claude CLI selection import the Windows user's reusable credentials into the isolated agent, or guide a separate agent-owned sign-in?
  • Recommendation: Keep sign-in agent-owned: Guide installation and authentication inside the isolated account through the package owner.
  • Why: Neither the existing isolation contract nor recorded discussion approves this transfer, its consent wording, or two independently refreshing copies of one sign-in.

Before merge

  • Add real behavior proof - Inspected Windows 11 guest screenshots exercise Companion setup against Store Gateway 2026.11.11081.0 and show authentication detection, but all predate a85bae9; successful completion is older still, and current credential preservation and cleanup have only test evidence. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • [P2] Sweep abandoned staging before returning for an existing sign-in (P2) - If Companion exits after the agent-side copy installs .credentials.json but before the host finally block removes staging, the next explicit share sees the installed sign-in and returns here. Both RemoveStagingFolders calls are below this return, so the abandoned shared copy survives subsequent attempts instead of being swept as promised. Perform the existing owned-staging cleanup before this early return and cover the combination of an existing agent sign-in and leftover staging credentials. This branch was added in the latest commit.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P2] [P2] Sweep abandoned staging before returning for an existing sign-in — src/OpenClaw.SetupEngine/ClaudeCliAgentBridge.cs:110-111

Tests

  • Missing end-to-end proof: Supply current-head isolated-Gateway evidence for first import, preservation of an existing agent sign-in, interrupted-transfer cleanup, and latest-stable upgrade with credentials and settings intact; redact credentials and private endpoints.
Agent review details

How this fits together

Companion's native setup session invokes the installed Gateway package's clawctl commands to provision the isolated agent profile before Gateway-owned provider activation.

flowchart LR
User[Windows user] --> Setup[Companion AI setup]
Setup --> Bridge[Claude CLI bridge]
Bridge --> Shared[Shared staging folder]
Shared --> Shell[Packaged clawctl shell]
Shell --> Agent[Isolated agent profile]
Agent --> Gateway[Gateway provider activation]
Loading

Technical review

Best possible solution:

Prefer package-owned Claude installation and agent-owned sign-in unless maintainers approve a supported credential-import contract with explicit consent and reliable staging cleanup.

Do we have a high-confidence way to reproduce the issue?

The isolated-account ownership contract and inspected failure screenshot support the host-install visibility mismatch; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The proposal explains the mismatch, but copying credentials through Companion is premature while package ownership, consent, and credential lifecycle remain undecided.

Full review comments:

  • [P2] [P2] Sweep abandoned staging before returning for an existing sign-in — src/OpenClaw.SetupEngine/ClaudeCliAgentBridge.cs:110-111
    If Companion exits after the agent-side copy installs .credentials.json but before the host finally block removes staging, the next explicit share sees the installed sign-in and returns here. Both RemoveStagingFolders calls are below this return, so the abandoned shared copy survives subsequent attempts instead of being swept as promised. Perform the existing owned-staging cleanup before this early return and cover the combination of an existing agent sign-in and leftover staging credentials. This branch was added in the latest commit.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b762c8dc12a8.

Provenance checked

  • Isolated account ownership changes intended behavior with a stated reason (5abfabb: Native onboarding moved configuration and credentials into the package's isolated agent account instead of a competing host-user profile.)
  • Provider selection changes intended behavior with a stated reason (3eed1f1: Focused onboarding selects Gateway-provided choices and verifies the exact model; this PR explicitly proposes provisioning before that selection.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Karen: Raw commit 0086a65 adds src/OpenClaw.SetupEngine/NativeGatewaySetupSession.cs:30 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0086a65c7c64; files: src/OpenClaw.SetupEngine/NativeGatewaySetupSession.cs)
  • Paul Campbell: Raw commit 5abfabb adds src/OpenClaw.SetupEngine.UI/NativeGatewaySetupHost.cs:14 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5abfabb38e12; files: src/OpenClaw.SetupEngine.UI/NativeGatewaySetupHost.cs)
  • Pedro Larroy: Raw commit f906460 adds src/OpenClaw.SetupEngine.UI/NativeGatewaySetupHost.cs:13 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: f906460f9c43; files: src/OpenClaw.SetupEngine.UI/NativeGatewaySetupHost.cs)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Patch size Production +292/-0; tests +257/-0 The growth implements a distinct cross-account provisioning feature, so its ownership decision should precede further expansion.

Labels

Label changes:

No label changes.

Label justifications:

  • merge-risk: 🚨 security-boundary: The explicit setup choice newly gives the isolated agent reusable host-account credentials.
  • merge-risk: 🚨 auth-provider: Host and agent retain independent copies of one sign-in, with refresh-token behavior unresolved.
  • merge-risk: 🚨 compatibility: The bridge writes persisted agent credentials and executable state and can change agent PATH without supplied existing-install upgrade proof.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-28T15:11:40.644Z sha 78621a9 :: needs real behavior proof before merge. :: [P1] [P1] Preserve the sign-in behind an already-detected Claude candidate

Reviewed November 28, 2026, 9:34 PM ET / November 29, 2026, 02:34 UTC (Revision 2).

…Claude Code

Picking the Gateway's already detected Claude Code candidate ran the share
step too, and the agent step always overwrote the agent account's
.credentials.json with the Windows user's. An agent signed in to another
Claude account silently lost that sign-in.

- Share only for the explicit "reuse the host's Claude Code login" sign-in
  choice, never for a detected candidate.
- Probe the agent account first and share nothing when it already has a
  Claude sign-in.
- The agent step itself no longer overwrites an existing sign-in, so a
  sign-in that appears between the probe and the copy is kept too.

Related: openclaw#2112
@Fly-onlyone

Copy link
Copy Markdown
Author

@clawsweeper re-review

Changes since the last review at 78621a9d, head is now a85bae93:

  • P1 finding fixed. The share step no longer runs for a detected claude-cli candidate, shares nothing when the agent account already has a Claude sign-in, and the agent-side step no longer overwrites an existing sign-in. Tests cover all three, including the real PowerShell script run.
  • Not changed: this is still a draft design proposal. The ownership and consent questions need a maintainer decision, and no new guest run was made for this commit.

@clawsweeper

clawsweeper Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

🦞👀

Re-review progress:

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

impact:auth-provider This issue is about auth, provider routing, model choice, or SecretRef resolution. impact:security This issue is about security boundaries, credentials, authz, sandboxing, or sensitive data. merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P1 Urgent regression or broken agent/channel workflow affecting real users now. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant