accounts: ChatGPT accounts come in from codexbar's config.json (碳碳双键)

碳碳双键 on Discord (#general): several Codex accounts switched with
codexbar on the old computer; after a magpie backup and restore the new
one had only the account Codex itself was signed in to. A backup carries
no sign-in by design (a refresh token rotates, so two computers can't
share one); importing is how accounts move. But codexbar's own store,
~/.codexbar/config.json, wasn't a shape the importer knew: its accounts
sit under providers[].accounts, so the whole file was read as one entry
with no token ("#1: failed").

codexbarEntries reads it as codexbar (lizhelang/codexbar 9f2e0f53)
writes it (CodexBarConfig.swift, CodexBarConfigStore): the accounts of
the provider of kind openai_oauth and openAI.remoteConnectionAccounts,
camelCase tokens, the workspace from openAIAccountId (its id is
codexbar's own). api_key accounts are said to be keys; other providers
(API endpoints of other vendors) are left alone; a sign-in in both places
is read once. codexbar signs in with Codex's own OAuth client, so the
refresh works as for Codex's auth.json. Its own export (Sub2API's shape)
was already read.

The import window's texts (en, zh, zh-TW, ja, de), the CLI's warning and
the docs name codexbar; reference.md says a backup carries no sign-in and
that importing the old computer's file is how accounts move.

Run:
- TestImportCodexbarConfig, fixture in codexbar's encoder output (pretty,
  sorted keys, ISO dates; two Team seats, a duplicate remote account, an
  access-only account, a DeepSeek api_key provider): fails on the old code
  ("got #1:failed"), passes on the new; seats kept apart by
  openAIAccountId with an id token that doesn't name the workspace.
- Built nogui binary, sandbox HOME: `magpie accounts import codex
  config.json --yes` lists the three accounts, ChatGPT refusing the fake
  tokens; no real codexbar install here to try with real accounts.
- login-import.test.cjs (chromium, webkit; en, zh) and i18n-keys.test.cjs
  pass.
- go test -tags nogui ./... (temp HOME, pinned caches): all ok.
- go vet (darwin, GOOS=linux, GOOS=windows) on . and internal/provider;
  gofmt -l clean.
