If you juggle two or three Google accounts with Google Antigravity (agy), you eventually notice an odd bug after switching accounts manually. You switch to Account B, start a coding session, and an hour later Antigravity silently flips back to Account A.

No crash happened, and nobody ran a login command. Another agy process running in a forgotten terminal or IDE workspace simply refreshed its hourly OAuth token and wrote the updated credentials back into the shared local state under ~/.gemini.

Here is why that race happens, how the open-source terminal switcher agy-swap isolates switches and harvests background refreshes without clobbering your active account, and how to run two completely separate accounts side by side when you need concurrent agents.

Why switching accounts by hand often reverts an hour later

Both the standalone agy CLI and the Antigravity IDE read and write shared credential files under ~/.gemini alongside your system keychain entry. Suppose Terminal 1 started earlier under Account A, and an hour later you sign out and sign into Account B in Terminal 2 (or inside the IDE).

Terminal 1 still holds Account A's OAuth refresh token in memory. When Terminal 1's access token expires, it calls Google OAuth, receives a new access token for Account A, and writes that session straight back to disk. Whatever you switched to in Terminal 2 gets overwritten on disk without warning.

On macOS, frequent reads and writes against the login keychain by credential helpers can also trigger repeated OS password prompts right in the middle of a coding loop.

What one safe account switch updates locally

Instead of asking you to sign out in a browser, agy-swap saves each OAuth session once (agy-swap add) and performs atomic updates guarded by advisory file locks (flock on Unix, LockFileEx on Windows) with automatic rollback if any write step fails:

  1. Writes the target account's OAuth session (file permissions 0600) under ~/.gemini for agy CLI, IDE, and Jetski.
  2. Mirrors the active session into the OS keychain via /usr/bin/security on macOS, secret-tool on Linux, or Windows Credential Manager.
  3. On macOS and Linux, updates the signed-in email label inside state.vscdb when sqlite3 is installed so the IDE UI stays consistent.
  4. Drops a reload marker on macOS and Linux so the background agy --hub service restarts cleanly under the new account without forcing you to close the IDE window.

Harvesting background token refreshes with --sync-session

Updating the active session atomically solves half the problem. The other half is stopping older agy processes in other directories from overwriting that switch later.

When agy-swap configures its launcher guard (either automatically or through agy-swap install-agy), it installs lightweight wrappers at ~/.local/bin/agy and ~/.gemini/bin/agy, moving the real binary to ~/.local/libexec/agy (or .agy.real) and updating size and modification metadata in agy.version.json so the IDE trusts the launcher.

Whenever a wrapped agy process exits or completes a refresh, agy-swap --sync-session inspects the refreshed session token on disk:

 older workspace `agy` refreshes Account A token │ ▼ wrapper runs `agy-swap --sync-session` │ matches `refresh_token` in vault │ ┌─────────────┴─────────────┐ ▼ ▼ updates Account A row keeps Account B active inside `vault.json` as your selected session 

Because tokens are matched by refresh_token against saved accounts rather than blindly trusting whichever account happened to write last, Account A receives its fresh token cleanly inside your vault while Account B stays active across your workspace.

If switching ever reverts unexpectedly, agy-swap doctor checks both ~/.local/bin/agy and ~/.gemini/bin/agy to verify that every shell invocation passes through the wrapper.

Checking 5-hour, weekly, and Gemini 4 Argon pools before hitting HTTP 429

Quota starvation is usually what drives people to switch accounts in the first place. Antigravity meters three separate quota pools rather than one global counter:

  • Gem (Gemini) enforces both a 5-hour rolling window and a 7-day weekly cap, and agy-swap displays whichever remaining percentage is tighter.
  • C/G (Claude and GPT) shares an independent 5-hour rolling window and 7-day weekly cap alongside Gemini.
  • Argon (Gemini 4 Argon) tracks a separate weekly ceiling on Pro plans and renders in its own detail panel so an exhausted Argon pool never marks standard Gemini or Claude/GPT quota as LIMITED.

The TUI refreshes your active account every 20 seconds (or roughly 10 seconds after agy writes logs) and idle accounts every 2 minutes, converting reset timestamps to your local timezone with clock skew compensation. From scripts or agent loops, you can inspect and rotate accounts directly:

# Inspect 5-hour windows, weekly ceilings, and local reset timestamps agy-swap limits --refresh --verbose # Rotate automatically to the next account with Claude/GPT quota left agy-swap next --family claude # Put a noisy account on a 6-hour cooldown for Claude/GPT agy-swap limit set 1 6h --group claude # Bind a repository profile with sticky, balanced, or round-robin ranking agy-swap profile set work work-account --family claude --policy sticky --threshold 15 agy-swap bind set /path/to/repo work --mode recommend agy-swap run now 

See the Quota Limits Guide for status badge behavior (READY, LOW, GEMINI ONLY, CLAUDE/GPT ONLY, LIMITED, VERIFY) and agy-swap verify recovery steps when Google returns HTTP 403.

Running two separate accounts simultaneously in two terminals

Directory bindings and agy-swap run now select an account before launching in your shared Antigravity session, which covers jumping between work and personal repos one at a time. When you actually need two standalone agy CLI agents running at the exact same moment under two different Google accounts on macOS or Linux, launching a second process without isolation still collides in the shared OS keychain.

Creating an isolated HOME directory with the file-backed keyring marker avoids that collision (Parallel Sessions Guide):

AGY_BIN="$HOME/.local/libexec/agy" [ -x "$AGY_BIN" ] || AGY_BIN="$(command -v agy)" PROFILE_HOME="$HOME/.agy-homes/account-b" mkdir -p "$PROFILE_HOME/.gemini/antigravity-cli/cache" touch -t 203601010000 "$PROFILE_HOME/.gemini/antigravity-cli/cache/antigravity-keyring-unavailable" HOME="$PROFILE_HOME" AGY_SWAP_SKIP_SYNC=1 WSL_INTEROP=1 "$AGY_BIN" 

Setting WSL_INTEROP=1 alongside antigravity-keyring-unavailable instructs agy to keep its OAuth credentials inside $PROFILE_HOME/.gemini instead of touching your global macOS Keychain or Linux Secret Service, while AGY_SWAP_SKIP_SYNC=1 stops the isolated instance from firing global session sync.

Local-first storage details without hand-waving

agy-swap runs strictly on your workstation with zero telemetry, analytics, or crash-reporting endpoints:

  1. Saved account tokens live in vault.json inside your config directory with file permissions 0600. By default, vault.json is not encrypted so headless shells and non-interactive --sync-session hooks never hang waiting for a passphrase.
  2. Desktop users who want hardware or OS keystore protection can export AGY_SWAP_VAULT=keychain (using native Security.framework on macOS, Windows Credential Manager, or Linux Secret Service) and run agy-swap account migrate.
  3. Secret archives (agy-swap backup export --include-secrets) encrypt payloads using AES-GCM with 600,000 PBKDF2-HMAC-SHA256 iterations, and tokens are redacted from logs and CLI output.

The full network endpoint list and backup recovery behavior are documented on the Security page.

Getting started

On macOS with Homebrew:

brew install aklkbqx/agy-swap/agy-swap 

Linux and Windows installers (SHA-256 verified) plus shell completion and Starship/tmux/zsh statusline setup instructions are on the project website, and the Go source code is MIT-licensed at github.com/aklkbqx/agy-swap.