Feature request: support multiple Codex (ChatGPT) login states in one gateway

Author: SilverRegexCreated Sep 28, 2026Updated Sep 28, 2026

Summary

CCR can discover and import exactly one Codex login, and after that it is impossible to add a second account or switch to another one from the UI. There is also no field to enter a Codex/ChatGPT token manually.

Concretely, today a single gateway instance is hard-wired to $HOME/.codex/auth.json:

  • only one Codex candidate can ever exist (its id is hardcoded codex-api),
  • the scan ignores CODEX_HOME and any Codex executable location,
  • the UI hides the Codex row as soon as one ccr-local-agent-login provider exists, so it cannot be re-imported,
  • hand-editing stored tokens does not work, because the runtime always prefers the live ~/.codex/auth.json.

Installing a second Codex CLI changes nothing, and there is no supported way to route to two different ChatGPT subscriptions from one gateway.

Environment

  • @musistudio/[email protected] (also checked 3.1.1 — same limitation; the panel is now titled "Import local agent login" with the text "ChatGPT login detected. Click Import to add it as a gateway provider.")
  • Linux, gateway running via ccr serve
  • ~/.codex/auth.json present, auth_mode: "chatgpt", with access_token, refresh_token, id_token, account_id

Expected vs actual

Expected: "Import local agent login" detects each locally logged-in agent account, and two Codex accounts can coexist as two independent gateway providers, each refreshing its own tokens.

Actual:

  1. Only one Codex candidate is produced, with a fixed id:

    javascript
    // dist/main/cli.js — zJ()
    { detail: "ChatGPT login detected. Click Import to add it as a gateway provider.",
      id: "codex-api", importable: true, kind: "codex",
      name: "Codex API", protocol: "openai_responses", ... }
  2. The auth file path is hardcoded to the process home directory:

    javascript
    // dist/main/cli.js — Yi()
    let e = path.join(u4(), ".codex", "auth.json"), ...
    
    // dist/main/cli.js — u4()
    return process.env.CCR_INTERNAL_HOME_DIR?.trim()
        || process.env.HOME?.trim()
        || process.env.USERPROFILE?.trim()
        || os.homedir();
  3. The candidate list can contain at most one Codex entry:

    javascript
    // dist/main/cli.js — mS()  (IPC: getLocalAgentProviderCandidates)
    return [zJ(), sre(), T4(), ...mre(), ...X4(), bre()].filter(e => e.status !== "missing");
  4. CODEX_HOME / CCR_CODEX_CHATGPT_AUTH_FILE are only injected into launched Codex child processes (QUe() / DUe()); they are never consulted by the scan. So relocating the Codex home does not create a second importable candidate.

  5. Even after switching accounts on disk, the row stays hidden. N8e() in the renderer drops any candidate whose name is prefixed by an existing local-login provider:

    javascript
    // dist/renderer/assets/main.js
    return o.size === 0 ? false
      : t.some(i => i.api_key === Vme && i.name.trim().toLowerCase().startsWith(e.name.toLowerCase()))

    With a provider named Codex API present, the Codex candidate is filtered out permanently.

  6. There is no manual token input. The provider wizard has no token editor (accessToken occurs exactly once in the renderer bundle, as a plugin badge). For an imported Codex provider, api_key is only the sentinel ccr-local-agent-login; the credentials live in the generated ccr-local-agent-<provider>-codex-oauth plugin:

    javascript
    // dist/main/cli.js — XJ()
    codexOauth: { accessToken, accountId, refreshToken,
                  refreshIfMissingAccessToken: true, required: true }
  7. Editing those stored tokens does not help. The runtime resolver prefers the live auth file and only falls back to the config:

    javascript
    // dist/main/local-agent-auth-provider-hook.js
    let r = Yi();                                  // $HOME/.codex/auth.json
    let n = r?.accessToken || te(t.accessToken) || te(t.access_token),
        o = r?.refreshToken || te(t.refreshToken) || te(t.refresh_token),
        i = r?.accountId   || te(t.accountId)   || te(t.account_id);

    So duplicating a provider and pasting a second account's tokens into the plugin config is silently overridden by whatever is in ~/.codex/auth.json.

  8. A generic provider with api_base_url: https://chatgpt.com/backend-api/codex + a pasted access_token is not equivalent: the endpoint also needs ChatGPT-Account-Id, originator: codex_cli_rs and User-Agent: codex-cli. extraHeaders is a supported provider field in the normalizer (y_e(), forwarded via xre()/kre(), and cl() is a no-op validator), but the UI exposes no editor for it, and there is no refresh path, so it is only usable for short-lived manual testing.

Steps to reproduce

  1. codex login as account A; in CCR, Add provider → Choose provider → Import local agent provider → Import on the Codex row. Provider Codex API is created.
  2. Log in as account B (CODEX_HOME=~/codex-b codex login, or codex login after backing up ~/.codex/auth.json).
  3. Open Add provider again → the Codex row is gone (filtered by N8e), so no second import is possible.
  4. Try to add a provider manually: there is no field for a ChatGPT access/refresh/id token or account_id.
  5. Duplicate Codex API in the config and replace the plugin tokens with account B's → requests still go out as account A, because Yi() wins.

Requested behavior

  1. Multiple discovery sources, unique ids. Produce one candidate per Codex auth source: $CODEX_HOME/auth.json when set, $HOME/.codex/auth.json, the codexHome of each enabled Codex profile, and a user-configured list, e.g. localAgentLogins.codex.authFiles: string[]. Candidate ids must be unique and stable, e.g. codex-api:<accountId> or codex-api:<hash(path)>, with a display name such as Codex API (plus · a1b2c3d4).
  2. Per-provider auth binding. Let an imported Codex provider record which auth file it belongs to, e.g. codexOauth.authFile, and make the runtime resolver prefer that file over the default one. This is the piece that would make two accounts work inside a single gateway, each with independent refresh.
  3. Fix the dedup rule. Key local-login dedup on the account id (or the auth-file path) instead of on the provider name prefix, so a second account is importable side by side and both providers can coexist.
  4. Add "Re-authenticate / Switch account" for an already imported local-login provider, instead of forcing delete-then-reimport.
  5. Optional manual token entry — access token, refresh token, id token and account id — for headless/CI hosts with no local Codex CLI login. This would also remove the need for CCR_INTERNAL_HOME_DIR juggling.
  6. Documentation. Please state in the README that one gateway instance currently supports one Codex account, and document the CCR_INTERNAL_HOME_DIR workaround above.

Notes

  • Verified against the installed dist of 3.0.21 and the published 3.1.1 bundle; no secrets or tokens are included here.
  • Happy to test a patch. As a maintainer-level suggestion, items 1–3 together are sufficient for the multi-account case; 5 is the ergonomic follow-up.

Source: musistudio/claude-code-router