This commit is contained in:
yetone
2026-10-10 15:04:23 +08:00
parent 494dedcf8f
commit a154197bbb
8 changed files with 289 additions and 35 deletions
+4 -3
View File
@@ -452,8 +452,9 @@ const importUsage = "usage: magpie accounts import <codex|claude|antigravity|fac
// importAccounts: `magpie accounts import <agent> <file>... [--yes]` brings
// in accounts from other tools' files, as the window's "Import accounts from
// a file…" does (#1453): Codex's auth.json, Cockpit Tools', CLIProxyAPI's
// and Sub2API's exports for ChatGPT; Claude Code's .credentials.json and
// a file…" does (#1453): Codex's auth.json, codexbar's config.json, and
// Cockpit Tools', CLIProxyAPI's and Sub2API's exports for ChatGPT; Claude
// Code's .credentials.json and
// CLIProxyAPI's for Claude; Antigravity Cockpit's, Antigravity Manager's
// and CLIProxyAPI's for Antigravity; Factory API keys. The files are only
// read. What importing does to the tool the file came from is said first,
@@ -510,7 +511,7 @@ func importAccounts(args []string) error {
switch id {
case "codex":
say = []string{"Each account's sign-in is refreshed with ChatGPT before it is added, as signing in does.",
"That spends the file's sign-in: the tool it came from (Codex CLI on another computer, Cockpit Tools, CLIProxyAPI) is signed out of that account and has to sign in again. From then on the account is magpie's.",
"That spends the file's sign-in: the tool it came from (Codex CLI on another computer, codexbar, Cockpit Tools, CLIProxyAPI) is signed out of that account and has to sign in again. From then on the account is magpie's.",
"The files are only read, never changed. An account magpie holds already is left as it is."}
case "claude":
say = []string{provider.ClaudeRisk,
+9 -6
View File
@@ -1133,12 +1133,15 @@ adding one; use an account you can afford to lose.
Accounts signed in elsewhere can be imported from their files instead of
signed in again: *Import accounts from a file…* under a subscription's
accounts, or `magpie accounts import <codex|claude|antigravity|factory>
<file>... [--yes]`. For ChatGPT that takes Codex's `auth.json` and the
exports of Cockpit Tools, CLIProxyAPI and Sub2API, as many files as you
like. Each ChatGPT sign-in is refreshed before it is added, which checks
it and makes magpie its only holder: the tool the file came from (Codex on
another computer, Cockpit Tools, CLIProxyAPI) is signed out of that
account and has to sign in again. The files are only read. An account
<file>... [--yes]`. For ChatGPT that takes Codex's `auth.json`, codexbar's
`~/.codexbar/config.json` (every ChatGPT account it switches between) and
the exports of Cockpit Tools, CLIProxyAPI and Sub2API, as many files as
you like. Each ChatGPT sign-in is refreshed before it is added, which
checks it and makes magpie its only holder: the tool the file came from
(Codex on another computer, codexbar, Cockpit Tools, CLIProxyAPI) is
signed out of that account and has to sign in again. A backup carries no
sign-in, so this is also how accounts move to a new computer: import the
file from the old one there. The files are only read. An account
magpie has already is left as it is, two Team seats of one email stay two
accounts, and an entry with only an access token (a ChatGPT web session)
is refused, since it would stop working within days with nothing to renew
+2 -2
View File
@@ -25,7 +25,7 @@ keys and accounts per request is in [Gateway routing and fallback](gateway-routi
| Token refresh | Each account refreshes through its vendor. For example, `codexToken` refreshes within 5 minutes of expiry and writes the rotated tokens back into `~/.codex/auth.json` for Codex CLI. A 400 or 401 from the vendor's refresh endpoint means it was refused (`refreshFailed`). | [`account.go`](../../internal/provider/account.go) |
| Saved accounts | `logins.json` remembers every Codex and Claude Code account seen signed in. A switch moves the credentials into the agent's own store and saves the ones it replaces. A saved account that is on (`SetLoginOn`) stands behind the agent's own. Its tokens stay in `logins.json`. | [`logins.go`](../../internal/provider/logins.go), [`logins_on.go`](../../internal/provider/logins_on.go) |
| Sign-in in magpie | `StartSignIn` runs the vendor's own browser OAuth with its client and takes the tokens at a callback on this machine. A browser that can't reach that callback (magpie on a server or in Docker) ends on a page that won't load; its address, pasted (`SubmitSignInCallback`), goes through the same callback handler (`pastedCallback`). A plugin's browser sign-in (`auto`) whose page names a port on this machine to come back to takes its pasted address too: magpie opens it there on 127.0.0.1, for the plugin's own listener (`pluginCallback`, `loopbackPorts`); Command Code's page posts its key from script, so it offers the API key way instead. A Claude account is signed in by Claude Code itself. Signing in brings back an account removed from magpie (`ShowAccount`). A sign-in started in magpie (`StartSignIn`, `StartPluginSignIn`) reads as done (`SignInStatus`, `WaitSignIn`) only after `finish` has run `ShowAccount` for its account, so the window, which opens the account as soon as it sees done, finds it listed. If providers.json can't be written then, the account stays hidden and the sign-in still ends done. Signing in to a plugin's provider from the command line (`pluginLogin`, with a key or the browser) brings it back too. It also takes off the mark a sign-in its vendor turned away left on the account (`Lapsed`) and shows again the agent's own account removed in magpie (`clearPluginLapse`). The window's plugin sign-in does the same with the browser (`pluginDone`, then `finish`) or with a key (`PluginAPIKey`); a key and the command line share these steps in `PluginSignedIn`. | [`signin.go`](../../internal/provider/signin.go), [`claude_signin.go`](../../internal/provider/claude_signin.go), [`pluginsignin.go`](../../internal/provider/pluginsignin.go), [`pluginsignin_paste.go`](../../internal/provider/pluginsignin_paste.go), [`plugins_cli.go`](../../plugins_cli.go) |
| Import from files | `ImportLogins` (ChatGPT, Claude), `ImportGoogleAccounts` (Antigravity) and `ImportFactoryKeys` take other tools' files, from the window (`signin/import`) or `magpie accounts import` (#1453). ChatGPT reads Codex's `auth.json`, CLIProxyAPI's and Cockpit Tools' files and Sub2API's export (`sub2apiEntry`). Each ChatGPT and Google sign-in is refreshed before it is added, so the tool the file came from is signed out of it; both surfaces say so first, and the command imports nothing without `--yes` or a yes. Claude's are kept as the file has them. A refresh token magpie holds already is `exists`, never refreshed; accounts are matched by email and workspace (`sameLogin`). An entry with an access token and no refresh token is refused (`accessOnly`). One file of several that holds no account is a failed row with its place (`ImportedAccount.File`), never skipped. The files are only read. | [`login_import.go`](../../internal/provider/login_import.go), [`google_import.go`](../../internal/provider/google_import.go), [`factory_key.go`](../../internal/provider/factory_key.go), [`accounts_cli.go`](../../accounts_cli.go) |
| Import from files | `ImportLogins` (ChatGPT, Claude), `ImportGoogleAccounts` (Antigravity) and `ImportFactoryKeys` take other tools' files, from the window (`signin/import`) or `magpie accounts import` (#1453). ChatGPT reads Codex's `auth.json`, CLIProxyAPI's and Cockpit Tools' files, Sub2API's export (`sub2apiEntry`) and codexbar's `~/.codexbar/config.json` (`codexbarEntries`: the `openai_oauth` provider's accounts and `openAI.remoteConnectionAccounts`, the workspace from `openAIAccountId`). Each ChatGPT and Google sign-in is refreshed before it is added, so the tool the file came from is signed out of it; both surfaces say so first, and the command imports nothing without `--yes` or a yes. Claude's are kept as the file has them. A refresh token magpie holds already is `exists`, never refreshed; accounts are matched by email and workspace (`sameLogin`). An entry with an access token and no refresh token is refused (`accessOnly`). One file of several that holds no account is a failed row with its place (`ImportedAccount.File`), never skipped. The files are only read. | [`login_import.go`](../../internal/provider/login_import.go), [`google_import.go`](../../internal/provider/google_import.go), [`factory_key.go`](../../internal/provider/factory_key.go), [`accounts_cli.go`](../../accounts_cli.go) |
| Used-up switch | When the account Codex or Claude Code is signed in to has used its allowance, the agent is signed in to the next account that is on and has room (#208). | [`codex_switch.go`](../../internal/provider/codex_switch.go) |
| Routing groups | User-made groups from the Routing view, and auto-found groups of the same model across providers (derived, never stored). Members are `provider/model[:effort]`. A group can nest another (`group/<id>`); `SaveGroup` refuses loops. `Match` takes a glob or `re:` pattern (#766). A found group follows its providers: one switched off or removed leaves it, and one on again is back. A found group the user changed (an `auto-…` id stored) is read without the members of providers magpie no longer has (`withoutRemoved`, not written back, so a provider back under its id is back in it), except a manual group's pick, a rule's model, or all of them when none would be left. A switched-off provider's members stay in it, skipped by `membersIn`, and the Routing page says them as switched off (`memberJSON.providerOff`). The user's own groups keep their members. | [`group.go`](../../internal/provider/group.go) |
| Allowance | `Quotas` asks every vendor at once: subscription windows (`SubscriptionUsage`), key-bought plans (`PlanQuotas`) and key balances (`KeyBalances`). The Usage page, `magpie quota --json` and `GET /v1/magpie/quotas` read it. A single card can be read again on its own (#840). A remote magpie's cards come from what it has kept (`CachedCards`, `GET /v1/magpie/quotas/cards`) and are never read there for this computer except by a card's refresh (`POST /v1/magpie/quotas/refresh`, throttled per card). What it has kept is the Usage page's cards with the readings made behind the requests since laid over them, a later one over an earlier by `readSeq` (`cards_kept.go`): each account's `LoginUsage` reading (the used-up switch, the Codex warm-up, routing's `Allowances`), and each key's `KeyAllowance` windows on its plan or balance card. An account or key read that way and never on the page gets a card from that reading, and after a restart, before either is read again, the cards come from `quotas.json`, dated (`AsOf`). A magpie serving only other magpies has nobody on its page (#1313). Cursor, Grok and a Kiro key keep the page's cards only. | [`cards_kept.go`](../../internal/provider/cards_kept.go), [`quotas.go`](../../internal/provider/quotas.go), [`subscription_usage.go`](../../internal/provider/subscription_usage.go), [`planquota.go`](../../internal/provider/planquota.go), [`balance.go`](../../internal/provider/balance.go), [`quota_refresh.go`](../../internal/provider/quota_refresh.go), [`remote_quotas.go`](../../internal/provider/remote_quotas.go) |
@@ -108,7 +108,7 @@ no decision model was discovered (`Test` in
## Verification
```sh
go test -tags nogui ./internal/provider -run 'TestAccount|TestCodex|TestGroup|TestQuota|TestLogin|TestSignIn|TestSeveralKeys|TestKeyProtocol|TestSetKeyWeight|TestReadSub2APIKeyLimits|TestSub2APIKeyLimitsOnItsCard|TestKeyAllowance|TestPlanKeyAllowance|TestPayAsYouGoKeyAskedSeldom|TestClaudeAccountToldRenewed|TestPluginAccountToldRenewed'
go test -tags nogui ./internal/provider -run 'TestAccount|TestImport|TestCodex|TestGroup|TestQuota|TestLogin|TestSignIn|TestSeveralKeys|TestKeyProtocol|TestSetKeyWeight|TestReadSub2APIKeyLimits|TestSub2APIKeyLimitsOnItsCard|TestKeyAllowance|TestPlanKeyAllowance|TestPayAsYouGoKeyAskedSeldom|TestClaudeAccountToldRenewed|TestPluginAccountToldRenewed'
go test -tags nogui ./internal/provider -run 'TestCapHeld|TestCapReached|TestWindowCapHeld|TestSetWindowCap'
go test -tags nogui . -run TestAccountCapCmd
node --test internal/gui/tests/account-cap.test.cjs internal/gui/tests/window-cap.test.cjs
+6 -5
View File
@@ -10338,12 +10338,13 @@ function importSay(agent) {
};
}
if (agent === "codex") {
// Cockpit Tools exports in its own shape (CLIProxyAPI's), Codex's
// auth.json, CPA and Sub2API: all read (login_import.go)
// codexbar's config.json; Cockpit Tools exports in its own shape
// (CLIProxyAPI's), Codex's auth.json, CPA and Sub2API: all read
// (login_import.go)
return {
from: t("Bring in accounts from Codex's auth.json, or exports from Cockpit Tools, CLIProxyAPI or Sub2API"),
intro: t("Choose or paste one or more files: Codex's auth.json, or an export from Cockpit Tools, CLIProxyAPI or Sub2API. Each account's sign-in is refreshed with ChatGPT before it is added."),
spent: t("This takes the sign-in over: the tool the file came from (Codex on another computer, Cockpit Tools, CLIProxyAPI) is signed out of that account and has to sign in again. The file itself is only read."),
from: t("Bring in accounts from Codex's auth.json, codexbar's config.json, or exports from Cockpit Tools, CLIProxyAPI or Sub2API"),
intro: t("Choose or paste one or more files: Codex's auth.json, codexbar's config.json (in ~/.codexbar), or an export from Cockpit Tools, CLIProxyAPI or Sub2API. Each account's sign-in is refreshed with ChatGPT before it is added."),
spent: t("This takes the sign-in over: the tool the file came from (Codex on another computer, codexbar, Cockpit Tools, CLIProxyAPI) is signed out of that account and has to sign in again. The file itself is only read."),
checking: t("Checking the accounts with {vendor}…", { vendor: "ChatGPT" }),
checks: t("Each account's sign-in is refreshed and its account looked up, as signing in does."),
};
+12 -12
View File
@@ -1350,9 +1350,9 @@ const I18N = {
"{name} is too big to be an export": "{name} 太大,不像是导出文件",
"Checking the accounts with Google…": "正在向 Google 验证账号…",
"Bring in accounts from CLIProxyAPI's auth files or {own}": "导入 CLIProxyAPI 的认证文件或 {own} 里的账号",
"Bring in accounts from Codex's auth.json, or exports from Cockpit Tools, CLIProxyAPI or Sub2API": "导入 Codex 的 auth.json,或 Cockpit Tools、CLIProxyAPI、Sub2API 导出的账号",
"Choose or paste one or more files: Codex's auth.json, or an export from Cockpit Tools, CLIProxyAPI or Sub2API. Each account's sign-in is refreshed with ChatGPT before it is added.": "选择或粘贴一个或多个文件:Codex 的 auth.json,或 Cockpit Tools、CLIProxyAPI、Sub2API 的导出文件。每个账号先向 ChatGPT 刷新登录再添加。",
"This takes the sign-in over: the tool the file came from (Codex on another computer, Cockpit Tools, CLIProxyAPI) is signed out of that account and has to sign in again. The file itself is only read.": "导入会接管这个登录:文件原来所在的工具(另一台电脑上的 Codex、Cockpit Tools、CLIProxyAPI)会退出该账号,需要重新登录。文件本身只读取,不会改动。",
"Bring in accounts from Codex's auth.json, codexbar's config.json, or exports from Cockpit Tools, CLIProxyAPI or Sub2API": "导入 Codex 的 auth.json、codexbar 的 config.json,或 Cockpit Tools、CLIProxyAPI、Sub2API 导出的账号",
"Choose or paste one or more files: Codex's auth.json, codexbar's config.json (in ~/.codexbar), or an export from Cockpit Tools, CLIProxyAPI or Sub2API. Each account's sign-in is refreshed with ChatGPT before it is added.": "选择或粘贴一个或多个文件:Codex 的 auth.json、codexbar 的 config.json(位于 ~/.codexbar),或 Cockpit Tools、CLIProxyAPI、Sub2API 的导出文件。每个账号先向 ChatGPT 刷新登录再添加。",
"This takes the sign-in over: the tool the file came from (Codex on another computer, codexbar, Cockpit Tools, CLIProxyAPI) is signed out of that account and has to sign in again. The file itself is only read.": "导入会接管这个登录:文件原来所在的工具(另一台电脑上的 Codex、codexbar、Cockpit Tools、CLIProxyAPI)会退出该账号,需要重新登录。文件本身只读取,不会改动。",
"Choose or paste CLIProxyAPI's auth files (JSON) or {own}. Each account is kept as the file has it.": "选择或粘贴 CLIProxyAPI 的认证文件(JSON)或 {own}。每个账号按文件原样保存。",
"Claude Code renews the sign-in the first time it uses it, and the file's copy then stops working: the tool it came from has to sign in again.": "Claude Code 第一次使用时会续期这个登录,之后文件里的那份就失效了:原工具需要重新登录。",
"Adding the accounts…": "正在添加账号…",
@@ -5286,9 +5286,9 @@ const I18N = {
"{name} is too big to be an export": "{name} 太大,不像是匯出檔案",
"Checking the accounts with Google…": "正在向 Google 驗證帳號…",
"Bring in accounts from CLIProxyAPI's auth files or {own}": "匯入 CLIProxyAPI 的認證檔案或 {own} 裡的帳號",
"Bring in accounts from Codex's auth.json, or exports from Cockpit Tools, CLIProxyAPI or Sub2API": "匯入 Codex 的 auth.json,或 Cockpit Tools、CLIProxyAPI、Sub2API 匯出的帳號",
"Choose or paste one or more files: Codex's auth.json, or an export from Cockpit Tools, CLIProxyAPI or Sub2API. Each account's sign-in is refreshed with ChatGPT before it is added.": "選擇或貼上一個或多個檔案:Codex 的 auth.json,或 Cockpit Tools、CLIProxyAPI、Sub2API 的匯出檔案。每個帳號先向 ChatGPT 重新整理登入再新增。",
"This takes the sign-in over: the tool the file came from (Codex on another computer, Cockpit Tools, CLIProxyAPI) is signed out of that account and has to sign in again. The file itself is only read.": "匯入會接管這個登入:檔案原本所在的工具(另一台電腦上的 Codex、Cockpit Tools、CLIProxyAPI)會登出該帳號,需要重新登入。檔案本身只會讀取,不會變更。",
"Bring in accounts from Codex's auth.json, codexbar's config.json, or exports from Cockpit Tools, CLIProxyAPI or Sub2API": "匯入 Codex 的 auth.json、codexbar 的 config.json,或 Cockpit Tools、CLIProxyAPI、Sub2API 匯出的帳號",
"Choose or paste one or more files: Codex's auth.json, codexbar's config.json (in ~/.codexbar), or an export from Cockpit Tools, CLIProxyAPI or Sub2API. Each account's sign-in is refreshed with ChatGPT before it is added.": "選擇或貼上一個或多個檔案:Codex 的 auth.json、codexbar 的 config.json(位於 ~/.codexbar),或 Cockpit Tools、CLIProxyAPI、Sub2API 的匯出檔案。每個帳號先向 ChatGPT 重新整理登入再新增。",
"This takes the sign-in over: the tool the file came from (Codex on another computer, codexbar, Cockpit Tools, CLIProxyAPI) is signed out of that account and has to sign in again. The file itself is only read.": "匯入會接管這個登入:檔案原本所在的工具(另一台電腦上的 Codex、codexbar、Cockpit Tools、CLIProxyAPI)會登出該帳號,需要重新登入。檔案本身只會讀取,不會變更。",
"Choose or paste CLIProxyAPI's auth files (JSON) or {own}. Each account is kept as the file has it.": "選擇或貼上 CLIProxyAPI 的認證檔案(JSON)或 {own}。每個帳號依檔案原樣儲存。",
"Claude Code renews the sign-in the first time it uses it, and the file's copy then stops working: the tool it came from has to sign in again.": "Claude Code 第一次使用時會續期這個登入,之後檔案裡的那份就失效了:原工具需要重新登入。",
"Adding the accounts…": "正在新增帳號…",
@@ -9198,9 +9198,9 @@ const I18N = {
"{name} is too big to be an export": "{name} はエクスポートとしては大きすぎます",
"Checking the accounts with Google…": "Google でアカウントを確認中…",
"Bring in accounts from CLIProxyAPI's auth files or {own}": "CLIProxyAPI の認証ファイルまたは {own} からアカウントを取り込みます",
"Bring in accounts from Codex's auth.json, or exports from Cockpit Tools, CLIProxyAPI or Sub2API": "Codex の auth.json、または Cockpit Tools・CLIProxyAPI・Sub2API のエクスポートからアカウントを取り込みます",
"Choose or paste one or more files: Codex's auth.json, or an export from Cockpit Tools, CLIProxyAPI or Sub2API. Each account's sign-in is refreshed with ChatGPT before it is added.": "1 つ以上のファイルを選択するか貼り付けてください:Codex の auth.json、または Cockpit Tools・CLIProxyAPI・Sub2API のエクスポート。各アカウントのサインインは追加前に ChatGPT で更新されます。",
"This takes the sign-in over: the tool the file came from (Codex on another computer, Cockpit Tools, CLIProxyAPI) is signed out of that account and has to sign in again. The file itself is only read.": "取り込むとサインインを引き継ぎます:ファイルの元のツール(別のコンピューターの Codex、Cockpit Tools、CLIProxyAPI)はそのアカウントからサインアウトされ、もう一度サインインが必要です。ファイル自体は読み取るだけで、変更しません。",
"Bring in accounts from Codex's auth.json, codexbar's config.json, or exports from Cockpit Tools, CLIProxyAPI or Sub2API": "Codex の auth.json、codexbar の config.json、または Cockpit Tools・CLIProxyAPI・Sub2API のエクスポートからアカウントを取り込みます",
"Choose or paste one or more files: Codex's auth.json, codexbar's config.json (in ~/.codexbar), or an export from Cockpit Tools, CLIProxyAPI or Sub2API. Each account's sign-in is refreshed with ChatGPT before it is added.": "1 つ以上のファイルを選択するか貼り付けてください:Codex の auth.json、codexbar の config.json(~/.codexbar 内)、または Cockpit Tools・CLIProxyAPI・Sub2API のエクスポート。各アカウントのサインインは追加前に ChatGPT で更新されます。",
"This takes the sign-in over: the tool the file came from (Codex on another computer, codexbar, Cockpit Tools, CLIProxyAPI) is signed out of that account and has to sign in again. The file itself is only read.": "取り込むとサインインを引き継ぎます:ファイルの元のツール(別のコンピューターの Codex、codexbar、Cockpit Tools、CLIProxyAPI)はそのアカウントからサインアウトされ、もう一度サインインが必要です。ファイル自体は読み取るだけで、変更しません。",
"Choose or paste CLIProxyAPI's auth files (JSON) or {own}. Each account is kept as the file has it.": "CLIProxyAPI の認証ファイル(JSON)または {own} を選択するか貼り付けてください。各アカウントはファイルのまま保存されます。",
"Claude Code renews the sign-in the first time it uses it, and the file's copy then stops working: the tool it came from has to sign in again.": "Claude Code は最初に使うときにサインインを更新し、その後ファイルのコピーは使えなくなります。元のツールではもう一度サインインが必要です。",
"Adding the accounts…": "アカウントを追加中…",
@@ -13129,9 +13129,9 @@ const I18N = {
"{name} is too big to be an export": "{name} ist zu groß für einen Export",
"Checking the accounts with Google…": "Konten werden bei Google geprüft…",
"Bring in accounts from CLIProxyAPI's auth files or {own}": "Konten aus den Auth-Dateien von CLIProxyAPI oder {own} übernehmen",
"Bring in accounts from Codex's auth.json, or exports from Cockpit Tools, CLIProxyAPI or Sub2API": "Konten aus Codex' auth.json oder aus Exporten von Cockpit Tools, CLIProxyAPI oder Sub2API übernehmen",
"Choose or paste one or more files: Codex's auth.json, or an export from Cockpit Tools, CLIProxyAPI or Sub2API. Each account's sign-in is refreshed with ChatGPT before it is added.": "Wählen Sie eine oder mehrere Dateien aus oder fügen Sie sie ein: Codex' auth.json oder einen Export von Cockpit Tools, CLIProxyAPI oder Sub2API. Die Anmeldung jedes Kontos wird vor dem Hinzufügen bei ChatGPT aktualisiert.",
"This takes the sign-in over: the tool the file came from (Codex on another computer, Cockpit Tools, CLIProxyAPI) is signed out of that account and has to sign in again. The file itself is only read.": "Damit wird die Anmeldung übernommen: Das Tool, aus dem die Datei stammt (Codex auf einem anderen Computer, Cockpit Tools, CLIProxyAPI), wird von diesem Konto abgemeldet und muss sich erneut anmelden. Die Datei selbst wird nur gelesen.",
"Bring in accounts from Codex's auth.json, codexbar's config.json, or exports from Cockpit Tools, CLIProxyAPI or Sub2API": "Konten aus Codex' auth.json, die config.json von codexbar oder aus Exporten von Cockpit Tools, CLIProxyAPI oder Sub2API übernehmen",
"Choose or paste one or more files: Codex's auth.json, codexbar's config.json (in ~/.codexbar), or an export from Cockpit Tools, CLIProxyAPI or Sub2API. Each account's sign-in is refreshed with ChatGPT before it is added.": "Wählen Sie eine oder mehrere Dateien aus oder fügen Sie sie ein: Codex' auth.json, die config.json von codexbar (in ~/.codexbar) oder einen Export von Cockpit Tools, CLIProxyAPI oder Sub2API. Die Anmeldung jedes Kontos wird vor dem Hinzufügen bei ChatGPT aktualisiert.",
"This takes the sign-in over: the tool the file came from (Codex on another computer, codexbar, Cockpit Tools, CLIProxyAPI) is signed out of that account and has to sign in again. The file itself is only read.": "Damit wird die Anmeldung übernommen: Das Tool, aus dem die Datei stammt (Codex auf einem anderen Computer, codexbar, Cockpit Tools, CLIProxyAPI), wird von diesem Konto abgemeldet und muss sich erneut anmelden. Die Datei selbst wird nur gelesen.",
"Choose or paste CLIProxyAPI's auth files (JSON) or {own}. Each account is kept as the file has it.": "Wählen Sie die Auth-Dateien von CLIProxyAPI (JSON) oder {own} aus oder fügen Sie sie ein. Jedes Konto wird so übernommen, wie es in der Datei steht.",
"Claude Code renews the sign-in the first time it uses it, and the file's copy then stops working: the tool it came from has to sign in again.": "Claude Code erneuert die Anmeldung beim ersten Gebrauch, danach funktioniert die Kopie in der Datei nicht mehr: Das Ursprungs-Tool muss sich erneut anmelden.",
"Adding the accounts…": "Konten werden hinzugefügt…",
+5 -5
View File
@@ -55,8 +55,8 @@ function serve(lang, posted) {
}
const want = {
en: { imp: "Import accounts from a file…", instead: "Import from a file instead…", title: "Import ChatGPT accounts", intro: /Codex's auth\.json, or an export from Cockpit Tools, CLIProxyAPI or Sub2API/, spent: /signed out of that account.*only read/, checking: "Checking the accounts with ChatGPT…", done: ["Added", "Already in magpie", "Not added", "Not added"], pasted: "The pasted text" },
zh: { imp: null, instead: null, title: null, intro: /Cockpit Tools.*Sub2API/, spent: /退出该账号/, checking: null, done: null, pasted: "粘贴的内容" },
en: { imp: "Import accounts from a file…", instead: "Import from a file instead…", title: "Import ChatGPT accounts", intro: /Codex's auth\.json, codexbar's config\.json \(in ~\/\.codexbar\), or an export from Cockpit Tools, CLIProxyAPI or Sub2API/, spent: /signed out of that account.*only read/, checking: "Checking the accounts with ChatGPT…", done: ["Added", "Already in magpie", "Not added", "Not added"], pasted: "The pasted text" },
zh: { imp: null, instead: null, title: null, intro: /codexbar 的 config\.json.*Cockpit Tools.*Sub2API/, spent: /退出该账号/, checking: null, done: null, pasted: "粘贴的内容" },
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
@@ -89,9 +89,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
if (lang === "zh") {
// every new string has its Chinese
for (const s of ["Import from a file instead…", "Checking the accounts with {vendor}…",
"Bring in accounts from Codex's auth.json, or exports from Cockpit Tools, CLIProxyAPI or Sub2API",
"Choose or paste one or more files: Codex's auth.json, or an export from Cockpit Tools, CLIProxyAPI or Sub2API. Each account's sign-in is refreshed with ChatGPT before it is added.",
"This takes the sign-in over: the tool the file came from (Codex on another computer, Cockpit Tools, CLIProxyAPI) is signed out of that account and has to sign in again. The file itself is only read.",
"Bring in accounts from Codex's auth.json, codexbar's config.json, or exports from Cockpit Tools, CLIProxyAPI or Sub2API",
"Choose or paste one or more files: Codex's auth.json, codexbar's config.json (in ~/.codexbar), or an export from Cockpit Tools, CLIProxyAPI or Sub2API. Each account's sign-in is refreshed with ChatGPT before it is added.",
"This takes the sign-in over: the tool the file came from (Codex on another computer, codexbar, Cockpit Tools, CLIProxyAPI) is signed out of that account and has to sign in again. The file itself is only read.",
"The pasted text",
"Each account's sign-in is refreshed and its account looked up, as signing in does."]) {
assert.notEqual(await T(s), s, "no Chinese for: " + s);
+61 -2
View File
@@ -8,8 +8,10 @@ package provider
// ({claudeAiOauth: {…}}), and Sub2API as {accounts: [{platform, type:
// "oauth", credentials: {…}}]}. Cockpit Tools (jlcodes99/cockpit-tools)
// exports its Codex accounts in these shapes: its own (CLIProxyAPI's),
// Codex's auth.json, CPA and Sub2API. A bare refresh token a line is taken
// too. They all sign in with the agents' own OAuth clients, the ones
// Codex's auth.json, CPA and Sub2API. codexbar (lizhelang/codexbar), a
// menu-bar switcher, keeps its ChatGPT accounts in ~/.codexbar/config.json
// (see codexbarEntries); its own export is Sub2API's. A bare refresh token
// a line is taken too. They all sign in with the agents' own OAuth clients, the ones
// magpie uses.
//
// A ChatGPT one is checked the way a sign-in is finished: its refresh token
@@ -67,6 +69,10 @@ func parseLoginImport(agent, data string) ([]loginImport, error) {
out = append(out, sub2apiEntry(agent, x, c))
return
}
if es, ok := codexbarEntries(agent, x); ok {
out = append(out, es...)
return
}
if as, ok := x["accounts"].([]any); ok && jsonStr(x, "refresh_token", "refreshToken") == "" {
walk(as)
return
@@ -139,6 +145,59 @@ func loginEntry(agent string, x map[string]any) loginImport {
return e
}
// codexbarEntries reads codexbar's config.json, as its CodexBarConfigStore
// writes it: {version, active, openAI: {remoteConnectionAccounts: […]},
// providers: [{id, kind, accounts: […]}]}. The ChatGPT sign-ins are the
// accounts of the provider of kind "openai_oauth" and the remote
// connection's, each {id, kind: "oauth_tokens" or "api_key", email,
// openAIAccountId, accessToken, refreshToken, idToken, …}: the account's
// workspace is openAIAccountId, its id is codexbar's own. The other
// providers are other vendors' API endpoints, not accounts, and are left
// alone. A sign-in in both places is read once.
func codexbarEntries(agent string, x map[string]any) ([]loginImport, bool) {
ps, ok := x["providers"].([]any)
if !ok {
return nil, false
}
var accts []any
for _, p := range ps {
if p, ok := p.(map[string]any); ok && jsonStr(p, "kind") == "openai_oauth" {
as, _ := p["accounts"].([]any)
accts = append(accts, as...)
}
}
if o, ok := x["openAI"].(map[string]any); ok {
as, _ := o["remoteConnectionAccounts"].([]any)
accts = append(accts, as...)
}
var out []loginImport
seen := map[string]bool{}
for _, a := range accts {
a, ok := a.(map[string]any)
if !ok {
continue
}
e := loginImport{email: jsonStr(a, "email"), idToken: jsonStr(a, "idToken"), accessToken: jsonStr(a, "accessToken"),
refreshToken: jsonStr(a, "refreshToken"), accountID: jsonStr(a, "openAIAccountId")}
if e.refreshToken != "" {
if seen[e.refreshToken] {
continue
}
seen[e.refreshToken] = true
}
switch {
case agent != "codex":
e.err = "a ChatGPT account, not Claude's"
case jsonStr(a, "kind") == "api_key":
e.err = "an API key, not a sign-in; add it as a key instead"
case e.refreshToken == "" && e.accessToken != "":
e.err = accessOnly
}
out = append(out, e)
}
return out, true
}
// accessOnly: an account with an access token and no refresh token (a
// ChatGPT web session, an access-token export) works for days at most and
// can't be renewed, so it isn't kept as an account that would just stop.
@@ -0,0 +1,190 @@
package provider
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"sync"
"testing"
"time"
)
// codexbarConfig is ~/.codexbar/config.json as codexbar (lizhelang/codexbar
// 9f2e0f53) writes it: JSONEncoder, prettyPrinted and sortedKeys, dates in
// ISO 8601, nil fields left out. Two seats of one email in the OAuth
// provider, the remote connection holding one of them again, an account
// with no refresh token, and an API-compatible provider with a key.
const codexbarConfig = `{
"active" : {
"accountId" : "user-a__acct-a",
"providerId" : "openai-oauth"
},
"global" : {
"defaultModel" : "gpt-5.5",
"reviewModel" : "gpt-5.5"
},
"openAI" : {
"accountOrder" : [
"user-a__acct-a",
"user-b__acct-b"
],
"remoteConnectionAccountID" : "user-a__acct-a",
"remoteConnectionAccounts" : [
{
"accessToken" : "y",
"email" : "team@example.com",
"id" : "user-a__acct-a",
"idToken" : "x",
"kind" : "oauth_tokens",
"label" : "team@example.com",
"openAIAccountId" : "acct-a",
"refreshToken" : "r-a"
}
]
},
"providers" : [
{
"accounts" : [
{
"accessToken" : "y",
"addedAt" : "2026-09-30T08:12:44Z",
"email" : "team@example.com",
"expiresAt" : "2026-10-10T08:12:44Z",
"id" : "user-a__acct-a",
"idToken" : "x",
"kind" : "oauth_tokens",
"label" : "team@example.com",
"lastRefresh" : "2026-10-09T08:12:44Z",
"oauthClientID" : "app_EMoamEEZ73f0CkXaXp7hrann",
"openAIAccountId" : "acct-a",
"planType" : "team",
"refreshToken" : "r-a"
},
{
"accessToken" : "y",
"email" : "team@example.com",
"id" : "user-b__acct-b",
"idToken" : "x",
"kind" : "oauth_tokens",
"label" : "team@example.com",
"openAIAccountId" : "acct-b",
"refreshToken" : "r-b"
},
{
"accessToken" : "y",
"email" : "session@example.com",
"id" : "user-c__acct-c",
"kind" : "oauth_tokens",
"label" : "session@example.com",
"openAIAccountId" : "acct-c"
}
],
"activeAccountId" : "user-a__acct-a",
"cachedModelCatalog" : [
],
"enabled" : true,
"id" : "openai-oauth",
"kind" : "openai_oauth",
"label" : "OpenAI",
"pinnedModelIDs" : [
],
"wireAPI" : "responses"
},
{
"accounts" : [
{
"apiKey" : "sk-deepseek",
"id" : "6F1C2B9E-0D3A-4E57-9B1F-2A7C8E4D5F60",
"kind" : "api_key",
"label" : "Default"
}
],
"baseURL" : "https://api.deepseek.com/v1",
"cachedModelCatalog" : [
],
"enabled" : true,
"id" : "deepseek",
"kind" : "openai_compatible",
"label" : "DeepSeek",
"pinnedModelIDs" : [
],
"presetID" : "deepseek",
"wireAPI" : "chat"
}
],
"version" : 1
}`
// 碳碳双键 on Discord: several Codex accounts switched with codexbar on the
// old computer, only the one Codex was signed in to on the new one. A
// backup carries no sign-in, so codexbar's own file is what brings them:
// each ChatGPT account in it is imported, its seat kept apart by
// openAIAccountId, and nothing else in the file taken for an account.
func TestImportCodexbarConfig(t *testing.T) {
claudeHome(t)
var mu sync.Mutex
asked := map[string]int{}
fake := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var body map[string]string
json.NewDecoder(r.Body).Decode(&body)
rt := body["refresh_token"]
mu.Lock()
asked[rt]++
mu.Unlock()
if rt != "r-a" && rt != "r-b" {
w.WriteHeader(400)
json.NewEncoder(w).Encode(map[string]any{"error": "invalid_grant"})
return
}
// an id token that doesn't name the workspace: the file's
// openAIAccountId is what tells the two seats apart
json.NewEncoder(w).Encode(map[string]any{
"id_token": fakeJWT(map[string]any{"email": "team@example.com", "https://api.openai.com/auth": map[string]any{"chatgpt_plan_type": "team"}}),
"access_token": fakeJWT(map[string]any{"exp": float64(time.Now().Add(time.Hour).Unix())}),
"refresh_token": "n" + rt,
})
}))
defer fake.Close()
t.Cleanup(CodexTokenURLForTest(fake.URL))
rs, err := ImportLogins(context.Background(), "codex", []string{codexbarConfig})
if err != nil {
t.Fatal(err)
}
want := "team@example.com · Team:added,team@example.com · Team:added,session@example.com:failed"
if got := importStatuses(rs); got != want {
t.Fatalf("got %s\nwant %s", got, want)
}
if !strings.Contains(rs[2].Error, "only an access token") {
t.Errorf("no refresh token: %q", rs[2].Error)
}
if asked["r-a"] != 1 || asked["r-b"] != 1 || len(asked) != 2 {
t.Errorf("asked %v", asked)
}
loginsMu.Lock()
ls := readLogins()
loginsMu.Unlock()
ws := map[string]bool{}
for _, l := range ls {
if e, w := codexWho(l.Auth); e == "team@example.com" {
ws[w] = true
}
}
if !ws["acct-a"] || !ws["acct-b"] || len(ls) != 2 {
t.Errorf("seats kept: %v (%d logins)", ws, len(ls))
}
// for Claude, nothing in it is Claude's
rs, _ = ImportLogins(context.Background(), "claude", []string{codexbarConfig})
for _, r := range rs {
if r.Status != "failed" || !strings.Contains(r.Error, "ChatGPT account") {
t.Errorf("claude: %+v", r)
}
}
}