Skip to content

Account Pooler: pool-routed Claude Code and Codex threads, and CLIs they start, should authenticate only with the hub token and leave the host's own logins untouched #6171

Open

Description

@seklow

The workflow

On one Linux host, bb 0.46.1 routes every Claude Code and Codex thread through Account Pooler. The same host keeps its own Claude Code and Codex logins (~/.claude/.credentials.json, ~/.codex/auth.json) for terminal use. A separate account switcher, ccswap v0.39.2, manages those logins, and they should not depend on the pool in either direction.

What I want: while a thread is routed through the pool, nothing in that thread uses, refreshes or requires the host logins. That covers the provider process, its subagents, model-list probes and CLIs the agent starts. The hub token is the thread's only credential. Threads that are not routed keep using the host logins as they do today.

Where bb gets in the way:

  1. Routed Claude Code threads still refresh and rewrite ~/.claude/.credentials.json.
  2. Routed Codex threads run codex app-server on the host's ChatGPT login.
  3. A codex CLI started from a routed Claude Code thread is not routed at all. A typical case is codex exec review for a second opinion. It runs on the host's ChatGPT login and quota.

What happens today

Versions.

  • Base commit for code links: 1e80ca7b44bccd06c6da75ed9ca6ba497bd380f5 (main, 2026-10-23).
  • bb 0.46.1, installed via npm bb-app. desktop-v0.46.1 is the latest release.
  • Linux x86_64, Node v24.22.1, built-in account-pool 0.1.0.
  • Claude Code 2.1.308 at the time of the incident below, 2.1.309 now.
  • codex-cli 0.163.0 during the observations; 0.164.0 has been installed since 2026-10-23 05:48 UTC.
  • The installed account-pool/dist/server.js and provider-codex/dist/host.js contain the same env entries and flags as main.

Claude Code.

Observed 2026-10-23 (UTC) in thread thr_cv4aev22bx:

  • Its Claude session env came from account-pool: provider.env-resolved seq 6979 shows ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN and the other entries, and no CLAUDE_CONFIG_DIR or CLAUDE_CODE_OAUTH_TOKEN.
  • A workflow subagent in that session (Claude Code 2.1.308, entrypoint sdk-cli) produced this timeline:
00:49:49.973  subagent transcript: tool result
00:49:50.440  ~/.claude/.credentials.json rewritten; new expiresAt = write time + 8 h (file timestamp recorded during the investigation)
00:49:50.455  subagent transcript: api-request (to the pool hub, with the hub token)
00:49:50.876  account-pool plugin.log: "Account Pooler claude account <account B> OAuth refresh failed: OAuth refresh failed with HTTP 400. invalid_grant. expiresAt=1792716887319, forced=false."
00:49:51, 00:49:53, 00:49:55  three routed threads (thr_cv4aev22bx itself, thr_cehnf3bqqh, thr_t9xt22j7id): 429 "No Account Pooler account is currently eligible. Next account is expected to be available at 2026-10-23T02:59:59.798Z"

Account B had been added with --import from this host login, so it held the same refresh token. That part is covered in #4352 (evidence comment there), and how the pool reacts when it loses the race is #6167. This issue is about something else: the routed thread had no use for the host login, yet its refresh still spent the single-use refresh token and took a pool account out of service.

Across about 3.7 days, the investigation counted 8 windows in which Claude Code on the host's active login renewed it before the pool did. Three of them ended in invalid_grant for the pool, each 267–297 s before expiresAt:

Time (UTC) Renewing process (pool-routed bb thread, running on the env credential)
2026-10-21T10:05:55Z thr_a2dvs6byg3
2026-10-22T11:46:58Z thr_biw5z6pxki
2026-10-23T00:49:50Z thr_cv4aev22bx

When such a session loses the race instead, Claude Code clears the stored login on the 400 (tengu_oauth_refresh_token_cleared_on_disk in the binary), and that signs the terminal out.

