Skip to content

feat(account): add account module with cache invalidation on account switch#153

Draft
nh13 wants to merge 3 commits intostephenleo:mainfrom
nh13:nh13/feat-account-display
Draft

feat(account): add account module with cache invalidation on account switch#153
nh13 wants to merge 3 commits intostephenleo:mainfrom
nh13:nh13/feat-account-display

Conversation

@nh13
Copy link
Copy Markdown

@nh13 nh13 commented Apr 12, 2026

Summary

  • Account profile display: new cship.account module fetches organization and account
    metadata from the /api/oauth/profile OAuth endpoint, letting users see at a glance
    whether they're on their work or personal Claude account
  • Label mapping: opt-in [cship.account.labels] table maps raw organization names to
    user-friendly labels (e.g. "Fulcrum Genomics" = "work", "Personal Workspace" = "personal")
  • Format string placeholders: {label}, {organization}, {display_name}, {email},
    {tier}, {type} — default format is {label} (resolved label or raw org name)
  • 24h cache: profile data rarely changes, so the default TTL is 86400s (configurable
    via ttl). Stale cache is used as fallback when the API fetch times out.
  • Cache invalidation on account switch: a token fingerprint (last 16 chars of OAuth
    token) is stored in both the usage limits and account profile cache envelopes. On every
    cache read, the current token is re-read from the OS credential store and its fingerprint
    is compared. A mismatch (e.g. after /login to a different account) invalidates the
    cache immediately — even stale fallback reads — preventing stale data from the wrong
    account from being displayed.
  • Shared fetch_with_timeout<T>(): extracted generic timeout wrapper to
    modules/mod.rs

Test plan

  • cargo fmt — passes
  • cargo clippy -- -D warnings — passes (lib clean; pre-existing warnings in
    explain.rs/cli.rs are addressed by fix: resolve clippy warnings in explain and cli tests #151)
  • cargo test — 356 unit + 66 integration tests pass (includes tests for
    API parsing, cache hit/miss/TTL/stale, format rendering, label resolution, render
    entry points, fingerprint match/mismatch/stale/backwards-compat)
  • cargo build --release — builds successfully
  • End-to-end verified against real /api/oauth/profile endpoint

nh13 added 3 commits April 11, 2026 16:37
Adds a placeholder Unreleased entry for an upcoming cship.account
module that will display the currently authenticated Anthropic
account (work vs personal) via the /api/oauth/profile OAuth
endpoint. No implementation yet — this commit exists so the
feature can be tracked via a draft PR while design is firmed up.
…play

Add a new native module that fetches the current Anthropic account
profile from the /api/oauth/profile OAuth endpoint and renders the
organization name (or a user-defined label) in the statusline, so
users can see at a glance whether they're on their work or personal
Claude account.

- AccountProfile struct + API parser in src/account.rs
- Render module with format-string placeholders ({label},
  {organization}, {display_name}, {email}, {tier}, {type})
- Opt-in label mapping via [cship.account.labels] BTreeMap
- 24h cache with stale fallback on fetch timeout
- Shared fetch_with_timeout<T>() in modules/mod.rs
- explain.rs updated with is_disabled + config_section_for arms
- 22 new tests (parser, cache, render, label resolution)
Add a token fingerprint (last 16 chars of OAuth token) to the usage
limits and account profile cache envelopes. On every cache read, the
current token is read from the OS credential store and its fingerprint
is compared against the stored value. A mismatch (indicating an account
switch via /login) invalidates the cache immediately, even for stale
fallback reads.

Changes:
- platform.rs: add token_fingerprint() derivation function
- cache.rs: add token_fingerprint field to both cache envelopes,
  update read/write signatures with expected_fingerprint parameter
- account.rs: restructure render() to read token up front, pass
  fingerprint to all cache calls
- usage_limits.rs: restructure resolve_data/fetch_and_cache to
  compute fingerprint up front, pass to cache calls
@nh13 nh13 changed the title feat(account): add cship.account module for displaying authenticated Anthropic account feat(account): add account module with cache invalidation on account switch Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant