Why my saved Claude Code logins kept dying, and the switcher I built around it
Описание и применение
Инструмент claude-switch позволяет переключаться между несколькими аккаунтами Claude Code, автоматически управляя токенами и предотвращая их истечение.
Задача
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