Codex.

  • The pool contributes CODEX_OPENAI_BASE_URL and CODEX_POOL_AUTH_TOKEN (server.ts#L386-L400).
  • provider-codex turns them into -c overrides for codex app-server. One of them is a hardcoded model_providers.bb-account-pool.requires_openai_auth=true (provider-codex bridge.ts#L350-L386).
  • The Codex docs say: "Set requires_openai_auth = true to use OpenAI authentication. You can then sign in with ChatGPT or an API key", and "When requires_openai_auth = true, Codex ignores env_key." Sign-in-with-ChatGPT tokens are refreshed "automatically during use before they expire".

Codex's own log database (~/.codex/logs_2.sqlite) has 30 bb-launched pooled app-server processes (app_server.client_name="bb") between 2026-10-19 and 2026-10-23. In them:

  • All 326 tagged /responses requests to the hub show auth_mode="Chatgpt", auth_header_attached=true.
    • So the host's ChatGPT bearer goes to the hub on every request.
    • The hub authenticates by x-bb-account-pool-token first (hub.ts#L180-L185) and replaces Authorization with the pool account's token (codex-adapter.ts#L424-L438).
  • The same processes completed 438 POST https://chatgpt.com/backend-api/codex/analytics-events/events requests, all 200, outside the pool. Request headers are not logged, so I infer rather than see that these use the host login.

Two things I have not established for Codex:

  • I have not seen a bb Codex process refresh auth.json yet. The host's ChatGPT access token was issued 2026-10-16 and expires 2026-10-26, and refresh happens near expiry. Whichever Codex process is active then will refresh it, and a pooled bb app-server can be that process.
  • I did not test whether a pooled Codex thread works with no ~/.codex/auth.json at all. So "requires" is unverified for Codex. "Loads and may refresh" is verified.

Nested CLIs.

  • A Claude Code thread's shell gets the Claude routing variables. It also gets the nested-bb-server markers BB_ACCOUNT_POOL_PARENT_URL and BB_ACCOUNT_POOL_PARENT_TOKEN (server.ts#L290-L301, accounts-and-routing.md#L130-L136).
  • Nested claude is therefore routed, and it refreshes the host login the same way as above.
  • Nested codex is not routed. Codex takes its provider from config or -c flags only; the 0.164.0 binary does not reference CODEX_OPENAI_BASE_URL. So codex exec … from a pooled Claude thread runs on the host ChatGPT login and quota.
  • The workaround is a user-written PATH shim named codex that turns the markers into the same -c overrides. It is fragile. On this host, bash -lc 'type -a codex' resolves the npm codex before the shim because the login profile reorders PATH, so any agent command that uses a login shell bypasses the shim.

On main: unchanged.

  • PROVIDER_ROUTING_ENV, both env contributions and requires_openai_auth=true are the same as in 0.46.1.
  • The only relevant change since desktop-v0.46.1 is List provider models with plugin-contributed provider environment #5767. It lets model listing use the pool env with threadId: null, which adds model-list probes to the set of pooled processes.
  • git grep CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST finds nothing.

What you would expect

  1. Scope. While a thread is routed, it authenticates only with the hub token.

    • Its provider process, subagents, model-list probes and nested CLIs never refresh or write ~/.claude/.credentials.json, the macOS Keychain entry or ~/.codex/auth.json, and do not require them.
    • bb already plans for routed hosts without a local Claude login: see routedThreadsWithoutLocalLogin (operations.ts#L299-L341, server.ts#L502-L514).
    • Unrouted threads keep the host login as today. That covers routing off, bb pool bypass, and no usable account. So the change belongs in the routed branch of contributeFor (server.ts#L309-L332), not in global env.
  2. Claude Code. Candidate: contribute CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=1 together with the routing variables.

    • The env-vars docs describe it as "Set by host platforms that embed Claude Code and manage model provider routing on its behalf".
    • In the 2.1.308 and 2.1.309 binaries, the stored-login readers return null when it is set. The refresh path then finds no refresh token and leaves .credentials.json alone. The docs do not promise this; I got it from reading the binary.

    Side effects to check before adopting it:

  3. Codex. Launch the pooled app-server with provider auth that does not go through the ChatGPT login, and keep the model catalog.

    • From the Codex 0.163.0 source: requires_openai_auth=false alone is not enough. The provider still asks the base auth manager for auth, and that manager loads auth.json and can refresh it. Only a provider with command-backed auth gets a separate bearer-only manager.
    • So one candidate is requires_openai_auth=false plus a command-backed auth that prints the hub token. The hub already accepts the hub token as a bearer (hub.ts#L180-L185).

    Points to check:

    • Model catalog. OpenAI's gateway docs say that with only a custom header, "remote catalog discovery won't run", and point to model_catalog_json. The hub already serves GET /v1/models (server.ts#L453-L458). Confirm that Codex uses it under command-backed auth, or have bb supply model_catalog_json.
    • Resume. Existing pooled sessions are recorded with model_provider = "bb-account-pool" and must still resume (Pooled Codex sessions can't be resumed outside bb: model provider bb-account-pool not found #6107).
    • Other routes. Image routes must keep working through the pool.
    • Analytics. Decide explicitly whether the app-server's direct chatgpt.com analytics calls stop or keep using the host login.
  4. Nested CLIs. codex (and claude) started inside a pooled thread should be routed in a supported way that does not depend on PATH order or the shell type.

  5. Acceptance test.

    • Setup: in a scratch HOME, create a ~/.claude/.credentials.json whose access token expires in two minutes (dummy refresh token) and a ChatGPT-mode ~/.codex/auth.json. Record their sha256 and mtime.
    • Run, with routing on:
      • a new Claude thread turn;
      • resume after a bb restart;
      • fork;
      • a Claude subagent or workflow;
      • a model-list probe;
      • nested claude -p and codex exec from a Claude thread, via both bash -c and bash -lc;
      • Codex thread start, resume and fork.
    • Expected: both files are byte-identical with unchanged mtime, and every turn succeeds.
    • Today: the Claude turn alone should already change the file. It attempts the refresh and, on the resulting 400, clears the stored login.
    • Repeat with both files absent: everything still succeeds.
    • Routing off: the same threads use the host logins as today.

Context and alternatives

Checks

  • I searched open and closed issues for the same request.
  • If an agent wrote this, the body ends with > AGENT GENERATED.

AGENT GENERATED

Activity

  1. added theissue type on Oct 23, 2026
  2. added
    providers
    security
    provider-claude-code
    provider-codex
    partial-repro
    on Oct 23, 2026
  3. bb-slop-cop commented on Oct 23, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority Medium · Effort Medium.
    • Labels: providers, security, provider-claude-code, provider-codex, partial-repro.
    • Reproduction report: PARTIALLY REPRODUCED. Root-cause confidence: high for the verified launch configuration.
    • Root cause: pooled Codex launches still enable native OpenAI authentication (requires_openai_auth=true) alongside the hub-token header.
    • Evidence: the focused child-launch assertion fails identically in two clean trusted-main checkouts; nine existing catalog tests pass in each run, plus eight launch/routing controls. Actual upstream credential refresh, file writes, analytics, and nested-CLI behavior remain unverified.
    • No PR: authentication/security-boundary changes are excluded from the safe simple-fix policy.

    AGENT GENERATED

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    partial-reproprovider-claude-codeprovider-codexproviderssecurity

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions