Skip to content

feat(anthropic): multi-account support (ANTHROPIC_TOKEN_<NAME> / anthropic-profiles) - #154

Open
Itstommy10 wants to merge 1 commit into
onllm-dev:mainfrom
Itstommy10:feature/anthropic-multi-account
Open

Itstommy10 wants to merge 1 commit into
onllm-dev:mainfrom
Itstommy10:feature/anthropic-multi-account

Conversation

@Itstommy10

Copy link
Copy Markdown
Contributor

Summary

Adds multi-account support for the Anthropic (Claude) provider, modeled on the existing Codex/MiniMax multi-account support.

  • The primary account (ANTHROPIC_TOKEN or auto-detected Claude Code credentials) is unchanged and stored as account_id = 0; all existing data stays with it.
  • Extra accounts: ANTHROPIC_TOKEN_<NAME> (+ optional ANTHROPIC_REFRESH_TOKEN_<NAME>) seeds <data dir>/anthropic-profiles/<name>.json, or drop a Claude Code .credentials.json there directly. Docker friendly (/data volume).
  • Each account gets its own provider_accounts row, client, tracker and agent. Snapshots and reset cycles are stored per account (account_id column, migration with default 0).
  • OAuth refresh/rotation per account: rotated tokens are written only to that account's profile file, so one-time-use refresh tokens are never shared. The env seed is fingerprinted, so restarts keep rotated tokens and changing the env value re-seeds.
  • Statusline bridge, Claude Code detection and sessions stay on the primary (local) account.
  • Web: ?account=<id> on current/history/cycles, GET /api/anthropic/accounts, anthropicAccounts in the all-providers payload, per-account Telemetry/Dashboard toggles in Settings > Providers (anthropic:<id>), per-account cards on the Anthropic tab and in the All view.
  • Docs: docs/ANTHROPIC_ACCOUNTS.md, README env table.

Not in this PR

Insights, cycle overview, menubar, logging history and metrics remain primary-account only. Accounts are loaded at startup (restart to apply). At most 20 extra accounts.

Test plan

  • New tests: store account isolation, profile seeding/rotation/re-seed, profile loading, per-account credentials writer, agent stores under its account, web current/both/history/accounts endpoints, per-account toggle
  • go vet ./... and go test -race ./... (4754 passed, 0 failed)
  • docker build
  • Manual check with two real Claude accounts

@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

@Itstommy10

Copy link
Copy Markdown
Contributor Author

The only failing check is Test (Windows) → TestDaemonChildRun_DefaultPassword, which fails in TempDir RemoveAll cleanup: ... The directory is not empty after the test body passed. This looks like the known Windows file-handle race in the daemon subprocess tests (e.g. TestDaemonChildRun_DebugModeAllProvidersWithCopilot failed the same way on fix/menubar-never-blank-cursor-codex-resets). Could you re-run the job? Happy to adjust if it turns out to be related.

Track several Claude accounts at once. The primary account (ANTHROPIC_TOKEN
or auto-detected Claude Code credentials) is unchanged and stored as
account_id 0. Extra accounts come from ANTHROPIC_TOKEN_<NAME> (+ optional
ANTHROPIC_REFRESH_TOKEN_<NAME>) env vars, which seed
<data dir>/anthropic-profiles/<name>.json, or from Claude Code style
credential files dropped into that directory.

- store: account_id column on anthropic_snapshots/anthropic_reset_cycles
  (default 0), *ForAccount query variants, legacy functions keep working
- tracker/agent: per-account tracker and agent; rotated OAuth tokens are
  written only to that account's profile file (one-time-use refresh
  tokens are never shared); statusline and Claude Code guard stay on the
  primary account
- provider_accounts rows per extra account, soft-deleted when removed
- web: ?account= on current/history/cycles, /api/anthropic/accounts,
  anthropicAccounts in the all-providers payload, per-account
  telemetry/dashboard toggles (anthropic:<id>)
- docs: docs/ANTHROPIC_ACCOUNTS.md, README env table

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Itstommy10
Itstommy10 force-pushed the feature/anthropic-multi-account branch from 0c63a44 to 2e1ab14 Compare October 22, 2026 13:13
@prakersh

Copy link
Copy Markdown
Contributor

Thanks for the multi-account work. The storage side is careful and consistent, and the profile credential handling is well thought out. A few things need fixing before we can merge.

  1. A profile holding the same credentials as the main account can refresh them while Claude Code is running and save the result only into that profile, leaving Claude Code with an already-used refresh token. Please refuse or de-duplicate shared credentials, including when profiles are reloaded.

  2. Changing only ANTHROPIC_TOKEN_WORK after a rotation restores the original refresh token. The current test expects that behaviour. Please keep the rotated token, or reject the change.

  3. In Docker with only extra accounts and no main token, Anthropic counts as unconfigured, so saving Settings stops polling. Please treat extra accounts as configured.

Smaller items: every account reports its poll result under the same key, so one can clear another's error; a bad ?account= value returns the main account; turning off the default account hides it in one view but not the other; and extra accounts show "Collecting data..." because their history is always empty.

Tests should use fakes only, with no real Claude credentials or OAuth calls.

If you would rather we take this over, say so and we will pick it up from your branch. Either way, thanks for the careful work.

@Itstommy10

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review, and for merging #156.

All the points make sense, in particular the shared-credential case (1) and keeping the rotated token after an env change (2); I had not considered a profile holding the same OAuth credentials as the main account. Given the number of items and the test rework (fakes only), I would gladly take you up on the offer: please feel free to take this over from the branch. I will not push further commits to feature/anthropic-multi-account so you can build on it as is.

For what it is worth, the setup I have been running it on: 2 extra accounts seeded via ANTHROPIC_TOKEN_<NAME> in Docker, each with its own .credentials.json copied from a separate CLAUDE_CONFIG_DIR login, so no profile shared credentials with the main account. Per-account polling and OAuth rotation have been working on that setup since 2026-10-22.

Happy to test a revised branch against real accounts when you have one. Thanks again!

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.

2 participants