Claude --source cli all-accounts reports incorrect per-account usage
Summary
codexbar usage --provider claude --source cli --all-accounts can return incorrect per-account usage in a multi-account Claude setup.
In my environment, CLI source reports identical exhausted values for multiple accounts, while OAuth source (and direct OAuth usage checks) show different usage per account as expected.
Environment
- CodexBar CLI version:
2.1.47 - OS: macOS (Apple Silicon)
- Claude setup: multiple token accounts configured in CodexBar
- Accounts intentionally have different real usage states
Expected behavior
--source cli should return usage scoped to each requested Claude account (or match OAuth source results for the same account).
Actual behavior
--source cli --all-accounts reports duplicated / incorrect usage across accounts.
Example symptom:
<ACCOUNT_A>truly exhausted weekly (100%)<ACCOUNT_B>has remaining weekly quota (e.g., ~29% left / ~71% used)--source clireports both as exhausted
Reproduction steps
- Configure at least two Claude accounts in CodexBar
tokenAccounts. - Ensure accounts have different usage.
- Run:
codexbar usage --provider claude --source oauth --json --all-accounts --log-level error
codexbar usage --provider claude --source cli --json --all-accounts --log-level error
- Compare outputs per account.
Example output (sanitized)
OAuth source (correct / distinct per account)
[
{
"account": "<ACCOUNT_A>",
"source": "oauth",
"usage": { "primary": { "usedPercent": 0 }, "secondary": { "usedPercent": 100 } }
},
{
"account": "<ACCOUNT_B>",
"source": "oauth",
"usage": { "primary": { "usedPercent": 1 }, "secondary": { "usedPercent": 71 } }
}
]
CLI source (incorrect / duplicated)
[
{
"account": "<ACCOUNT_A>",
"source": "claude",
"usage": { "primary": { "usedPercent": 0 }, "secondary": { "usedPercent": 100 } }
},
{
"account": "<ACCOUNT_B>",
"source": "claude",
"usage": { "primary": { "usedPercent": 0 }, "secondary": { "usedPercent": 100 } }
}
]
Additional diagnostics
I verified credentials are synchronized across:
- CodexBar account config
- Claude profile credential files
- Shared secret export used by related tools
I also tested Claude CLI account scoping behavior:
CLAUDE_CODE_PROFILE=<PROFILE> claude -p ...did not reliably switch usage context in this setup.CLAUDE_CONFIG_DIR=<PROFILE_CONFIG_DIR> claude -p ...did switch correctly.
This suggests CLI probing may not be binding the account context robustly per account.
Suspected root cause
In Claude source=cli probing, account context is not explicitly pinned per account (e.g., missing config-dir scoping), so usage can be read from the wrong active context and then attributed to multiple accounts.
Suggested fix
One of these approaches should resolve it:
- For Claude CLI probing, set explicit account config context per probe (for example via per-account config directory).
- Internally route Claude CLI-source usage to OAuth-source implementation when OAuth tokens are available.
- Add a regression test with two accounts returning intentionally different usage and assert distinct per-account output for
--all-accounts.
Acceptance criteria
- With at least two accounts having different usage,
--source cli --all-accountsreturns correct per-account values (not duplicated). - Results are consistent with
--source oauth --all-accountswithin normal freshness windows.
Impact
This can cause automated account selection to pick an exhausted account even when another account has available quota, creating avoidable failures/retries.
Current workaround
Use OAuth source for Claude usage checks:
codexbar usage --provider claude --source oauth ...
instead of:
codexbar usage --provider claude --source cli ...
Related
Possibly related to #215 (usage mismatch report), but this issue is specifically about multi-account --source cli behavior.
Follow-up repro that may help narrow root cause:
I tested switching the Claude activeIndex in ~/.codexbar/config.json and observed the app-level snapshot for Claude flips entirely to whichever account is active.
Repro
- Set Claude
activeIndex=0in~/.codexbar/config.json - Restart CodexBar
- Inspect
~/Library/Group Containers/group.com.steipete.codexbar/widget-snapshot.json - Note Claude entry values (example from my run):
secondary.usedPercent = 100primary.usedPercent = 0
- Set Claude
activeIndex=1 - Restart CodexBar
- Inspect same snapshot file again
- Claude entry now flips (example from my run):
secondary.usedPercent = 73primary.usedPercent = 16
Then switching back to activeIndex=0 flips back to the first values.
Interpretation
This suggests the app snapshot/state for Claude may be sourced from the currently active account and then reused broadly, instead of maintaining independent per-account snapshot values for multi-account display/probing.
This aligns with the --source cli --all-accounts behavior in the issue body where values can appear duplicated across accounts.
Happy to run any debug build / extra probes if useful.
I'm going to take a look at this on current main and see whether I can reproduce it cleanly and cut a small fix from there.
I took a read-only pass through current main, and I think this is a real issue.
The likely problem seems to be that --source cli --all-accounts does iterate over Claude token accounts, but the CLI path does not appear to bind each fetch to a distinct Claude CLI account context. So multiple accounts can end up reading the same active CLI context and then get relabeled as separate per-account results.
From what I can see, there are probably two reasonable ways to fix it:
-
A small / safe fix: make this path honest and deterministic by avoiding per-account CLI results when the account is not actually CLI-scoped (for example, falling back to OAuth for OAuth-backed Claude accounts, or failing explicitly for unsupported multi-account CLI cases), plus a regression test.
-
A larger fix: add true per-account CLI scoping for Claude (for example via config-dir based context binding), then keep
--source cli --all-accountsfully per-account.
My instinct would be to start with (1) as the smaller current-main fix unless there is a strong preference for going straight to (2). Happy to put together that smaller PR if that direction makes sense.
Fixed on main in 29386fe7.
Proof:
- Added regression coverage for Claude
--all-accountswith explicit--source cliover OAuth and session token accounts. - Verified selected-account rerouting uses OAuth for bearer accounts and web/session cookie routing for session-key accounts, so ambient CLI usage is not relabeled.
- Ran
swift testand the focused token-account shard.
Closing as fixed for the next release.