claude-code-usage-bar icon indicating copy to clipboard operation
claude-code-usage-bar copied to clipboard

Account stores ignore CLAUDE_CONFIG_DIR: two profiles share one rate_latest bucket

Open kossolax opened this issue 2 months ago • 0 comments

Running a second Claude Code profile via CLAUDE_CONFIG_DIR (e.g. a personal and a work login on one machine) makes both profiles write into the same account bucket, so the last session to render sets the 5h/7d figures for both bars. A work session's usage shows up on the personal bar and vice versa.

This is the same leak the per-account keying in predict.py was introduced to prevent (the 2026-06-11 incident in the header comment) — it just does not cover the config-dir case.

Cause

_read_account_id() reads ~/.claude.json unconditionally:

_CLAUDE_JSON_PATH = Path(os.path.expanduser("~")) / ".claude.json"

But CLAUDE_CONFIG_DIR gives a profile its own login file at $CLAUDE_CONFIG_DIR/.claude.json, so ~/.claude.json is not that session's identity. Both profiles resolve to the default account's uuid, hence one bucket. CLAUDE_CONFIG_DIR appears nowhere in src/.

The forecast spec already states the intended behaviour — docs/superpowers/specs/2026-06-02-rate-limit-forecast-design.md, line 74:

~/.cache/claude-statusbar/rate_history.json (respects CLAUDE_CONFIG_DIR/HOME the same way other cache paths do)

So this reads as code/spec drift rather than a feature request.

Reproduction

Two profiles, two accounts:

profile account uuid bucket written
default (~/.claude) 2b094ee5-… rate_latest.2b094ee5-49f.json
CLAUDE_CONFIG_DIR=~/.claude-boulot 1c7f9277-… rate_latest.2b094ee5-49f.json ← wrong

No bucket is ever created for the second account.

The catch: the environment alone is not enough

Reading os.environ["CLAUDE_CONFIG_DIR"] fixes the inline path but is still wrong under fast mode: daemon._render_payload() runs core.main() in-process, and render_worker.main() loops over many sessions' payloads in one long-lived process. That process's environment names the daemon's profile, not the session's.

The payload already carries the per-session answer. transcript_path is <config dir>/projects/<slug>/<id>.jsonl, and core already parses it:

/home/u/.claude-boulot/projects/-home-u-proj/d4ebdb02-….jsonl

Proposed fix

Derive the config dir from transcript_path, falling back to CLAUDE_CONFIG_DIR (resolved at import) and then ~, with an unrecognised layout falling back rather than keying by a wrong uuid. Correct in both process models, no new per-render cost beyond the existing stat().

PR follows. Happy to restructure if you would rather thread this differently — e.g. resolve once in parse_stdin_data instead of per store-path call.

Environment

  • cs --version: 3.36.0 (bug confirmed unchanged at main a36a0b5 / v3.43.1)
  • Claude Code 2.1.272, Linux, pip install

kossolax avatar Sep 15 '26 13:09 kossolax