Repository navigation
Description
Claude usage check ignores CLAUDE_CONFIG_DIR, reporting expired for a signed-in account
Summary
provider-claude-code's maintenance check reads the Claude login from
$HOME/.claude/.credentials.json unconditionally. When BB runs Claude Code with a
CLAUDE_CONFIG_DIR pointing elsewhere — which BB does correctly for sessions — the usage check
reads a different home than the one the sessions authenticate with. If that other home holds a
stale token, system.usageLimits reports { status: "expired" } for an account that is signed
in and working, and the UI tells the user to sign in again on a host where nothing is wrong.
Affected code (main, and the shipped 0.42.1 bundle)
plugins/provider-claude-code/src/bridge/provider-maintenance.ts:
// 275
async function readCredentials(): Promise<ClaudeCredentials | null> {
const keychainCredentials = await readKeychainCredentials();
if (keychainCredentials !== null) { ... }
try {
return parseCredentials(
await fs.readFile(
path.join(os.homedir(), ".claude", ".credentials.json"), // 284
"utf8",
),
);
} catch { return null; }
}
// 293
async function readAccountEmail(): Promise<string | null> {
... await fs.readFile(path.join(os.homedir(), ".claude.json"), "utf8") // 297
}Line 490 then maps an expired expiresAt to { status: "expired" }, and line 361 does the same
for the health result. readAccountEmail has the same defect: with a custom config dir, Claude
Code writes .claude.json inside that directory, so the account email silently comes from the
wrong profile or goes missing.
The installed 0.42.1 build has the same hardcoded path in
server/dist/builtin-plugins/provider-claude-code/dist/host.js. That bundle references
CLAUDE_CONFIG_DIR 18 times for session and transcript plumbing — so the variable is plainly
known to this plugin; only the maintenance read ignores it.
Reproduction
- Start BB with
CLAUDE_CONFIG_DIRset to a directory other than~/.claude, holding a valid
login (BB propagates it to the bridge — the bridge worker process carries it). - Let
~/.claude/.credentials.jsonhold an expired token for the same account. - Run
bb settings usage, or open any surface backed bysystem.usageLimits.
Observed on 2026-09-13 09:23 CDT, Linux (WSL2), bb-app 0.42.1:
$ bb settings usage --json
{ "claude-code": { "status": "expired" }, ... }
while a direct call with the token from the configured config dir answers:
HTTP 200 five_hour utilization 14.0 seven_day utilization 30.0
Expected { status: "ok", ... } with those windows.
Suggested fix
Resolve the directory the same way the rest of the plugin does, then read
<dir>/.credentials.json and <dir>/.claude.json. BB already documents the semantics on
ExperimentalClaudePluginRoots.claudeDir — CLAUDE_CONFIG_DIR when set and non-blank
(absolute, ~-relative, or relative to the home directory), else ~/.claude — and
packages/plugin-sdk/src/vendor-plugin-roots.ts:435 (resolveClaudeConfigDir) already
implements exactly that. Reusing it would keep the two readers from drifting.
The macOS keychain source needs a decision rather than a mechanical change: the
Claude Code-credentials item is account-global, not per-config-dir, so keychain-first stays
right for the default home. With an explicit CLAUDE_CONFIG_DIR, a credentials file in that
directory is the more specific answer and arguably should win.
Impact
One hardcoded path, several surfaces: bb settings usage, any plugin built on
sdk.system.usageLimits (the third-party usage-tracker shows the same wrong status), and the
provider health badge. Each reports a signed-in account as expired, and the remedy the UI
suggests — sign in again on that host — does not fix it, because the host it names is not the
one the sessions use.
Activity
bb-slop-cop commentedon Sep 13, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotBug · Priority: Medium · Effort: Low —
providers,provider-claude-code.Reproduction report: REPRODUCED, high root-cause confidence. Maintenance reads fixed default credential and account paths, ignoring the configured profile.
Two clean checkouts produced the same three regression failures (usage, health, account email) and one passing control using synthetic profiles. Reproduction label:
confirmed-repro.No PR: changing authentication credential-source selection and deciding Keychain fallback precedence exceed this rule’s simple-fix limits.
dfaivre-pcs commentedon Sep 17, 2026
The workaround for this bug strands the whole session store
Reporting this because the blast radius is larger than a wrong status line, and the obvious
workaround is the thing that causes the damage.
Because the maintenance check reads
$HOME/.claudeunconditionally, the only way to stop BBreporting
expiredfor a valid login is to stop using a customCLAUDE_CONFIG_DIRat all. Idid that on 2026-09-17: the profile script that had been exporting
CLAUDE_CONFIG_DIR=/home/dfaiv/.local/share/dev-profiles/pcs/claudewas changed tounsetit,so the probe and the sessions would finally agree on one home.
That silently orphaned every transcript in the old home. Claude Code resolves a session by
<config-dir>/projects/<cwd-key>/<session-uuid>.jsonl, so the moment the variable went away,762 transcripts became unreachable. Every Claude thread in the instance failed to resume
with the same error:
BB surfaces that as
Claude Code returned an error resultand the thread lands inerror. Notone thread, all of them — including long-running ones mid-task. Nothing in the failure points at
the config directory; the transcripts were intact on disk the entire time, just in a home nobody
was reading anymore.
What made it hard to diagnose
The two changes were six hours apart, so the cause and the symptom looked unrelated:
direnvhad nowatch_fileon the sourced profile, sothe stale environment kept being served. A shell snapshot taken at 11:09 still carried
CLAUDE_CONFIG_DIR=/home/dfaiv/.local/share/dev-profiles/pcs/claude.for the first time, and every thread died at once — several hours after the only change that
could explain it, and immediately after a change that could not.
That second part is my own footgun, not BB's. The part that is BB's: the usage check being the
only reason to abandon
CLAUDE_CONFIG_DIRin the first place.Recovery, for anyone who hits this
The transcripts are not lost — they are in the old config dir under
projects/. Merging theminto the new home is enough:
In my case 814 transcripts merged into 548, with 52 colliding paths that were byte-identical
(verified with
cmpbefore copying), so nothing was overwritten. Threads resume normally afterthat.
Why this raises the severity
As written, the issue reads as a misleading display: the panel says
expiredwhile sessionswork fine. In practice it forces a choice between an accurate usage panel and a non-default
config dir, and taking the panel costs you every session in the instance. A user who sets
CLAUDE_CONFIG_DIRlater, or unsets it, gets the same failure from the other direction — thetranscripts silently stop resolving, with an error message that names a session ID and nothing
about where it was looked for.
Two things would each have prevented this independently of the fix here:
readCredentials/readAccountEmailhonoringCLAUDE_CONFIG_DIR— this issue. Then thereis no reason to abandon the custom home at all.
No conversation found with session ID: <uuid>is true but unactionable;... in <config-dir>/projects/<key>/would havemade this a two-minute fix instead of an instance-wide outage.
Happy to test a patch against 0.42.1 — the reproduction in the issue body still holds.
markspen commentedon Sep 21, 2026
macOS reproduction: path fix alone does not cover an expired Keychain access token
I reproduced the misleading
expiredstate on macOS with a working Claude session. This adds a second credential-source case that the fix should cover.Environment
CLAUDE_CONFIG_DIR=/Users/markspencer/.claude-personalmainatb5755d6859d68c2d8e2008fc570f2d5acec774daReproduction and observed results
claude auth statusreportsloggedIn: true,authMethod: oauth_token, andconfigDirectory: /Users/markspencer/.claude-personal.claude -p "Reply with only OK." --model haikusucceeds and returnsOK.bb settings usage --machine <local-host>returns:{ "claude-code": { "status": "expired" } }Running
claude auth loginand refreshing usage does not change the result.The only macOS Keychain item with service
Claude Code-credentialsstill contains an access-tokenexpiresAtof2026-09-20T22:07:01Zand a non-empty refresh token. No access or refresh token was printed or copied during this check.There is no
.credentials.jsonin the active custom config directory.The active Claude CLI can therefore refresh/authenticate sufficiently to run a request, while BB reads the expired Keychain access-token timestamp and stops before any usage request. Restarting BB only rereads the same record.
Code path
At
provider-maintenance.ts#L278-L293, Keychain always wins and the fallback path is hardcoded to~/.claude. The health check treats the stored access-token timestamp as terminal at#L347-L368, and usage does the same before contacting Anthropic at#L495-L510.So honoring
CLAUDE_CONFIG_DIRfor file/account reads remains necessary, but it is not sufficient for this macOS case. The maintenance path also needs a safe credential-refresh strategy (tracked more broadly in #3337), or it needs to delegate auth/usage to a Claude-supported CLI surface rather than interpreting an expired access token as a signed-out account. A forced logout/login may rotate the Keychain record, but ordinaryclaude auth loginwhile already logged in does not, and asking users to destroy a working session is not a reasonable usage-meter repair.Investigation thread:
thr_atnbz83rxg.AbelThorne commentedon Sep 22, 2026
macOS root cause: the Keychain service name also depends on
CLAUDE_CONFIG_DIRThis also explains the macOS "expired" case in the previous comment. On macOS, when
CLAUDE_CONFIG_DIRis set, Claude Code does not use theClaude Code-credentialsKeychain service. It uses a suffixed service:readKeychainCredentials()inprovider-maintenance.tsonly looks up the fixedCLAUDE_KEYCHAIN_SERVICE = "Claude Code-credentials". That item belongs to the default profile, or is left over from an earlier login without a custom config dir. It is never refreshed by the profile actually in use, so BB reads a stale token and reportsexpiredorunauthenticated. Re-runningclaude auth loginupdates only the suffixed item, which is why it "does not change the result".Repro (bb 0.43.3, macOS)
CLAUDE_CONFIG_DIR=~/.claude-tcpprintf '%s' "$CLAUDE_CONFIG_DIR" | shasum -a 256 | cut -c1-8→80ae27a8security dump-keychain | grep -o '"Claude Code-credentials[^"]*"'listsClaude Code-credentialsplus several suffixed items, one per config dir used (-80ae27a8among them).Claude Code-credentials→ BB reports the provider as unauthenticated.Claude Code-credentials-80ae27a8with the same parsing and the sameGET https://api.anthropic.com/api/oauth/usagecall →200, correct session and weekly percentages.Suggested fix
When resolving the Claude profile for maintenance, derive everything from the effective config dir:
Claude Code-credentialswhenCLAUDE_CONFIG_DIRis unset, otherwiseClaude Code-credentials-${sha256(configDir).slice(0, 8)}. Keep the unsuffixed service only as a fallback, and ideally only when the suffixed item is absent. Otherwise the stale default-profile token keeps winning.${configDir}/.credentials.json.${configDir}/.claude.json.Stopgap for anyone affected: I added a "Claude Keychain service" override setting to the community Usage Tracker plugin, which reads the suffixed item directly. PR: MateoCerquetella/bb-plugins#48.
markspen commentedon Sep 22, 2026
Confirmed on the machine from my previous comment. This fully explains that reproduction and corrects my earlier refresh-token hypothesis.
/Users/markspencer/.claude-personalsha256(configDir).slice(0, 8):d2f7a5d9Claude Code-credentialsandClaude Code-credentials-d2f7a5d9.2026-09-20T22:07:01Z(Sep 20, 3:07 PM PDT).2026-09-22T03:13:21Z(Sep 21, 8:13 PM PDT). It was therefore valid during the original Sep 21, 12:13 PM PDT reproduction, whenclaude auth loginhad just succeeded and BB still reportedexpired.So
claude auth logindid update the active profile's suffixed Keychain item. BB continued showingexpiredbecause it selected the stale unsuffixed default-profile item. For this observed case, selecting the Keychain service derived from the effectiveCLAUDE_CONFIG_DIRis sufficient; automatic refresh is a separate concern rather than the root cause here.Thanks for finding the service-name derivation.
markspen commentedon Oct 7, 2026
My fix for this, #4086, was closed automatically last night by the two-week stale-PR rule. It hadn't been reviewed, and its CI checks never started, so the close doesn't reflect a problem with the change.
The bug is still on
main:provider-maintenance.tsreads only the unsuffixedClaude Code-credentialsKeychain item, so anyone running Claude Code withCLAUDE_CONFIG_DIRstill sees "expired" for a signed-in account.#4086 resolves
CLAUDE_CONFIG_DIRthe same way Claude Code does, readsClaude Code-credentials-<hash>and the custom profile's.credentials.json/.claude.json, and keeps the unsuffixed item as a last fallback. It includes regression tests for each case. Default-profile behavior is unchanged.For anyone hitting this in the meantime: the Usage Tracker plugin (0.1.10 and later) has a
claudeKeychainServicesetting. Set it toClaude Code-credentials-<hash>, and it reads and refreshes that Keychain item directly.Would you like me to reopen #4086 and rebase it on current
main? I'm happy to adjust the approach if you'd rather handle it differently.Read Claude credentials from the configured profile
vlasovsmm commentedon Nov 4, 2026
Still reproducing on 0.48.1, and
mainstill has the fixedClaude Code-credentialslookup inprovider-maintenance.ts.Setup: bb runs as a launchd service with
CLAUDE_CONFIG_DIRpointing at a second Claude account. Threads work on that account. The usage card andbb settings usagereport the default account instead: 99% weekly while the working account was at 41%, or "expired" when nobody has used the default account for a while.#6495 had a complete fix for this but was closed by the two-week auto-close. Could it be reopened or the usage part landed?
Stop scanning ~/.claude/skills when CLAUDE_CONFIG_DIR moves it (#7076)
Ask Claude Code for the account and usage instead of reading its login (