Skip to content
 
 

Repository files navigation

Antigravity OAuth Plugin for OpenCode

License: MIT

Enable Opencode to authenticate against Antigravity (Google's IDE) via OAuth so you can use Antigravity rate limits and access models like gemini-3.1-pro and claude-opus-4-6-thinking with your Google credentials.

What You Get

  • Claude Opus 4.6, Sonnet 4.6 and Gemini 3.1 Pro / 3.8 Flash via Google OAuth
  • Multi-account support — add multiple Google accounts, auto-rotates when rate-limited
  • Modern Gemini API support — use Antigravity SDK-style API keys / Cloud Projects as Gemini backups or opt-in primary routing
  • Thinking models — extended thinking for Claude and Gemini 3 with configurable budgets
  • Google Search grounding — enable web search for Gemini models (auto or always-on)
  • Auto-recovery — handles session errors and tool failures automatically
  • Plugin compatible — works alongside other OpenCode plugins (oh-my-opencode, dcp, etc.)

⚠️ Terms of Service Warning — Read Before Installing

[!CAUTION] Using this plugin (and any proxy for Antigravity) violates Google's Terms of Service. A number of users have reported their Google accounts being banned or shadow-banned (restricted access without explicit notification).

By using this plugin, you acknowledge:

  • This is an unofficial tool not endorsed by Google
  • Your account may be suspended or permanently banned
  • You assume all risks associated with using this plugin

Installation

This fork is installed directly from a local checkout.

1. Clone and build

git clone https://github.com/NightCorpse/opencode-antigravity-auth.git
cd opencode-antigravity-auth
npm install
npm run build
pwd

Node.js 20 or newer is required. npm install also attempts to create the opencode-agy and opencode-antigravity commands in ~/.local/bin (or $XDG_BIN_HOME). The repository can be cloned anywhere. The final pwd command prints the value to use in place of <REPOSITORY_PATH> below.

2. Load the local plugin

Edit ~/.config/opencode/opencode.json and replace <REPOSITORY_PATH> with the path printed by pwd.

OpenCode V2

V2 uses the plural key plugins and loads the repository directory:

{
  "$schema": "https://opencode.ai/config.json",
  "plugins": [
    "<REPOSITORY_PATH>"
  ]
}

For example, <REPOSITORY_PATH> might be /home/user/projects/opencode-antigravity-auth. OpenCode V2 resolves the package entrypoint from that directory and loads the V2 adapter exported by dist/index.js.

OpenCode V1

V1 uses the singular key plugin and points to the compiled V1 plugin file:

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": [
    "file://<REPOSITORY_PATH>/dist/src/plugin.js"
  ]
}
OpenCode version Configuration key Local target
V1 plugin dist/src/plugin.js file
V2 plugins repository directory

Do not point V1 at the repository directory: its default package export is the V2 adapter. After pulling changes, run npm install when dependencies changed, then npm run build, and restart OpenCode.

Because this installation is managed with Git rather than a package registry, disable package update checks in ~/.config/opencode/antigravity.json:

{
  "auto_update": false
}

3. Authenticate

opencode auth login

Current OpenCode versions load plugin models dynamically. If your version still requires static provider configuration, run opencode-agy and select Configure models in opencode.json, or copy the full configuration.

4. Verify

opencode run "Hello" --model=google/antigravity-claude-opus-4-6-thinking --variant=max

Local account manager

opencode-agy and opencode-antigravity are aliases for the same interactive account manager:

opencode-agy
# or
opencode-antigravity

Use it to:

  • add, remove, refresh, enable, or disable OAuth accounts;
  • verify one account or all configured accounts;
  • view the available quota and reset time for each account;
  • clear the stored accounts and authenticate again;
  • write the current model definitions to opencode.json.

If the commands are not found, ensure the user binary directory is on PATH:

export PATH="$HOME/.local/bin:$PATH"
npm run link-bin

Models

Model Reference

Antigravity quota (default routing for Claude and Gemini):

Model Variants Notes
antigravity-gemini-3-pro low, high Discontinued by Google
antigravity-gemini-3.1-pro low, high Gemini 3.1 Pro with thinking (rollout-dependent)
antigravity-gemini-3-flash minimal, low, medium, high Gemini 3 Flash with thinking
antigravity-gemini-3.5-flash minimal, low, medium, high Discontinued by Google
antigravity-gemini-3.6-flash low, medium, high Gemini 3.6 Flash with thinking (medium default)
antigravity-gemini-3.7-flash minimal, low, medium, high Gemini 3.7 Flash with thinking
antigravity-gemini-3.8-flash low, medium, high Gemini 3.8 Flash with thinking (medium default)
antigravity-claude-sonnet-4-6 — Claude Sonnet 4.6
antigravity-claude-opus-4-6-thinking low, max Claude Opus 4.6 with extended thinking

