Skip to main content

Gemini Provider

Access Google Gemini models via OAuth authentication with automatic token management and interactive model configuration.

Quick Start

# First run (browser opens for OAuth)
ccs gemini "explain this code"

# Select model interactively
ccs gemini --config

# Use specific account
ccs gemini --use work

Authentication

Initial Setup

1

First Run

Run ccs gemini "your prompt" - browser opens automatically
2

Google OAuth

Sign in with your Google account
3

Token Cached

OAuth token saved to ~/.ccs/cliproxy/auth/gemini-{email}.json
4

Auto Refresh

Token refreshes automatically 5 minutes before expiry

OAuth Flow Specifics

Authorization Code Flow:
  • Callback server spawns on provider-specific port
  • Browser opens for Google OAuth consent
  • Token received via HTTP callback
  • Auto-refresh prevents mid-request failures
Proactive Token Refresh:
  • Checks expiry_date before each execution
  • Refreshes 5 minutes before expiry (matches CLIProxyAPI)
  • Prevents UND_ERR_SOCKET errors during long sessions
  • Graceful re-auth prompt if refresh fails

Headless Authentication

For servers without browser access:
ccs gemini --headless

# Output:
# Open this URL on any device:
# https://accounts.google.com/o/oauth2/auth?...
#
# Waiting for authentication...
Complete OAuth on another device - CCS detects when token is cached.

Multi-Account Support

Manage multiple Google accounts seamlessly:
# Add second account (preserves existing)
ccs gemini --auth --add

# Auto-nicknamed from email prefix
# john@gmail.com → "john"
Account Registry: ~/.ccs/cliproxy/accounts.json
{
  "version": 1,
  "providers": {
    "gemini": {
      "default": "john@gmail.com",
      "accounts": {
        "john@gmail.com": {
          "email": "john@gmail.com",
          "nickname": "john",
          "tokenFile": "gemini-john@gmail.com.json",
          "createdAt": "2024-01-01T00:00:00Z",
          "lastUsedAt": "2024-01-05T12:00:00Z"
        }
      }
    }
  }
}

Model Configuration

Interactive Model Picker

Select Gemini model interactively with --config flag:
ccs gemini --config

# Interactive prompt:
# Available models for Gemini:
# 1. Gemini 3 Pro (High) - Recommended (fast, reliable)
# 2. Gemini 3 Pro (Preview) - Latest features (may be unstable)
# 3. Gemini 2.5 Pro - Free tier
# 4. Gemini 3 Flash - Fast responses
# Select model [1-4]: 1
First-Run Detection: If no model configured, prompts automatically before first execution.

Available Models

Model IDNameTierNotes
gemini-3-pro-highGemini 3 Pro (High)PaidRecommended, fast & reliable
gemini-3-pro-previewGemini 3 Pro (Preview)PaidLatest features, may be unstable
gemini-2.5-proGemini 2.5 ProFreeWorks with free Google account
gemini-3-flashGemini 3 FlashPaid/FreeFast responses, lower quality
Gemini 3 Pro models require a paid Google account. Use Gemini 2.5 Pro for free tier.

Model Settings Storage

Settings saved to ~/.ccs/gemini.settings.json:
{
  "model": "gemini-3-pro-high",
  "maxTokens": 8192
}
Priority: Custom settings → User overrides → Bundled defaults

Configuration

Config Keys

Configure via ~/.ccs/config.yaml:
# WebSearch integration
websearch:
  providers:
    gemini:
      model: "gemini-2.5-pro"      # Model for WebSearch hook
      timeout: 30000                # CLI timeout (ms)

# CLIProxy settings
cliproxy:
  auth:
    api_key: "ccs-internal-managed"
    management_secret: "ccs"        # Dashboard login password

Environment Variables

These are set automatically by CCS. Manual override rarely needed.
# Claude CLI injection (auto-managed)
ANTHROPIC_BASE_URL=http://127.0.0.1:8317/api/provider/gemini
ANTHROPIC_AUTH_TOKEN=ccs-internal-managed
ANTHROPIC_MODEL=gemini-3-pro-high
ANTHROPIC_DEFAULT_OPUS_MODEL=gemini-3-pro-high
ANTHROPIC_DEFAULT_SONNET_MODEL=gemini-3-flash
ANTHROPIC_DEFAULT_HAIKU_MODEL=gemini-3-flash
ANTHROPIC_MAX_TOKENS=8192

Commands Reference

Basic Usage

# Execute with default model
ccs gemini "your prompt"

# One-shot mode (exit after response)
ccs gemini "explain this function"

Authentication Commands

# Trigger OAuth (no session)
ccs gemini --auth

# Add new account (preserves existing)
ccs gemini --auth --add

# Logout (clear tokens)
ccs gemini --logout

# Headless mode (no browser)
ccs gemini --headless

Account Management

# List all accounts
ccs gemini --accounts

# Switch default account
ccs gemini --use work

# Rename current account
ccs gemini --nickname personal

Configuration

# Interactive model picker
ccs gemini --config

# Dashboard configuration
ccs config

Troubleshooting

Token Refresh Failures

Symptom: UND_ERR_SOCKET errors during execution Cause: Token expired mid-request Solution: Proactive refresh handles this automatically. If issue persists:
# Clear and re-authenticate
ccs gemini --logout
ccs gemini --auth

Model Not Working

Symptom: API errors, tool call failures Cause: Model incompatible with Claude Code Solution: Change model via --config:
ccs gemini --config
# Select "Gemini 3 Pro (High)" - most reliable
Gemini 3 Pro (Preview) has known issues with tool calls. Use “High” variant instead.

Multiple Accounts Confusion

Symptom: Wrong account being used Solution: Check default account:
# View all accounts (default marked with *)
ccs gemini --accounts

# Switch default
ccs gemini --use work

Browser Doesn’t Open

Symptom: OAuth flow stuck waiting for browser Solution: Use headless mode:
ccs gemini --headless
# Copy URL to browser manually

Storage Locations

PathDescription
~/.ccs/cliproxy/auth/gemini-*.jsonOAuth tokens (one per account)
~/.ccs/cliproxy/accounts.jsonAccount registry, nicknames
~/.ccs/gemini.settings.jsonModel selection, preferences
~/.ccs/cliproxy/config.yamlCLIProxy configuration

Cost Information

TierModelsCost
FreeGemini 2.5 Pro, Gemini 3 Flash (limited)$0
PaidGemini 3 Pro (High/Preview)Google subscription required
Quota Management: Automatic rotation if rate limited (config: quota-exceeded.switch-project: true)

Advanced Features

Token Structure

OAuth token file format (gemini-{email}.json):
{
  "type": "gemini",
  "access_token": "ya29...",
  "refresh_token": "1//...",
  "email": "user@gmail.com",
  "expired": "2024-12-31T23:59:59Z",
  "expiry_date": 1735689599000
}

Proactive Refresh Logic

  1. Before execution: Check expiry_date
  2. If < 5 minutes until expiry: Trigger refresh
  3. If refresh succeeds: Update token file
  4. If refresh fails: Prompt re-auth
  5. Execute Claude CLI with valid token
Why 5 minutes? Matches CLIProxyAPI behavior, prevents race conditions during long API calls.

Next Steps