Integrating Google Gemini into Claude Code CLI

(Modify : 2026-07-25)

The adoption of Claude Code CLI, a terminal-based AI coding agent, is rapidly growing among developers.

However, because Claude Code CLI is natively designed to operate using Anthropic's Messages API specification, directly integrating and using other LLMs (such as Google Gemini, OpenAI, etc.) poses a significant challenge.

In this article, we walk through the detailed pipeline architecture and step-by-step setup for using Google Gemini models as the backend engine for Claude Code CLI. This is achieved by building a local proxy server (LiteLLM) that converts Anthropic API requests into Google Gemini API requests in real time.

To state the bottom line up front: While building this technical pipeline is entirely feasible, we do not recommend using it in production environments due to the massive token consumption inherent to autonomous agent workloads.

Below, we analyze the setup process alongside the specific bottlenecks, trade-offs, and failure scenarios that emerge from this integration.

Architecture & Integration Principles

Claude Code CLI internally hardcodes and communicates using Anthropic's proprietary API specification (Messages API).

Directly pointing it to the Google Gemini API endpoint causes errors due to discrepancies in request and response JSON formats, which is why a LiteLLM proxy server is deployed in between.

Plain Text

1

2

3

4

5

6

7

8

9

[Claude Code CLI] 
   │ 
   │  (1) Anthropic JSON Format (Messages API)
   ▼ 
[LiteLLM Proxy (로컬 포트 4000)] 
   │ 
   │  (2) Real-time Payload Translation (Google API Format)
   ▼ 
[Google Gemini API Server]

Workflow Process

  1. Claude Code CLI: Operates under the assumption that it is communicating directly with Anthropic servers, sending Anthropic-formatted JSON requests to the local proxy(http://127.0.0.1:4000)

  2. LiteLLM Proxy: Intercepts incoming Anthropic JSON protocols, translates them to the Google Gemini API specification in real time, and forwards them to Google's servers.

  3. Google Gemini: Processes the payload and returns the response, which LiteLLM translates back into the Anthropic format before delivering it back to Claude Code CLI.

Prerequisites: Verifying Gemini API Key Functionality

First, verify that the Gemini API Key issued from platforms such as Google AI Studio is functioning properly.

Run a direct communication test with Google's servers by executing a curl command in your terminal.

Plain Text

1

2

3

4

5

6

export GEMINI_API_KEY="your_actual_gemini_api_key"

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{"contents": [{"parts":[{"text": "hi"}]}]}'

If you receive a normal JSON response containing candidates and content structures, your API key is ready for use.

Installing and Configuring the LiteLLM Proxy Server

LiteLLM is a widely used multi-model router that centrally manages and translates API specifications across various AI providers (such as Anthropic, OpenAI, and Google).

Install litellm[proxy] using pipx to ensure an isolated package environment.

Plain Text

1

2

3

4

5

6

7

# Install pipx (macOS Homebrew)
brew install pipx
pipx ensurepath
source ~/.zshrc

# Install LiteLLM proxy package
pipx install 'litellm[proxy]'

Creating the Configuration File

Create a config.yaml file to map model requests sent by the Claude Code CLI to the actual Gemini model.

config.yaml

YAML

1

2

3

4

5

6

model_list:
  - model_name: claude-sonnet-5-20241022    # Model name requested by Claude Code CLI
    litellm_params:
      model: gemini/gemini-2.5-flash        # Google Gemini model that actually executes the workload
      api_key: "os.environ/GEMINI_API_KEY"  # Reference key from system environment variables
      drop_params: true                     # Automatically drop parameters unsupported by Gemini

Configuration Note

  • drop_params: true: An essential setting that automatically ignores and strips Anthropic-specific parameters (e.g., thinking, prompt_caching, etc.) to prevent errors during communication with Gemini.

Running the Proxy Server

Start the LiteLLM proxy server using the configuration file you created.

Plain Text

1

litellm --config config.yaml --port 4000

Once running correctly, a local API endpoint will be activated at http://127.0.0.1:4000.

Integrating and Testing Claude Code CLI

Open a new terminal window and set the environment variables so that Claude Code CLI points to the local proxy(http://127.0.0.1:4000) instead of the official Anthropic API.

Plain Text

1

2

3

4

ANTHROPIC_BASE_URL="http://127.0.0.1:4000" \
ANTHROPIC_API_KEY="sk-ant-api03-dummy1234567890" \
ANTHROPIC_MODEL="claude-sonnet-5-20241022" \
claude -p "test start: who are you?"

Verifying the Response

Plain Text

1

2

3

⚠ claude.ai connectors are disabled because ANTHROPIC_API_KEY or another auth source is set...

I am Gemini, a large language model developed by Google.

You can confirm that the internal engine has successfully switched to Google Gemini while maintaining the exact same interface.

Production Considerations & Limitations

While this proxy architecture successfully establishes technical integration, applying it to real-world projects reveals critical limitations:

Excessive Token Consumption

The primary issue is an abnormally high rate of token usage.

Even simple requests—such as reviewing and editing blog text once or twice—consumed 30% to 40% of the Gemini API usage limit in a flash.

This happens because Claude Code CLI operates as an autonomous agent rather than a simple chatbot.

To fulfill even a short query, the CLI sends massive amounts of data with every request, including:

  • Complex internal system prompts of Claude Code

  • JSON schema definitions for all tools accessible to the agent

  • Current file system states and cumulative conversation history

Consequently, tens of thousands of context tokens are passed through the API on every call, frequently causing Rate Limit errors or exhausting daily quotas.

Tool Calling Compatibility Issues

Claude Code CLI heavily relies on complex agent tools like reading files, editing code, and running bash commands.

Although LiteLLM translates Anthropic’s <tools> schema into Gemini’s format—working smoothly for simple summaries—schema mismatches can halt execution during complex regex-based code edits or chained sub-agent calls.

Requirement for Official Claude APIs

Because of the drop_params: true setting, Claude-specific optimizations like Extended Thinking and Prompt Caching do not function.

For a reliable production environment, using an official Claude API key is vastly more efficient.

Conclusion

Building a pipeline to map Anthropic Messages API requests to Gemini API via a LiteLLM proxy is a technically fascinating experiment.

Swapping the underlying engine of a complex agent with just a few lines of configuration is certainly compelling.

However, due to extreme token consumption driven by the agent's massive context payloads, using this setup for production or daily coding tasks is not recommended.

Losing 30% to 40% of your quota on light text reviews presents an unacceptable trade-off.

For reliable agent performance, stick to the official Claude API as originally intended.

민갤

Back-End Developer

백엔드 개발자입니다.

Troubleshooting Native API Versioning and Swagger Integration in Spring Boot 4

Spring Boot

v5.0