Add the plugin to your OpenCode config:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-gemini-auth"]
}
Then run:
opencode auth login
Choose the Google provider and select OAuth with Google (Gemini CLI).
[!WARNING] Google has stated that using Gemini CLI OAuth with third-party software is a policy-violating use case and may trigger abuse detection or account restrictions. It is unclear how aggressively this is enforced for projects like this one, but you should assume there is real risk and use this plugin at your own discretion. If you want the lowest-risk option, use Opencode with your own Gemini API key instead.
See: https://github.com/google-gemini/gemini-cli/discussions/22970
Authenticate the Opencode CLI with your Google account. This plugin enables you to use your existing Gemini plan and quotas (including the free tier) directly within Opencode.
Add the plugin to your Opencode configuration file
(~/.config/opencode/opencode.json or similar):
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-gemini-auth@latest"]
}
[!IMPORTANT] If you're using a paid Gemini Code Assist subscription (Standard/Enterprise), explicitly configure a Google Cloud
projectId. Free tier accounts should auto-provision a managed project, but you can still setprojectIdto force a specific project.
Login: Run the authentication command in your terminal:
opencode auth login
Select Provider: Choose Google from the list.
Authenticate: Select OAuth with Google (Gemini CLI).
Once authenticated, Opencode will use your Google account for Gemini requests.
To check your current Gemini Code Assist quota buckets at any time, run:
/gquota
By default, the plugin attempts to provision or find a suitable Google Cloud
project. To force a specific project, set the projectId in your configuration
or via environment variables:
File: ~/.config/opencode/opencode.json
{
"provider": {
"google": {
"options": {
"projectId": "your-specific-project-id"
}
}
}
}
You can also set OPENCODE_GEMINI_PROJECT_ID, GOOGLE_CLOUD_PROJECT, or
GOOGLE_CLOUD_PROJECT_ID to supply the project ID via environment variables.
Below are example model entries you can add under provider.google.models in your
Opencode config. Each model can include an options.thinkingConfig block to
enable "thinking" features.
{
"provider": {
"google": {
"models": {
"gemini-2.5-flash": {
"options": {
"thinkingConfig": {
"thinkingBudget": 8192,
"includeThoughts": true
}
}
},
"gemini-2.5-pro": {
"options": {
"thinkingConfig": {
"thinkingBudget": 8192,
"includeThoughts": true
}
}
},
"gemini-3-flash-preview": {
"options": {
"thinkingConfig": {
"thinkingLevel": "high",
"includeThoughts": true
}
}
},
"gemini-3-pro-preview": {
"options": {
"thinkingConfig": {
"thinkingLevel": "high",
"includeThoughts": true
}
}
}
}
}
}
}
Note: Available model names and previews may change—check Google's documentation or the Gemini product page for the current model identifiers.
The plugin supports configuring Gemini "thinking" features per-model via
thinkingConfig. The available fields depend on the model family:
thinkingLevel with values "low" or "high".thinkingBudget (token count).includeThoughts (boolean) controls whether the model emits internal thoughts.A combined example showing both model types:
{
"provider": {
"google": {
"models": {
"gemini-3-pro-preview": {
"options": {
"thinkingConfig": {
"thinkingLevel": "high",
"includeThoughts": true
}
}
},
"gemini-2.5-flash": {
"options": {
"thinkingConfig": {
"thinkingBudget": 8192,
"includeThoughts": true
}
}
}
}
}
}
}
If you don't set a thinkingConfig for a model, the plugin will use default
behavior for that model.
If automatic provisioning fails, you may need to set up the project manually:
cloudaicompanion.googleapis.com).projectId in your Opencode config as shown above.Common causes of 429 RESOURCE_EXHAUSTED or QUOTA_EXHAUSTED:
gemini-3-pro-preview vs gemini-3-flash-preview).Notes:
provider.google.options.projectId (or OPENCODE_GEMINI_PROJECT_ID) and re-authenticate.To view detailed logs of Gemini requests and responses, set the
OPENCODE_GEMINI_DEBUG environment variable:
OPENCODE_GEMINI_DEBUG=1 opencode
This will generate gemini-debug-<timestamp>.log files in your working
directory containing sanitized request/response details.
This plugin mirrors the official Gemini CLI OAuth flow and Code Assist endpoints. In particular, project onboarding and quota retry handling follow the same behavior patterns as the Gemini CLI.
For local parity checks, you can keep a separate clone of the official
gemini-cli in this repo at .local/gemini-cli.
This mirror is intentionally untracked, so contributors must set it up once on their machine:
git clone https://github.com/google-gemini/gemini-cli.git .local/gemini-cli
After setup, pull upstream updates with:
bun run update:gemini-cli
Opencode does not automatically update plugins. To update to the latest version, you must clear the cached plugin:
# Clear the specific plugin cache
rm -rf ~/.cache/opencode/node_modules/opencode-gemini-auth
# Run Opencode to trigger a fresh install
opencode
To develop on this plugin locally:
Clone:
git clone https://github.com/jenslys/opencode-gemini-auth.git
cd opencode-gemini-auth
bun install
Link:
Update your Opencode config to point to your local directory using a
file:// URL:
{
"plugin": ["file:///absolute/path/to/opencode-gemini-auth"]
}
MIT
Sign in to leave a comment.