Repository navigation
Conversation
Health and usage read ~/.claude/.credentials.json, ~/.claude.json and the default Keychain item, then called Anthropic's OAuth usage endpoint with that token. With CLAUDE_CONFIG_DIR set, Claude Code signs in from a different profile, so bb reported the wrong account, or expired for one that was signed in. Both now start Claude Code through the Agent SDK with no prompt, as model listing already does, and read the account it reports. Usage comes from the SDK usage request with skipBehaviors, so it skips the local transcript scan. Only the account UUID behind accountKey is still read from the profile's .claude.json, because Claude Code reports it nowhere else. Fork resolved a relative CLAUDE_CONFIG_DIR against the bridge process instead of the session's cwd, where Claude Code reads it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
force-pushed
the
bb/3607-claude-usage-check-ignores-claude-config-di-thr_4yj34xabd9
branch
from
November 6, 2026 05:05
867c68f to
5ff80e9
Compare
ymichael
deleted the
bb/3607-claude-usage-check-ignores-claude-config-di-thr_4yj34xabd9
branch
November 6, 2026 05:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
The Claude Code plugin's health and usage checks read Claude's login themselves:
~/.claude/.credentials.json,~/.claude.jsonand the defaultClaude Code-credentialsKeychain item. Usage then calledapi.anthropic.com/api/oauth/usagewith that token. WhenCLAUDE_CONFIG_DIRis set, Claude Code signs in from a different profile, so bb reported a different account than its sessions use. A stale token in the default profile could show asexpiredfor an account that was signed in and working (#3607).Fixing the paths would mean copying Claude Code's private rules for its folder, Keychain name and account file. The installed 2.1.317 binary showed several edge cases those rules miss: a legacy
.config.json,CLAUDE_SECURESTORAGE_CONFIG_DIR, relative paths and an empty variable. Separately, fork resolved a relativeCLAUDE_CONFIG_DIRagainst the bridge process's directory instead of the session's cwd, which is where Claude Code reads it.What changed
Everything is inside
plugins/provider-claude-code. There is no daemon protocol change, no plugin SDK change and no dependency change: main is already on@anthropic-ai/claude-agent-sdk0.3.318 (#7133).initialization-probe.ts: the probe that model and command listing already use now has a second entry point,probeClaudeUsage. It starts Claude Code with no prompt and sends the SDK usage request withskipBehaviors: true, which skips Claude's scan of local transcripts.initializationResult().account). It is signed out only when Claude reportstokenSource: "none"with no API key and a first-party provider. The plan label comes from Claude's own plan name, for example "Claude Ultra" → Ultra.unauthenticatedwhen Claude has no usable login or plan limits don't apply, which matches today's result for API-key logins..credentials.jsonreads, the directoauth/usagecall, and itsclaude-code/2.1.0User-Agent. This covers the Claude rows of Use regular Claude and Codex interfaces for status and usage, and identify bb as its own client #6688's table.accountKeystill reads the account UUID from the profile's.claude.json, at$CLAUDE_CONFIG_DIRor~(Claude Code's rule). Claude Code doesn't report the UUID anywhere else, andanthropic:account:<uuid>has to match the Account Pooler's key so the same account dedupes.claudeConfigDirectoryresolvesCLAUDE_CONFIG_DIRagainst the session's cwd and treats an empty value as unset. Fork keeps this local rule rather than askingclaude auth status, because that would break users who run only the SDK's bundled binary.Behaviour changes:
expiredis no longer reported. Claude Code refreshes access tokens itself, and the old check called a token expired once its timestamp passed, even with a valid refresh token. A login Claude Code can't use now shows asunauthenticated, and the sign-in action is the same.How you verified
Live, on macOS with Claude Code 2.1.317, calling the real
getClaudeProviderHealthandgetClaudeProviderUsage:accountKeyCLAUDE_CONFIG_DIR= empty profileCLAUDE_CONFIG_DIR= profile with an invalid tokenThe last row is Claude usage check ignores CLAUDE_CONFIG_DIR, reporting expired for a signed-in account #3607's mismatch: main reports the default profile's account while Claude Code itself has no usable login in that profile.
New
provider-maintenance.account.test.ts: usage reports the account and plan Claude Code returns, and keys it from$CLAUDE_CONFIG_DIR/.claude.json. Usage is signed out for a login Claude can't use and for logins without plan limits. Health is ready or signed out from the same account. It fails on main.New
claudeConfigDirectorycases insession-fork.test.ts: a relative path resolves against the session cwd, and unset or empty means~/.claude.pnpm exec turbo run typecheck --filter=bb-plugin-provider-claude-codepasses, and oxlint is clean. Targeted vitest (provider-maintenance*,session-fork,model-list,provider-commands) passes 26 of 26. CI runs the full suites.Fixes #3607
Part of #6688
🤖 Generated with Claude Code