mrwick/notebook

drag or arrow keys to move · scroll to zoom · esc to exit

Two Claude accounts behind one proxy

I have two Claude subscription accounts, a personal account and a work account. I run coding agents on three machines. I wanted one place that decides which account each chat uses, so I do not switch by hand.

The setup

One proxy runs on my main machine. It is CLIProxyAPI, a small open source server. It holds both account tokens. The coding tool on each machine sends its requests to the proxy with a dummy key. The proxy swaps in a real token and forwards the request.

agent tool --ANTHROPIC_BASE_URL--> proxy --real token--> api.anthropic.com

The proxy listens on the private network only. The dummy key only names the machine in the proxy log.

Who picks the account

Both accounts stay enabled. Each one has a priority number in its auth file. New chats go to the account with the highest priority.

A timer runs every 5 minutes. It reads the usage of each account and sets the priorities. The rules are plain code:

  1. An account with a 5-hour use above 85% or a weekly use of 95% or more is limited. The timer never picks a limited account when another one is free.
  2. Otherwise the timer picks the account with the most weekly use left per hour until its reset. It switches only when that need is 1.15 times higher than the current account’s need.

The 1.15 margin stops flapping. A switch means a cold prompt cache. If a usage reading is older than 10 minutes, the timer keeps the current account.

Running chats stay put

The proxy has session-affinity on, with a 6 hour lifetime. A chat that starts on one account stays on it. Only new chats follow the timer.

The manual override

proxy use <account> sets the account by hand. It also pauses the timer for 2 hours. proxy auto hands control back.

A measured trap

A custom base URL makes Claude Code turn tool search off. Then every MCP tool schema goes into each prompt. I measured this on 2026-10-06 by replaying a session:

My usage drained fast until I found it. Setting ENABLE_TOOL_SEARCH=true in the service environment brought the proxy to the direct numbers.

A second trap: with one token variable, Claude Code asks for the 5-minute prompt cache. With the other, it asks for the 1-hour cache. Cache writes grew 10 to 30 times on the wrong one.

Still open