Antigravity SDK / Gemini API projects (API-key backed; used by API-key auth, or as OAuth fallback when configured):

The official Antigravity SDK uses GEMINI_API_KEY for local Gemini access. This plugin now supports that path directly for Gemini models while keeping OAuth accounts for Antigravity and Claude.

Routing behavior:

  • OAuth requests use Antigravity quota and rotate across configured Google accounts.
  • API-key auth, GEMINI_API_KEY, or configured agy_sdk.cloud_projects route Gemini requests through the public Gemini API.
  • Configured public Gemini API projects can provide backup capacity when agy_sdk.enabled: true, agy_sdk.api_key_fallback: true, and usable API-key credentials are present.
  • Set agy_sdk.prefer_for_gemini: true to use the public Gemini API before OAuth-backed Antigravity for Gemini models.
  • Claude and image models always use Antigravity.

Using variants:

opencode run "Hello" --model=google/antigravity-claude-opus-4-6-thinking --variant=max

For details on variant configuration and thinking levels, see docs/MODEL-VARIANTS.md.

Full models configuration (copy-paste ready)

Add this to your ~/.config/opencode/opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": [
    "file://<REPOSITORY_PATH>/dist/src/plugin.js"
  ],
  "provider": {
    "google": {
      "models": {
        "antigravity-gemini-3-pro": {
          "name": "Gemini 3 Pro (Antigravity)",
          "limit": { "context": 1048576, "output": 65535 },
          "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] },
          "variants": {
            "low": { "thinkingLevel": "low" },
            "high": { "thinkingLevel": "high" }
          }
        },
        "antigravity-gemini-3.1-pro": {
          "name": "Gemini 3.1 Pro (Antigravity)",
          "limit": { "context": 1048576, "output": 65535 },
          "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] },
          "variants": {
            "low": { "thinkingLevel": "low" },
            "high": { "thinkingLevel": "high" }
          }
        },
        "antigravity-gemini-3-flash": {
          "name": "Gemini 3 Flash (Antigravity)",
          "limit": { "context": 1048576, "output": 65536 },
          "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] },
          "variants": {
            "minimal": { "thinkingLevel": "minimal" },
            "low": { "thinkingLevel": "low" },
            "medium": { "thinkingLevel": "medium" },
            "high": { "thinkingLevel": "high" }
          }
        },
        "antigravity-gemini-3.5-flash": {
          "name": "Gemini 3.5 Flash (Antigravity)",
          "limit": { "context": 1048576, "output": 65536 },
          "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] },
          "variants": {
            "minimal": { "thinkingLevel": "minimal" },
            "low": { "thinkingLevel": "low" },
            "medium": { "thinkingLevel": "medium" },
            "high": { "thinkingLevel": "high" }
          }
        },
        "antigravity-gemini-3.6-flash": {
          "name": "Gemini 3.6 Flash (Antigravity)",
          "limit": { "context": 1048576, "output": 65536 },
          "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] },
          "variants": {
            "low": { "thinkingLevel": "low" },
            "medium": { "thinkingLevel": "medium" },
            "high": { "thinkingLevel": "high" }
          }
        },
        "antigravity-gemini-3.7-flash": {
          "name": "Gemini 3.7 Flash (Antigravity)",
          "limit": { "context": 1048576, "output": 65536 },
          "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] },
          "variants": {
            "minimal": { "thinkingLevel": "minimal" },
            "low": { "thinkingLevel": "low" },
            "medium": { "thinkingLevel": "medium" },
            "high": { "thinkingLevel": "high" }
          }
        },
        "antigravity-gemini-3.8-flash": {
          "name": "Gemini 3.8 Flash (Antigravity)",
          "limit": { "context": 1048576, "output": 65536 },
          "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] },
          "variants": {
            "low": { "thinkingLevel": "low" },
            "medium": { "thinkingLevel": "medium" },
            "high": { "thinkingLevel": "high" }
          }
        },
        "antigravity-claude-sonnet-4-6": {
          "name": "Claude Sonnet 4.6 (Antigravity)",
          "limit": { "context": 200000, "output": 64000 },
          "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
        },
        "antigravity-claude-opus-4-6-thinking": {
          "name": "Claude Opus 4.6 Thinking (Antigravity)",
          "limit": { "context": 200000, "output": 64000 },
          "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] },
          "variants": {
            "low": { "thinkingConfig": { "thinkingBudget": 8192 } },
            "max": { "thinkingConfig": { "thinkingBudget": 32768 } }
          }
        }
      }
    }
  }
}

