Skip to content

Claude --source cli all-accounts reports incorrect per-account usage #403

@0xble

Description

@0xble

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 cli reports both as exhausted

Reproduction steps

  1. Configure at least two Claude accounts in CodexBar tokenAccounts.
  2. Ensure accounts have different usage.
  3. 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
  1. 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:

  1. For Claude CLI probing, set explicit account config context per probe (for example via per-account config directory).
  2. Internally route Claude CLI-source usage to OAuth-source implementation when OAuth tokens are available.
  3. 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-accounts returns correct per-account values (not duplicated).
  • Results are consistent with --source oauth --all-accounts within 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions