The Claude subscription often showed as signed out over the last few days. Claude's refresh tokens are single-use. Once one is refreshed, every other copy holding the old one is dead: the next refresh with it fails with invalid_grant, and Claude Code then empties its sign-in. Two places kept an old copy.
1. A switch saved the outgoing account from magpie's credential cache, which can be up to 10s old. If Claude Code refreshed in that window, the saved login held the spent refresh token. Switching back then signed the account out. The switch now forgets the cache and reads the credential fresh.
2. The gateway keeps idle Claude Code runs in an account's own folder (CLAUDE_CONFIG_DIR) for up to an hour, each holding that account's token in memory. Once the account is handed to Claude Code's own home, both sides refresh the same token, and the loser is signed out. A switch now tells the gateway (provider.ClaudeHandedOver), which ends that account's idle runs. Runs in a home of their own are left alone.
TestClaudeSwitchSavesTheFreshCredential (the refreshed token is saved, and the gateway is told) fails without the change. TestClaudeHandOverLetsGoOfTheAccountsRuns (only the account's idle runs in its folder are closed, matched case-insensitively; -race) does not build without it.
go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass. TestClaudeRunEndsWhenTheClientLeaves failed once under load, then passed 5/5 alone and with the whole package.