DEV Community

Hojayfa Rahman
Hojayfa Rahman

Posted on

aswap: multi-account switching for the Antigravity CLI, with failover when quota runs out

I use the Antigravity CLI (agy) with more than one Google account. Switching meant signing out and back in, and when an account ran out of quota in the middle of a long task, the task just stopped.

claude-swap solves exactly this for Claude Code, so I built the same thing for agy: antigravity-swap, command aswap.

GitHub logo hrmasss / antigravity-swap

Multi-account switcher for the Antigravity CLI (agy), with automatic rotation and quota-aware failover

antigravity-swap

Multi-account switcher for the Antigravity CLI (agy). Switch between Google accounts without signing out, let aswap switch for you before an account runs out, see every account's quota in one table, and run long print-mode tasks that carry on to the next account when one hits its limit.

Inspired by claude-swap by Onur Cetinkol, which does the same for Claude Code. The command set, the defaults and the auto-switch design come from it; see Credits.

Installation

Using uv (recommended)

uv tool install antigravity-swap
Enter fullscreen mode Exit fullscreen mode

Using pipx

pipx install antigravity-swap
Enter fullscreen mode Exit fullscreen mode

Standalone binary

No Python needed. Linux (x86_64, aarch64) and macOS (Apple silicon):

curl -fsSL https://raw.githubusercontent.com/hrmasss/antigravity-swap/main/install.sh | sh
Enter fullscreen mode Exit fullscreen mode

Windows (PowerShell):

$d = "$env:LOCALAPPDATA\Programs\aswap"; New-Item -ItemType Directory -Force $d | Out-Null
irm https://github.com/hrmasss/antigravity-swap/releases/latest/download/aswap-windows-x86_64.exe -OutFile "
…
Enter fullscreen mode Exit fullscreen mode

Install

uv tool install antigravity-swap
# or: pipx install antigravity-swap
Enter fullscreen mode Exit fullscreen mode

There are also standalone binaries for Linux, macOS and Windows on the releases page, and a one-line installer for Linux and macOS.

Add your accounts

Sign in to agy as usual, then:

aswap add
Enter fullscreen mode Exit fullscreen mode

Sign in with the next account (no need to sign out first) and run aswap add again.

See every account at once

$ aswap list
Accounts:
  1: you@example.com [home] (active)
     ├ Gemini 5h:      23%   resets 13:42         in 4h 34m
     ├ Gemini 7d:       5%   resets Oct 8 18:23   in 6d 9h
     ├ Claude/GPT 5h:   0%   full
     └ Claude/GPT 7d:  33%   resets Oct 6 14:06   in 4d 4h
  2: work@example.com [work]
     ├ Gemini 5h:       0%   full
     ├ Gemini 7d:      44%   resets Oct 5 13:02   in 3d 3h
     ├ Claude/GPT 5h:   0%   full
     └ Claude/GPT 7d:   0%   full

Running instances:
  ● TUI    ~/code/app      1: you@example.com [home]   (2 sessions)
Enter fullscreen mode Exit fullscreen mode

agy meters two pools separately, the Gemini models and the Claude/GPT models, each with a 5-hour and a weekly window. aswap list shows both, with reset times, and every agy session running on the machine with the account it is on.

Switch

aswap switch            # next account
aswap switch work       # by number, email or alias
aswap switch --strategy most-quota
Enter fullscreen mode Exit fullscreen mode

After a switch, aswap runs agy models to prove the login works. That call lists models and spends no quota.

The part I actually wanted: keep a session going

aswap run
Enter fullscreen mode Exit fullscreen mode

aswap run starts agy in your terminal and watches its log. When the account hits its quota, aswap:

  1. holds that account out until the reset time agy reports,
  2. picks the next account with the most quota left,
  3. restarts agy on that account with the same conversation and a short "please continue" prompt.

You see agy restart and pick the task back up. For scripts and unattended runs, aswap exec -- -p "..." does the same for print mode.

Why a restart and not a swap in place?

claude-swap can change the account under a live Claude Code session, because Claude Code re-reads its credentials file. agy keeps its login in memory for the life of the process. I tested it: replacing the login file under a running agy changes nothing. So aswap restarts on the same conversation, which works because agy stores conversations as local files that any account can resume with --conversation <id>.

Two details mattered:

  • agy retries a quota error a couple of times before giving up. aswap only reacts to the final error that ends the turn, so a retry never kills a healthy session.
  • A fresh agy directory opens on the first-run theme picker. aswap carries over the "setup finished" flag, so a restart lands straight in the conversation.

Strategies

Strategy Also called Picks
best most-quota most quota left (default)
rotate round-robin next account by number
next-available next account that still has quota
consume-first soonest-reset the account whose weekly quota resets soonest

There is also aswap auto, which watches the active account and switches before it runs out, with a threshold, hysteresis and a cooldown so two accounts near the limit never ping-pong. That design comes straight from claude-swap.

Platforms

On Linux each account gets its own agy directory, so several accounts run side by side. On Windows, agy keeps one login per machine in Credential Manager, so aswap switches that login, and briefly swaps a non-active account in to renew its token so its quota stays visible.

Credits

The command set, the defaults and the auto-switch design are borrowed from claude-swap by Onur Cetinkol. No code was copied; agy's login and session model needed its own implementation. MIT licensed, issues and PRs welcome.

Top comments (0)