Multi-Account Setup

Add multiple Google accounts for a higher combined quota. The plugin automatically rotates between accounts when one is rate-limited.

opencode auth login  # Run again to add more accounts

Account management options (via opencode auth login):

  • Configure models — Auto-configure all plugin models in opencode.json
  • Check quotas — View remaining API quota for each account
  • Manage accounts — Enable/disable specific accounts for rotation

For details on load balancing and account storage, see docs/MULTI-ACCOUNT.md.


Troubleshooting

Quick Reset: Most issues can be resolved by deleting ~/.config/opencode/antigravity-accounts.json and running opencode auth login again.

Configuration Path (All Platforms)

OpenCode uses ~/.config/opencode/ on all platforms including Windows.

File Path
Main config ~/.config/opencode/opencode.json
Accounts ~/.config/opencode/antigravity-accounts.json
Plugin config ~/.config/opencode/antigravity.json
Debug logs ~/.config/opencode/antigravity-logs/

Windows users: ~ resolves to your user home directory (e.g., C:\Users\YourName). Do NOT use %APPDATA%.

Custom path: Set OPENCODE_CONFIG_DIR environment variable to use a custom location.

Windows migration: If upgrading from plugin v1.3.x or earlier, the plugin will automatically find your existing config in %APPDATA%\opencode\ and use it. New installations use ~/.config/opencode/.


Multi-Account Auth Issues

If you encounter authentication issues with multiple accounts:

  1. Delete the accounts file:
    rm ~/.config/opencode/antigravity-accounts.json
  2. Re-authenticate:
    opencode auth login

Gemini Model Not Found

Add this to your google provider config:

{
  "provider": {
    "google": {
      "npm": "@ai-sdk/google",
      "models": { ... }
    }
  }
}

Gemini 3 Models 400 Error ("Unknown name 'parameters'")

Error:

Invalid JSON payload received. Unknown name "parameters" at 'request.tools[0]'

Causes:

  • Tool schema incompatibility with Gemini's strict protobuf validation
  • MCP servers with malformed schemas
  • Plugin version regression

Solutions:

  1. Update and rebuild the local checkout:

    cd "<REPOSITORY_PATH>"
    git pull --ff-only
    npm install
    npm run build
  2. Disable MCP servers one-by-one to find the problematic one

  3. Add npm override:

    { "provider": { "google": { "npm": "@ai-sdk/google" } } }

MCP Servers Causing Errors

Some MCP servers have schemas incompatible with Antigravity's strict JSON format.

Common symptom:

Invalid function name must start with a letter or underscore

Sometimes it shows up as:

GenerateContentRequest.tools[0].function_declarations[12].name: Invalid function name must start with a letter or underscore

This usually means an MCP tool name starts with a number (for example, a 1mcp key like 1mcp_*). Rename the MCP key to start with a letter (e.g., gw) or disable that MCP entry for Antigravity models.

Diagnosis:

  1. Disable all MCP servers in your config
  2. Enable one-by-one until error reappears
  3. Report the specific MCP in a GitHub issue

"All Accounts Rate-Limited" (But Quota Available)

Cause: Cascade bug in clearExpiredRateLimits() in hybrid mode (fixed in recent versions).

Solutions:

  1. Update and rebuild the local checkout as described above
  2. If persists, delete accounts file and re-authenticate
  3. Try switching account_selection_strategy to "sticky" in antigravity.json

Session Recovery

If you encounter errors during a session:

  1. Type continue to trigger the recovery mechanism
  2. If blocked, use /undo to revert to pre-error state
  3. Retry the operation

Using with Oh-My-OpenCode

Important: Disable the built-in Google auth to prevent conflicts:

// ~/.config/opencode/oh-my-opencode.json
{
  "google_auth": false,
  "agents": {
    "frontend-ui-ux-engineer": { "model": "google/antigravity-gemini-3.1-pro#high" },
    "document-writer": { "model": "google/antigravity-gemini-3-flash" }
  }
}

Infinite .tmp Files Created

Cause: When account is rate-limited and plugin retries infinitely, it creates many temp files.

Workaround:

  1. Stop OpenCode
  2. Clean up: rm ~/.config/opencode/*.tmp
  3. Add more accounts or wait for rate limit to expire

OAuth Callback Issues

Safari OAuth Callback Fails (macOS)

Symptoms:

  • "fail to authorize" after successful Google login
  • Safari shows "Safari can't open the page"

Cause: Safari's "HTTPS-Only Mode" blocks http://localhost callback.

Solutions:

  1. Use Chrome or Firefox (easiest): Copy the OAuth URL and paste into a different browser.

  2. Disable HTTPS-Only Mode temporarily:

    • Safari > Settings (⌘,) > Privacy
    • Uncheck "Enable HTTPS-Only Mode"
    • Run opencode auth login
    • Re-enable after authentication
Port Conflict (Address Already in Use)

macOS / Linux:

# Find process using the port
lsof -i :51121

# Kill if stale
kill -9 <PID>

# Retry
opencode auth login

Windows (PowerShell):

netstat -ano | findstr :51121
taskkill /PID <PID> /F
opencode auth login
Docker / WSL2 / Remote Development

OAuth callback requires browser to reach localhost on the machine running OpenCode.

WSL2:

  • Use VS Code's port forwarding, or
  • Configure Windows → WSL port forwarding

SSH / Remote:

ssh -L 51121:localhost:51121 user@remote

Docker / Containers:

  • OAuth with localhost redirect doesn't work in containers
  • Wait 30s for manual URL flow, or use SSH port forwarding

Plugin Configuration Key

OpenCode V2 uses plugins (plural) with the local repository directory. OpenCode V1 uses plugin (singular) with the compiled dist/src/plugin.js file. See Load the local plugin for complete examples.


Migrating Accounts Between Machines

When copying antigravity-accounts.json to a new machine:

  1. Ensure the local checkout is built and configured using the correct V1 or V2 path described above
  2. Copy ~/.config/opencode/antigravity-accounts.json
  3. If you get "API key missing" error, the refresh token may be invalid — re-authenticate

Known Plugin Interactions

For details on load balancing and account storage, see docs/MULTI-ACCOUNT.md.


Plugin Compatibility

@tarquinen/opencode-dcp

DCP creates synthetic assistant messages that lack thinking blocks. List this plugin BEFORE DCP:

{
  "plugins": [
    "<REPOSITORY_PATH>",
    "@tarquinen/opencode-dcp"
  ]
}

oh-my-opencode

Disable built-in auth and override agent models in oh-my-opencode.json:

{
  "google_auth": false,
  "agents": {
    "frontend-ui-ux-engineer": { "model": "google/antigravity-gemini-3.1-pro#high" },
    "document-writer": { "model": "google/antigravity-gemini-3-flash" },
    "multimodal-looker": { "model": "google/antigravity-gemini-3-flash" }
  }
}

Tip: When spawning parallel subagents, enable pid_offset_enabled: true in antigravity.json to distribute sessions across accounts.

Plugins you don't need

  • gemini-auth plugins — Not needed. This plugin handles all Google OAuth.

Configuration

Create ~/.config/opencode/antigravity.json for optional settings:

{
  "$schema": "https://raw.githubusercontent.com/NightCorpse/opencode-antigravity-auth/main/assets/antigravity.schema.json"
}

Most users don't need to configure anything — defaults work well.

Model Behavior

Option Default What it does
keep_thinking false Preserve Claude's thinking across turns. Warning: enabling may degrade model stability.
session_recovery true Auto-recover from tool errors
agy_sdk.enabled true Enables the Antigravity SDK / Gemini API key route for Gemini requests.
agy_sdk.prefer_for_gemini false When API keys are configured, use the Gemini API route before OAuth-backed Antigravity for Gemini models.
agy_sdk.api_key_fallback true Use configured API keys / Cloud Projects when OAuth Antigravity quota is unavailable.
model_discovery.enabled true Load provider models dynamically from Gemini API / Antigravity model APIs, with bundled static definitions as fallback.

Antigravity SDK / Gemini API keys

The official Antigravity SDK quickstart uses GEMINI_API_KEY. You can provide one key via environment variable:

GEMINI_API_KEY=your-key opencode run "Hello" --model=google/gemini-3-pro

For multiple Cloud Projects / API keys, add them to ~/.config/opencode/antigravity.json:

{
  "agy_sdk": {
    "api_key_fallback": true,
    "prefer_for_gemini": false,
    "cloud_projects": [
      { "label": "primary", "project_id": "my-project", "api_key": "..." },
      { "label": "backup", "project_id": "my-backup-project", "api_key": "..." }
    ]
  }
}

Keep this file private: API keys are stored in your local OpenCode config and are sent to Gemini with the x-goog-api-key header, never in the request URL. Do not commit antigravity.json with real keys.

Set prefer_for_gemini: true if you want Gemini models to use the public Gemini API before OAuth-backed Antigravity. OAuth multi-account rotation remains active for Antigravity and Claude, and as fallback when preferred API keys are unavailable.

Account Rotation

Your Setup Recommended Config
1 account "account_selection_strategy": "sticky"
2-5 accounts Default ("hybrid") works great
5+ accounts "account_selection_strategy": "round-robin"
Parallel agents Add "pid_offset_enabled": true

Quota Protection

Option Default What it does
soft_quota_threshold_percent 90 Skip account when quota usage exceeds this percentage. Prevents Google from penalizing accounts that fully exhaust quota. Set to 100 to disable.
quota_refresh_interval_minutes 15 Background quota refresh interval. After successful API requests, refreshes quota cache if older than this interval. Set to 0 to disable.
soft_quota_cache_ttl_minutes "auto" How long quota cache is considered fresh. "auto" = max(2 × refresh interval, 10 minutes). Set a number (1-120) for fixed TTL.

How it works: Quota cache is refreshed automatically after API requests (when older than quota_refresh_interval_minutes) and manually via "Check quotas" in opencode auth login. The threshold check uses soft_quota_cache_ttl_minutes to determine cache freshness - if cache is older, the account is considered "unknown" and allowed (fail-open). When ALL accounts exceed the threshold, the plugin waits for the earliest quota reset time (like rate limit behavior). If wait time exceeds max_rate_limit_wait_seconds, it errors immediately.

Rate Limit Scheduling

Control how the plugin handles rate limits:

Option Default What it does
scheduling_mode "cache_first" "cache_first" = wait for same account (preserves prompt cache), "balance" = switch immediately, "performance_first" = round-robin
max_cache_first_wait_seconds 60 Max seconds to wait in cache_first mode before switching accounts
failure_ttl_seconds 3600 Reset failure count after this many seconds (prevents old failures from permanently penalizing accounts)

When to use each mode:

  • cache_first (default): Best for long conversations. Waits for the same account to recover, preserving your prompt cache.
  • balance: Best for quick tasks. Switches accounts immediately when rate-limited for maximum availability.
  • performance_first: Best for many short requests. Distributes load evenly across all accounts.

App Behavior

Option Default What it does
quiet_mode false Hide toast notifications
debug false Enable debug file logging (~/.config/opencode/antigravity-logs/)
debug_tui false Show debug logs in the TUI log panel (independent from debug)
auto_update true Package update checker; set to false for this local Git installation

For all options, see docs/CONFIGURATION.md.

Environment variables:

OPENCODE_CONFIG_DIR=/path/to/config opencode  # Custom config directory
OPENCODE_ANTIGRAVITY_DEBUG=1 opencode         # Enable debug file logging
OPENCODE_ANTIGRAVITY_DEBUG=2 opencode         # Verbose debug file logging
OPENCODE_ANTIGRAVITY_DEBUG_TUI=1 opencode     # Enable TUI log panel debug output

Troubleshooting

See the full Troubleshooting Guide for solutions to common issues including:

  • Auth problems and token refresh
  • "Model not found" errors
  • Session recovery
  • Public Gemini API-key configuration
  • Safari OAuth issues
  • Plugin compatibility
  • Migration guides

Documentation


Credits

License

MIT License. See LICENSE for details.

Legal

Intended Use

  • Personal / internal development only
  • Respect internal quotas and data handling policies
  • Not for production services or bypassing intended limits

Warning

By using this plugin, you acknowledge:

  • Terms of Service risk — This approach may violate ToS of AI model providers
  • Account risk — Providers may suspend or ban accounts
  • No guarantees — APIs may change without notice
  • Assumption of risk — You assume all legal, financial, and technical risks

Disclaimer

  • Not affiliated with Google. This is an independent open-source project.
  • "Antigravity", "Gemini", "Google Cloud", and "Google" are trademarks of Google LLC.

About

Enable Opencode to authenticate against Antigravity (Google's IDE) via OAuth so you can use Antigravity rate limits and access models like gemini-3.1-pro and claude-opus-4-6-thinking with your Google credentials.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages