Repository navigation
Description
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:
- Routed Claude Code threads still refresh and rewrite
~/.claude/.credentials.json. - Routed Codex threads run
codex app-serveron the host's ChatGPT login. - A
codexCLI started from a routed Claude Code thread is not routed at all. A typical case iscodex exec reviewfor 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.1is 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.jsandprovider-codex/dist/host.jscontain the same env entries and flags asmain.
Claude Code.
- For a routed thread, the pool contributes
ANTHROPIC_BASE_URL,ANTHROPIC_AUTH_TOKEN,ENABLE_TOOL_SEARCH,_CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URLandENABLE_PROMPT_CACHING_1H(server.ts#L355-L382). - The session env is the daemon env plus these overrides (provider-claude-code bridge.ts#L1721-L1731). So the default
~/.claude, with the host's claude.ai login, stays visible to the session. - Requests use
ANTHROPIC_AUTH_TOKEN, which ranks above the stored/loginin Claude Code's precedence. The stored login is never used for inference. - Claude Code refreshes it anyway. In the 2.1.308 and 2.1.309 binaries, the pre-request refresh checks only two things: that the provider is first-party, and that the stored token is within 300 s of
expiresAt. It does not check which credential the request actually uses. - Upstream: [BUG] CLI holding an env credential still renews the stored claude.ai login; on macOS sandboxed processes split it to .credentials.json and a later 400 wipes it anthropics/claude-code#104359. Our Linux data is in [BUG] CLI holding an env credential still renews the stored claude.ai login; on macOS sandboxed processes split it to .credentials.json and a later 400 wipes it anthropics/claude-code#104359 (comment).
Observed 2026-10-23 (UTC) in thread thr_cv4aev22bx:
- Its Claude session env came from
account-pool:provider.env-resolvedseq 6979 showsANTHROPIC_BASE_URL,ANTHROPIC_AUTH_TOKENand the other entries, and noCLAUDE_CONFIG_DIRorCLAUDE_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_URLandCODEX_POOL_AUTH_TOKEN(server.ts#L386-L400). - provider-codex turns them into
-coverrides forcodex app-server. One of them is a hardcodedmodel_providers.bb-account-pool.requires_openai_auth=true(provider-codex bridge.ts#L350-L386). - The Codex docs say: "Set
requires_openai_auth = trueto use OpenAI authentication. You can then sign in with ChatGPT or an API key", and "Whenrequires_openai_auth = true, Codex ignoresenv_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
/responsesrequests to the hub showauth_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-tokenfirst (hub.ts#L180-L185) and replacesAuthorizationwith the pool account's token (codex-adapter.ts#L424-L438).
- The same processes completed 438
POST https://chatgpt.com/backend-api/codex/analytics-events/eventsrequests, 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.jsonyet. 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.jsonat 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_URLandBB_ACCOUNT_POOL_PARENT_TOKEN(server.ts#L290-L301, accounts-and-routing.md#L130-L136). - Nested
claudeis therefore routed, and it refreshes the host login the same way as above. - Nested
codexis not routed. Codex takes its provider from config or-cflags only; the 0.164.0 binary does not referenceCODEX_OPENAI_BASE_URL. Socodex exec …from a pooled Claude thread runs on the host ChatGPT login and quota. - The workaround is a user-written PATH shim named
codexthat turns the markers into the same-coverrides. It is fragile. On this host,bash -lc 'type -a codex'resolves the npmcodexbefore 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 andrequires_openai_auth=trueare the same as in 0.46.1.- The only relevant change since
desktop-v0.46.1is List provider models with plugin-contributed provider environment #5767. It lets model listing use the pool env withthreadId: null, which adds model-list probes to the set of pooled processes. git grep CLAUDE_CODE_PROVIDER_MANAGED_BY_HOSTfinds nothing.
What you would expect
-
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 ofcontributeFor(server.ts#L309-L332), not in global env.
- Its provider process, subagents, model-list probes and nested CLIs never refresh or write
-
Claude Code. Candidate: contribute
CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=1together 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.jsonalone. The docs do not promise this; I got it from reading the binary.
Side effects to check before adopting it:
- Documented:
- provider, endpoint and auth variables in settings files (
ANTHROPIC_BASE_URL,ANTHROPIC_API_KEY,CLAUDE_CODE_USE_*) are ignored; model,fallbackModelandmodelOverridesin managed settings, andANTHROPIC_MODEL/ANTHROPIC_DEFAULT_*_MODELin a managedenvblock, are ignored;- the telemetry opt-out for third-party providers behaves differently.
- provider, endpoint and auth variables in settings files (
- From the binary:
- A 401 becomes an immediate hard failure (
api_request_host_managed_auth_fail). Checkbb pool token rotate, which keeps the old token for only 10 minutes, against long-running sessions. apiKeyHelperis ignored.- Everything that needs the stored claude.ai login goes away: claude.ai connectors, Remote Control, Claude in Chrome (already broken behind the pool, Account Pooler prevents Claude in Chrome tools from loading despite --chrome #4707) and the subscription type. For the subscription type, the binary reads undocumented
CLAUDE_CODE_SUBSCRIPTION_TYPE/CLAUDE_CODE_RATE_LIMIT_TIERenv vars.
- A 401 becomes an immediate hard failure (
- Child env: the binary has an env builder that strips
ANTHROPIC_AUTH_TOKEN,ANTHROPIC_BASE_URL,_CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URLand the flag itself from a child env when the flag is set. It looks like the background-session launcher. Confirm that Bash-tool children, such as a nestedclaude, stay routed. - No regressions: 1M context (
_CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL, Account Pooler drops Claude Code Opus to a 200k context window (ANTHROPIC_BASE_URL disables native 1M); no [1m] model to work around it #4207), tool search and the 1-hour cache keep working as today, and feature-flag fetching still runs. - Anthropic may also fix the refresh gate itself in [BUG] CLI holding an env credential still renews the stored claude.ai login; on macOS sandboxed processes split it to .credentials.json and a later 400 wipes it anthropics/claude-code#104359. bb should not depend on that.
-
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=falsealone is not enough. The provider still asks the base auth manager for auth, and that manager loadsauth.jsonand can refresh it. Only a provider with command-backedauthgets a separate bearer-only manager. - So one candidate is
requires_openai_auth=falseplus a command-backedauththat 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 servesGET /v1/models(server.ts#L453-L458). Confirm that Codex uses it under command-backed auth, or have bb supplymodel_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 providerbb-account-poolnot found #6107). - Other routes. Image routes must keep working through the pool.
- Analytics. Decide explicitly whether the app-server's direct
chatgpt.comanalytics calls stop or keep using the host login.
- From the Codex 0.163.0 source:
-
Nested CLIs.
codex(andclaude) started inside a pooled thread should be routed in a supported way that does not depend on PATH order or the shell type.- One option is a bb entry point such as
bb pool exec -- codex exec …that applies the same provider config and auth as the app-server, documented in the account-pool and codex-provider skills. - A resolvable
bb-account-poolprovider in Codex config, as Pooled Codex sessions can't be resumed outside bb: model providerbb-account-poolnot found #6107 suggests, could cover both the nested case and Pooled Codex sessions can't be resumed outside bb: model providerbb-account-poolnot found #6107.
- One option is a bb entry point such as
-
Acceptance test.
- Setup: in a scratch
HOME, create a~/.claude/.credentials.jsonwhose 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 -pandcodex execfrom a Claude thread, via bothbash -candbash -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.
- Setup: in a scratch
Context and alternatives
- Workarounds in use now, all partial:
- Give the pool its own logins (
--logininstead of--import). This removes the shared grant from Disabling Account Pooler breaks Claude: running turns 503-retry for ~3 min, new threads fail with an expired local OAuth login #4352, but routed threads still rotate the host login. - The user-written
codexPATH shim for nested CLIs, which login shells bypass. - A manual
bb pool account enableafter eachinvalid_grant.
- Give the pool its own logins (
- Considered and rejected:
CLAUDE_CODE_OAUTH_TOKENin the global env stops the refresh. But it needs either a dummy value or one more long-lived grant, and it also affects unrouted threads and terminals.CLAUDE_CONFIG_DIRorCODEX_HOMEfor bb moves settings, history and sessions, which breaks resume of existing threads. bb's Claude usage check also ignoresCLAUDE_CONFIG_DIR(Claude usage check ignores CLAUDE_CONFIG_DIR, reporting expired for a signed-in account #3607).CLAUDE_SECURESTORAGE_CONFIG_DIRmoves only.credentials.jsonand the refresh lock, but it is undocumented.apiKeyHelperandANTHROPIC_API_KEYdo not stop the refresh.--barealso turns off hooks, skills, plugins and CLAUDE.md.
- Not a duplicate of:
- Disabling Account Pooler breaks Claude: running turns 503-retry for ~3 min, new threads fail with an expired local OAuth login #4352 (import shares the refresh token; disabling the pool leaves a dead login). That is the other half of the same incidents. This issue covers routed processes touching the host login at all, which continues after pool accounts get their own logins.
- Account Pooler: a rejected proactive OAuth refresh errors an account whose access token is still valid; background refresh keeps replaying the rejected token #6167 (the pool marks an account
errorwhen it loses the race while its access token is still valid). That one is about the pool's reaction, not the trigger. - Use Account Pooler credentials for Codex AI helpers #5690, Codex AI service reports ready with expired credentials #5689, Codex AI service ignores configured custom provider auth and falsely asks for codex login #4484: Codex AI helpers (titles, voice, commit messages) and their status. They concern helper calls, not agent threads.
- Pooled Codex sessions can't be resumed outside bb: model provider
bb-account-poolnot found #6107: resuming pooled Codex sessions outside bb. Related, because changing the provider definition must keep that working. - Account Pooler prevents Claude in Chrome tools from loading despite --chrome #4707: Claude in Chrome lost behind
ANTHROPIC_AUTH_TOKEN. Relevant here only as a side effect to check. - Plugin SDK: provider pool lanes as data, and a refuse-capable env contribution contract #3954 (refuse-capable env contract) and Add named provider connections and explicit account routing #1447 (named provider connections): broader API requests, not this isolation.
- Not reproduced live for this report. I worked read-only from logs, transcripts, the installed bundles, the Claude Code binaries and
main. I did not run bb withCLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=1or with changed Codex provider flags. - Suggested priority: Medium.
- It affects everyone who pools subscription accounts and keeps a local login on the same host.
- Here, one race took a pool account out of service and three routed threads were told to wait until 02:59:59Z, 2 h 10 min later.
- The workarounds are partial and manual.
- Effort: Medium, split across the two providers plus nested-CLI support.
- Investigation: bb thread
thr_agudxusj98; reports are underpool-research/in its thread storage. - Affected threads:
thr_a2dvs6byg3,thr_biw5z6pxki,thr_cv4aev22bx,thr_cehnf3bqqh,thr_t9xt22j7id.
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
bb-slop-cop commentedon Oct 23, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotproviders,security,provider-claude-code,provider-codex,partial-repro.requires_openai_auth=true) alongside the hub-token header.Make the Account Pooler hold its own logins (#6691)