Skip to content

fix(claude-account): stash the displaced default login instead of adopting it - #10153

Merged
farion1231 merged 1 commit into
mainfrom
fix/claude-stash-displaced-login
Dec 1, 2026
Merged

farion1231 merged 1 commit into
mainfrom
fix/claude-stash-displaced-login

Conversation

@farion1231

Copy link
Copy Markdown
Owner

Human Note / 本人说明

用户不希望在未经他允许的下,把已经登录的账号收入到授权中心里面。尤其是 Claude、Antigravity、Codex 这三个应用。

Summary / 概述

With "switch login on card switch" enabled, switching to a card bound to another Claude account used to adopt the login sitting in the default slot as a new account in the Auth Center whenever it was not collected yet. This PR keeps that login safe without collecting it, following the Codex login-stash precedent.

开启「切卡时切换登录」后,切到绑了其他账号的官方卡时,默认槽位里原来那个没收录的号会被自动收录成新账号。现在改为放进隐藏暂存,不进授权中心,也不会丢。

  • The displaced, uncollected login is parked in <data>/claude-login-stash/<sha256(key)[..16]>/config, an ordinary account slot (own keychain entry / .credentials.json) that is not listed in claude_accounts.json and not shown in the UI.
  • The stash path is derived from the account key, so there is no index. Displacing the same account again reuses the slot; the older login goes to its backup slot.
  • If a later step fails, check_back restores the previous login from the stash and then deletes the stash (credentials and directory).
  • Startup recovery falls back to the stash when before_owner is not an account in the table.
  • Formally adding the same account later drops its stash.
  • Adopter, Ctx.adopter, DiskAccounts::adopt and the unused Outcome::Switched.adopted are removed.

Companion change for Antigravity / WorkBuddy is pushed to #10140.

Related Issue / 关联 Issue

Related to #10140

Checklist / 检查清单

  • pnpm typecheck passes / 通过 TypeScript 类型检查 (no frontend change)
  • pnpm format:check passes / 通过代码格式检查 (no frontend change)
  • cargo clippy passes (if Rust code changed) / 通过 Clippy 检查(如修改了 Rust 代码)
  • Updated i18n files if user-facing text changed / 如修改了用户可见文本,已更新国际化文件 (no user-facing text changed)

Local: cargo fmt --check, cargo clippy --all-targets -D warnings, cargo test (lib 5224 + integration 233) all pass. Tests use temp dirs and an in-memory credential store; not tested against a real keychain yet.

…pting it

With "switch login on card switch" on, switching to a card bound to another
account used to adopt the default slot's login as a new account when it was
not collected yet. It now goes into a private stash slot
(<data>/claude-login-stash/<sha256(key)[..16]>/config) that is not listed in
the account table, so a login is never collected without the user's consent
but is also not lost.

The stash location is derived from the account key, so no index is kept.
When a later step fails, check_back restores the previous login and deletes
the stash; startup recovery falls back to the stash when before_owner is not
an account; formally adding the same account later drops its stash. Adopter,
Ctx.adopter, DiskAccounts::adopt and Outcome::Switched.adopted are removed.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T02:53:58.438712Z c2f8170 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added the backend Backend (Rust/Tauri) label Dec 1, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c2f8170e97

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +52 to +54
check_out(ctx, previous, dir)?;
if layout::is_stash_dir(ctx.data_dir, dir) {
if let Err(error) = super::discard_stash(ctx, dir) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the stash until rollback finishing has completed

If restoring the stashed login commits its credentials but finish fails—for example, because Claude Code holds the default profile's configuration lock—check_out still returns success and leaves a Committed journal for recovery. Deleting the stash here removes the only profile that recover_locked can use to finish that rollback: the restored account is not in ctx.accounts, and recovery searches only the journal's target directory and the registered account directory. This can leave the restored credentials paired with the other account's profile, with recovery unable to repair it. Retain the stash until finishing succeeds, or defer deletion until recovery completes.

Useful? React with 👍 / 👎.

@farion1231
farion1231 merged commit 92d69a0 into main Dec 1, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend (Rust/Tauri)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant