Google Gemini OAuth Plugin for Opencode: Use Your Google AI Subscription Instead of API Pricing

Murtuzaali Surti
Murtuzaali Surti

• 3 min read

Updated

Table of Contents

Opencode is an open source AI coding agent similar to Claude Code, Gemini CLI, and Codex. It's an interactive terminal user interface (TUI) which connects with most of the AI model (LLM) providers out there, OpenRouter, Google, Anthropic, OpenAI, Amazon Bedrock, Groq, Ollama, you name it.

Out of the box, Opencode allows you to connect Google as a provider via an API key. But, what if you don't have a Google Cloud API key? What if you've purchased a Google AI Pro/Ultra subscription, or received a free Google AI subscription (students and users in India often qualify for these offers), and want to use it with Opencode?

To use a Google AI subscription, you need to sign in with your Google account in Opencode. The problem is, Opencode doesn't support this out of the box. I came across a plugin from a GitHub issue in the Opencode repository which solves this exact problem.

opencode-gemini-auth by Jens Lystad allows you to sign in using your Google account via OAuth and use any Gemini models accessible via your subscription with Opencode.

In this tutorial, I'll walk you through setting up the opencode-gemini-auth plugin with Opencode.

Pre-requisites

  • A Google account with a Google AI subscription (Pro, Ultra, or the free tier)
  • Opencode CLI installed

Installing Opencode

First, install Opencode if you haven't already using the simple shell script below:

curl -fsSL https://opencode.ai/install | bash

Locating the Config File

Opencode uses a JSON config file for configuration. I recommend using a global config for configuring providers, but you're free to use a local (project-scoped) config file (opencode.json) instead.

Find the global config file at these locations:

  • macOS/Linux: ~/.config/opencode/opencode.json
  • Windows: Run opencode debug paths to check the config file location

If the global opencode.json config file doesn't exist yet, create it at the respective location for your operating system.

Registering the Plugin

Add the following to your Opencode config file:

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": ["opencode-gemini-auth@latest"]
}

That's it. Opencode is now ready to use Google OAuth for authentication.

Connecting Your Google Account

Once you've updated the config file with the plugin, run this command:

opencode auth login

Choose Google from the list of providers. You'll see an OAuth with Google option. Selecting it will open a browser window and redirect you to the Google OAuth flow. After you sign in and grant access, Opencode can access any Gemini models associated with your subscription.

Pro Tip

If the browser doesn't open automatically (common in headless environments or when the port is in use), you can manually paste the callback URL or authorization code when prompted.

Troubleshooting

To view detailed logs for debugging, run Opencode with the debug flag:

OPENCODE_GEMINI_DEBUG=1 opencode

It will generate gemini-debug-<timestamp>.log files in your working directory.

Updating the Plugin

Opencode doesn't automatically update plugins. To update to the latest version, clear the cached plugin and restart Opencode:

rm -rf ~/.cache/opencode/node_modules/opencode-gemini-auth
opencode

Wrapping Up

The opencode-gemini-auth plugin is for Opencode users who have a Google AI subscription but don't want to deal with API billing. It's a straightforward way to leverage your existing Gemini quota directly within Opencode's powerful terminal user interface.

Note that your usage is subject to the quotas and rate limits of your Google AI subscription tier.


How to Use Free Antigravity AI Models in Claude Code

Previous