Skip to content

Claude usage check ignores CLAUDE_CONFIG_DIR, reporting expired for a signed-in account #3607

Closed

Description

@dfaivre

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

  1. Start BB with CLAUDE_CONFIG_DIR set to a directory other than ~/.claude, holding a valid
    login (BB propagates it to the bridge — the bridge worker process carries it).
  2. Let ~/.claude/.credentials.json hold an expired token for the same account.
  3. Run bb settings usage, or open any surface backed by system.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

  1. added theissue type on Sep 13, 2026
  2. added
    providers
    provider-claude-code
    confirmed-repro
    on Sep 13, 2026
  3. bb-slop-cop commented on Sep 13, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    Bug · 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.

  4. dfaivre-pcs commented on Sep 17, 2026

    @dfaivre-pcs

    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/.claude unconditionally, the only way to stop BB
    reporting expired for a valid login is to stop using a custom CLAUDE_CONFIG_DIR at all. I
    did that on 2026-09-17: the profile script that had been exporting
    CLAUDE_CONFIG_DIR=/home/dfaiv/.local/share/dev-profiles/pcs/claude was changed to unset it,
    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:

    No conversation found with session ID: 0f5a946e-c5a8-404a-9f94-847a44443405
    

    BB surfaces that as Claude Code returned an error result and the thread lands in error. Not
    one 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:

    • The profile edit landed at 09:17, but direnv had no watch_file on the sourced profile, so
      the 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.
    • At ~15:13 an unrelated checkout move invalidated direnv's cache. The 09:17 unset took effect
      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_DIR in the first place.

    Recovery, for anyone who hits this

    The transcripts are not lost — they are in the old config dir under projects/. Merging them
    into the new home is enough:

    rsync -a --ignore-existing \
      "$OLD_CONFIG_DIR/projects/" "$HOME/.claude/projects/"

    In my case 814 transcripts merged into 548, with 52 colliding paths that were byte-identical
    (verified with cmp before copying), so nothing was overwritten. Threads resume normally after
    that.

    Why this raises the severity

    As written, the issue reads as a misleading display: the panel says expired while sessions
    work 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_DIR later, or unsets it, gets the same failure from the other direction — the
    transcripts 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:

    1. readCredentials/readAccountEmail honoring CLAUDE_CONFIG_DIR — this issue. Then there
      is no reason to abandon the custom home at all.
    2. A resume failure that names the config dir it searched. No conversation found with session ID: <uuid> is true but unactionable; ... in <config-dir>/projects/<key>/ would have
      made 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.

  5. markspen commented on Sep 21, 2026

    @markspen

    macOS reproduction: path fix alone does not cover an expired Keychain access token

    I reproduced the misleading expired state on macOS with a working Claude session. This adds a second credential-source case that the fix should cover.

    Environment

    • bb desktop/CLI 0.43.3
    • Claude Code 2.1.278
    • macOS 27.0 (26A428)
    • CLAUDE_CONFIG_DIR=/Users/markspencer/.claude-personal
    • Checked current main at b5755d6859d68c2d8e2008fc570f2d5acec774da

    Reproduction and observed results

    1. claude auth status reports loggedIn: true, authMethod: oauth_token, and configDirectory: /Users/markspencer/.claude-personal.

    2. claude -p "Reply with only OK." --model haiku succeeds and returns OK.

    3. bb settings usage --machine <local-host> returns:

      { "claude-code": { "status": "expired" } }
    4. Running claude auth login and refreshing usage does not change the result.

    5. The only macOS Keychain item with service Claude Code-credentials still contains an access-token expiresAt of 2026-09-20T22:07:01Z and a non-empty refresh token. No access or refresh token was printed or copied during this check.

    6. There is no .credentials.json in 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_DIR for 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 ordinary claude auth login while already logged in does not, and asking users to destroy a working session is not a reasonable usage-meter repair.

    Investigation thread: thr_atnbz83rxg.

    AGENT GENERATED

  6. AbelThorne commented on Sep 22, 2026

    @AbelThorne

    macOS root cause: the Keychain service name also depends on CLAUDE_CONFIG_DIR

    This also explains the macOS "expired" case in the previous comment. On macOS, when CLAUDE_CONFIG_DIR is set, Claude Code does not use the Claude Code-credentials Keychain service. It uses a suffixed service:

    Claude Code-credentials-<first 8 hex chars of sha256(CLAUDE_CONFIG_DIR)>
    

    readKeychainCredentials() in provider-maintenance.ts only looks up the fixed CLAUDE_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 reports expired or unauthenticated. Re-running claude auth login updates only the suffixed item, which is why it "does not change the result".

    Repro (bb 0.43.3, macOS)

    • CLAUDE_CONFIG_DIR=~/.claude-tcp
    • printf '%s' "$CLAUDE_CONFIG_DIR" | shasum -a 256 | cut -c1-8 → 80ae27a8
    • security dump-keychain | grep -o '"Claude Code-credentials[^"]*"' lists Claude Code-credentials plus several suffixed items, one per config dir used (-80ae27a8 among them).
    • Reading Claude Code-credentials → BB reports the provider as unauthenticated.
    • Reading Claude Code-credentials-80ae27a8 with the same parsing and the same GET https://api.anthropic.com/api/oauth/usage call → 200, correct session and weekly percentages.

    Suggested fix

    When resolving the Claude profile for maintenance, derive everything from the effective config dir:

    • Keychain service: Claude Code-credentials when CLAUDE_CONFIG_DIR is unset, otherwise Claude 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.
    • Credentials file: ${configDir}/.credentials.json.
    • Account/email: ${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.

    Investigated with an AI agent; repro verified on my machine.

  7. markspen commented on Sep 22, 2026

    @markspen

    Confirmed on the machine from my previous comment. This fully explains that reproduction and corrects my earlier refresh-token hypothesis.

    • Effective config dir: /Users/markspencer/.claude-personal
    • sha256(configDir).slice(0, 8): d2f7a5d9
    • Keychain contains both Claude Code-credentials and Claude Code-credentials-d2f7a5d9.
    • The unsuffixed item BB reads expired at 2026-09-20T22:07:01Z (Sep 20, 3:07 PM PDT).
    • The suffixed item for the active profile expired at 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, when claude auth login had just succeeded and BB still reported expired.
    • Both checks only inspected service names, expiry timestamps, and token presence; no credential values were printed or copied.

    So claude auth login did update the active profile's suffixed Keychain item. BB continued showing expired because it selected the stale unsuffixed default-profile item. For this observed case, selecting the Keychain service derived from the effective CLAUDE_CONFIG_DIR is sufficient; automatic refresh is a separate concern rather than the root cause here.

    Thanks for finding the service-name derivation.

    AGENT GENERATED

  8. markspen commented on Oct 7, 2026

    @markspen

    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.ts reads only the unsuffixed Claude Code-credentials Keychain item, so anyone running Claude Code with CLAUDE_CONFIG_DIR still sees "expired" for a signed-in account.

    #4086 resolves CLAUDE_CONFIG_DIR the same way Claude Code does, reads Claude 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 claudeKeychainService setting. Set it to Claude 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.

  9. added a commit that references this issue on Oct 28, 2026
    ea8901a
  10. vlasovsmm commented on Nov 4, 2026

    @vlasovsmm

    Still reproducing on 0.48.1, and main still has the fixed Claude Code-credentials lookup in provider-maintenance.ts.

    Setup: bb runs as a launchd service with CLAUDE_CONFIG_DIR pointing at a second Claude account. Threads work on that account. The usage card and bb settings usage report 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?

    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

    confirmed-reproprovider-claude-codeproviders

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions