Why my saved Claude Code logins kept dying, and the switcher I built around it
说明与用途
claude-switch 自动管理 Claude Code 的 OAuth 令牌,实现多账户切换,避免令牌失效。
问题
Claude Code logins become invalid after a single use of the refresh token, causing sessions to expire when switching accounts.
结果
The tool keeps the most recent login, respects OAuth single-use tokens, uses locks to avoid race conditions, and warns when a login is dead, enabling seamless switching between multiple Claude accounts.
工作流
- 1. Install claude-switch via pipx.
2. Save the current account with
claude-switch save <name>. 3. Add a new account withclaude-switch add <name>and authenticate via browser. 4. Save the new account. 5. List accounts withclaude-switch list. 6. Switch accounts withclaude-switch use <name>orclaude-switch auto. 7. Continue conversation in an open session by exiting and restarting Claude withclaude -c.
证据
Claude Code signs in with OAuth. It holds a short-lived access token, about 8 hours, and a refresh token. When the access token runs out, Claude Code trades the refresh token for a new pair and writes both back.
The server accepts each refresh token once. After a renewal, the old one is dead.
claude-switch keeps one Claude Code profile and swaps only the login.
It takes Claude Code's own locks during the swap, in the same order Claude Code takes them, so no running session renews or rewrites the login halfway through.
It refuses to file one account's login under another name. It compares logins by a SHA-256 hash of the refresh token and by the email Claude Code records.
- 记录日期: 2026-11-02T21:14:03.129Z