·6 min read
How to use Gemini for coding in Claude Code

You can keep Claude Code as the terminal interface while using Gemini for the coding requests through a third-party gateway. This guide retains the local LiteLLM configuration and adds a November 13, 2026 test through TokAtlas directly. These are separate connection paths. Anthropic documents gateway setup and explicitly excludes routing to non-Claude models from its support scope. Claude Code gateway documentation
Decide whether Gemini is the model or a tool
Making Gemini the main model changes where coding requests go. Adding a tool that calls Gemini or exposes its documentation leaves the main model selection separate. This guide covers routing the main model requests.
The gateway needs a Claude Code-compatible Messages interface on the client side and Gemini access upstream. Verify the protocol even if you already have a Gemini or OpenAI-compatible URL. Gateway protocol guide
1. Configure the local route
Install Claude Code and uv first. Load your Gemini credential into GEMINI_API_KEY and a separate random gateway key starting with sk- into LITELLM_MASTER_KEY. Keep the Google credential on the gateway side. Create config.yaml using this model mapping. LiteLLM provider routing guide
model_list:
- model_name: gemini-3.8-flash
litellm_params:
model: gemini/gemini-3.8-flash
api_key: os.environ/GEMINI_API_KEY
general_settings:
master_key: os.environ/LITELLM_MASTER_KEY
Start the gateway from a terminal with both variables loaded. The local listener is restricted to loopback. model_name is the name the client requests. litellm_params.model specifies the upstream route. If the example model is unavailable to your account, change the mapping and commands to match an accessible model.
uv tool install 'litellm[proxy]' litellm --config ./config.yaml --host 127.0.0.1 --port 4000
2. Check the gateway first
In a second terminal, load the same gateway key and make one Messages request. Inspect the HTTP response and the upstream route in gateway records. An error here narrows investigation to the gateway URL, credentials, alias, or Gemini access before Claude Code enters the picture. Claude Code connection verification
curl -sS --fail-with-body http://127.0.0.1:4000/v1/messages \
-H "Authorization: Bearer $LITELLM_MASTER_KEY" \
-H 'anthropic-version: 2023-06-01' \
-H 'Content-Type: application/json' \
-d '{"model":"gemini-3.8-flash","max_tokens":256,"messages":[{"role":"user","content":"Reply with READY."}]}'
3. Start a Claude Code session
Use the gateway root URL, its bearer credential, and the configured model alias. The environment below applies to this process. Check /status for the active gateway and credential source. Existing settings may affect the effective values. Claude Code connection settings
env -u ANTHROPIC_API_KEY \ ANTHROPIC_BASE_URL=http://127.0.0.1:4000 \ ANTHROPIC_AUTH_TOKEN="$LITELLM_MASTER_KEY" \ claude --model gemini-3.8-flash
4. Validate a complete coding task
A successful chat only checks basic connectivity. Create this intentionally failing Python example in a temporary directory. The final command should first raise AssertionError. Then start Claude Code from that directory using the preceding command.
demo_dir="$(mktemp -d)"
cd "$demo_dir"
cat > price.py <<'PYTHON'
def discounted_price(cents, percent):
return cents * percent // 100
assert discounted_price(1000, 20) == 800
PYTHON
python3 price.py
Give the agent a bounded task. “Read price.py and fix the discounted amount due. Change only this file. Keep the existing assertion, add a zero-discount case, run python3 price.py, and explain the change.”
Inspect the upstream route in gateway records, the actual file change, and the command's exit result. Keep normal tool permissions enabled and review their prompts. A textual success message alone cannot confirm that the file changed or the test ran.
November 13 test: Claude Code with Gemini through TokAtlas
The small coding task passed.We used macOS and Claude Code 2.1.323. Both the requested model and returned model field were gemini-3.8-flash. The client connected directly to https://api.tokatlas.com/v1/messages without a local LiteLLM proxy. The platform details showed “Claude Messages → OpenAI Compatible → Google Gemini.” This result covers this client version, account route and task, not every Gemini model or Claude Code feature.
Test settings and reproduction
We created a dedicated pay-as-you-go key with a US$1 cumulative limit, the Value group, platform-recommended bidding and only gemini-3.8-flash selected. A minimal Messages request with max_tokens=128 returned HTTP 200, model gemini-3.8-flash and READY. We then created the price.py fixture from step 4 in an isolated directory and verified that its original assertion failed.
Load the test key securely into TOKATLAS_TEST_KEY and run the following from that isolated directory. This is the shell equivalent of the tested CLI invocation. Our runner cleared inherited Anthropic/Claude settings before injecting the test connection variables. Permissions allow reading and editing only price.py and running the specified Python command; no everyday client settings are changed.
env -u ANTHROPIC_AUTH_TOKEN \ ANTHROPIC_API_KEY="$TOKATLAS_TEST_KEY" \ ANTHROPIC_BASE_URL=https://api.tokatlas.com \ ANTHROPIC_MODEL=gemini-3.8-flash \ ANTHROPIC_DEFAULT_HAIKU_MODEL=gemini-3.8-flash \ ANTHROPIC_DEFAULT_SONNET_MODEL=gemini-3.8-flash \ ANTHROPIC_DEFAULT_OPUS_MODEL=gemini-3.8-flash \ CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 \ CLAUDE_CODE_MAX_OUTPUT_TOKENS=2048 MAX_THINKING_TOKENS=0 \ claude --bare --restricted --strict-mcp-config \ --no-session-persistence --disable-slash-commands --no-chrome \ --model gemini-3.8-flash --tools Read,Edit,Bash \ --allowedTools 'Read(./price.py)' 'Edit(./price.py)' 'Bash(python3 price.py)' \ --permission-mode dontAsk --max-budget-usd 0.8 \ --output-format stream-json --verbose \ -p 'Read price.py. Fix the calculation of the price after a percentage discount. Only modify price.py. Preserve its existing assertion and add a zero-discount assertion. Run exactly python3 price.py using Bash. Report the actual tool result. Do not read other files or use other commands.'
This --bare run used ANTHROPIC_API_KEY. Do not confuse the local LiteLLM master key in the earlier example with the TokAtlas key used here. The CLI's --max-budget-usd control does not replace the platform key allowance, and its cost estimate may be inaccurate for an unrecognized model.
Actual file change and tool results
- Before the edit:python3 price.py failed with AssertionError and exit code 1.
- Read:returned the original function and assertion.
- Edit:changed price.py, preserving the original assertion and adding a zero-discount case.
- Bash:ran python3 price.py and returned “Bash completed with no output,” with is_error=false.
- Independent check:after the CLI finished, a separate run of the same test exited 0. The actual diff is below.
def discounted_price(cents, percent): - return cents * percent // 100 + return cents - (cents * percent // 100) assert discounted_price(1000, 20) == 800 +assert discounted_price(1000, 0) == 1000
Timing, billing and compatibility limits
The CLI task took about 195 seconds. One response produced no visible output; the client requested continuation and then completed the task. The platform recorded two errors and a later success under the same request ID, with Retries=2 in the successful record. This was not an error-free run.
The platform showed eight records covering the connectivity check and coding workflow, totaling US$0.010356. The connectivity check cost US$0.000184; the coding task totaled US$0.010172. Both error records showed US$0, which does not imply that all failures are free. The CLI estimated US$0.113015 with costBasis=unknown, so we use the platform's recorded charges here. The temporary key was disabled after testing.
The test covered file reading, file editing, Bash execution and returning tool results to the model. It did not cover MCP, image input, long contexts, multi-file refactoring or sustained reliability. The local LiteLLM route remains a documentation-based configuration and was not rerun in this test. Anthropic excludes non-Claude model routing from official support, as linked at the start of this article.
When chat works but editing fails
Check whether the agent requested a tool, whether local permissions allowed it, and whether the result returned to the model. If it stalls after execution, check gateway translation of tool calls and results and look for interrupted streaming. Diagnose with a tiny task before using a larger repository.
The original configuration sources were checked on November 6, 2026. The direct TokAtlas test and billing review above were performed on November 13, 2026. Prices and route availability can change; repeat a small workload with your own account.
For the billing breakdown of this same test and a reusable acceptance-based calculation method, see the API cost-control guide.