Connecting Gemma 4 to Claude Code CLI#
This note outlines the process for routing the Claude Code CLI (v2.1.71) to a local Gemma 4:26b instance running via Ollama on macOS. This configuration keeps all source code processing 100% local and private on the MacStudio.
1. Terminal Environment Variables#
Before initializing the Claude Code engine, you must redirect its network calls from Anthropic’s cloud endpoints back to your local machine. Run these commands in your macOS terminal:
# Redirect the API traffic to the local Ollama Open-AI compatible endpoint
export ANTHROPIC_BASE_URL="http://localhost:11434/v1"
# Provide a dummy string to bypass client-side validation checks
export ANTHROPIC_API_KEY="ollama"2. Launching the Local Agent#
Navigate directly to your iOS workspace root directory (where your .xcodeproj or Package.swift is located) and execute the model target string:
# Change directory to your Swift project path
cd /path/to/your/prject# Initialize the Claude Code interface targeting Gemma 4
claude --model gemma4:26b3. Post-Launch Verification#
Once the terminal transitions into the interactive claude> input state, execute the structural configuration check command:
claude> /configExpected Settings Matrix#
- Base URL Target:
http://localhost:11434/v1 - Active Token Model:
gemma4:26b - Network Status: Local loopback routing active.
💡 Context Management Pro-Tip#
Because you are tracking a multi-file Xcode project, once the connection stabilizes, run /init inside the agent prompt. This signals Gemma 4 to map out your file trees and index class definitions using its 256K context window before you begin issuing code revision commands.