Saturday, June 13, 2026

Pairing Claude Code with Native Fashions


 

 

Introduction

 
Agentic coding classes are costly. A single Claude Code session — studying information, writing code, working exams, iterating — can burn 10–50x extra tokens than a plain chat dialog. At scale, that provides up quick. Add price limits that may interrupt a long-running workflow mid-session, and the dependency on a third-party API that may change pricing, implement stricter insurance policies, or go down at any level, and the case for native inference turns into easy.

Native fashions in 2026 are ok. For the duties Claude Code handles each day — code completion, refactoring, debugging, codebase rationalization — a well-chosen quantized mannequin working regionally covers the overwhelming majority of actual use circumstances at zero per-token value and with no price limits. This text covers three inference backends (Ollama, LM Studio, and llama.cpp), the precise surroundings variables and configuration information to wire each to Claude Code, a curated desk of fashions price working, and the troubleshooting fixes for the problems you’ll really hit.

 

How Claude Code Connects to Any Native Mannequin

 
The mechanism is easier than most guides make it look. Claude Code sends requests within the Anthropic Messages API format. By default these requests go to Anthropic’s servers. Setting ANTHROPIC_BASE_URL redirects them to any server that speaks the identical format, which now contains Ollama, LM Studio, and llama.cpp natively.

Based on the official Claude Code surroundings variables documentation, the variables that matter for this setup are:

  • ANTHROPIC_BASE_URL: redirects all API calls from Anthropic’s servers to no matter URL you set. Set this to your native inference server tackle.
  • ANTHROPIC_API_KEY: the API key despatched within the request header. Native servers usually ignore authentication, so that is often set to a placeholder string like “native” or “ollama.”
  • ANTHROPIC_AUTH_TOKEN: another auth header. Some native servers test for this as an alternative of the API key. Set it to the identical placeholder.

ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL, and ANTHROPIC_DEFAULT_OPUS_MODEL: Claude Code internally requests completely different mannequin tiers relying on the duty. These three variables map every tier to your native mannequin’s title. With out them, Claude Code sends requests for claude-sonnet-4-20250514 to your native server, which is able to reject the request as a result of no such mannequin exists regionally.

In January 2026, Ollama added native help for the Anthropic Messages API, which was the technical change that made this workflow sensible with out translation proxies. LM Studio added a local /v1/messages endpoint in model 0.4.1. llama.cpp has had direct Anthropic API help for longer. All three now converse Claude Code’s native protocol.

 

A clean architecture diagram showing Claude Code, Ollama, LM Studio and llama.cpp
A clear structure diagram exhibiting Claude Code, Ollama, LM Studio, and llama.cpp | Picture by Writer

 

Backend 1: Ollama

 
Ollama is the appropriate place to begin. It handles all of the complexity of mannequin administration — downloading weights, quantization, GPU and CPU allocation, and serving — behind a easy command-line interface (CLI). One command to put in, one command to drag a mannequin, a couple of surroundings variables to configure. It runs as a background service after set up, so there isn’t a guide server begin required.

Conditions

  • macOS, Linux, or Home windows (WSL2 beneficial on Home windows)
  • A minimum of 16 GB RAM for sensible use (32 GB beneficial)
  • GPU with 8+ GB VRAM for GPU inference, or CPU-only with sufficient RAM
  • Ollama v0.14.0 or later required for Anthropic Messages API help

Set up Ollama:

# macOS and Linux -- one command set up
curl -fsSL https://ollama.com/set up.sh | sh

# Confirm the model -- should be 0.14.0+ for Claude Code compatibility
ollama model
# Anticipated: ollama model is 0.14.x or larger

# Home windows: obtain the installer from https://ollama.com
# Native Home windows help has improved considerably in current releases

 

After set up, Ollama begins robotically as a background service on port 11434. You possibly can confirm it’s working:

# Examine the Ollama server is reside
curl http://localhost:11434

# Anticipated response:
# Ollama is working

 

Pull a coding mannequin:

# GLM-4.7-Flash -- beneficial place to begin
# Robust instrument calling, 128K context, suits on 8 GB VRAM
# Apache 2.0 license
ollama pull glm-4.7-flash:newest

# Qwen3-Coder -- robust code technology and instruction following
# Requires 20+ GB VRAM for the complete mannequin
ollama pull qwen3-coder

# Devstral-Small -- particularly designed for agentic coding workflows
# Group-tested for Claude Code compatibility
# 24B, requires 16+ GB VRAM
ollama pull devstral-small-2:24b

# Confirm the mannequin is downloaded and prepared
ollama checklist
# Exhibits all pulled fashions with their sizes and modification dates

 

// Configuring Claude Code to Use Ollama

Possibility 1: Shell export (present terminal session solely)

# Redirect Claude Code to your native Ollama server
export ANTHROPIC_BASE_URL="http://localhost:11434"

# Native servers don't require actual authentication
# Set these to any non-empty string -- Ollama ignores the worth
export ANTHROPIC_API_KEY="ollama"
export ANTHROPIC_AUTH_TOKEN="ollama"

# Map Claude Code's mannequin tier requests to your native mannequin title
# Claude Code internally requests sonnet/haiku/opus -- these variables
# translate these tier names to no matter mannequin you've pulled regionally
export ANTHROPIC_DEFAULT_SONNET_MODEL="glm-4.7-flash:newest"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="glm-4.7-flash:newest"
export ANTHROPIC_DEFAULT_OPUS_MODEL="glm-4.7-flash:newest"

# Launch Claude Code -- it is going to now use Ollama as an alternative of the Anthropic API
claude

 

Possibility 2: ~/.claude/settings.json (everlasting, applies to all classes)

This strategy survives terminal restarts and applies each time you launch Claude Code. Claude Code reads surroundings variables from settings.json at startup in order that they take impact regardless of how claude was launched.

Create or edit ~/.claude/settings.json:

{
  "env": {
    "ANTHROPIC_BASE_URL": "http://localhost:11434",
    "ANTHROPIC_API_KEY": "ollama",
    "ANTHROPIC_AUTH_TOKEN": "ollama",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.7-flash:newest",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.7-flash:newest",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.7-flash:newest"
  }
}

 

Possibility 3: .env file in venture listing (per-project override)

If you would like a selected venture to make use of a unique mannequin whereas conserving your international settings on the Anthropic API:

# .env in your venture root -- loaded robotically by Claude Code
ANTHROPIC_BASE_URL=http://localhost:11434
ANTHROPIC_API_KEY=ollama
ANTHROPIC_AUTH_TOKEN=ollama
ANTHROPIC_DEFAULT_SONNET_MODEL=qwen3-coder
ANTHROPIC_DEFAULT_HAIKU_MODEL=qwen3-coder
ANTHROPIC_DEFAULT_OPUS_MODEL=qwen3-coder

 

Confirm the connection:

# Launch Claude Code with a easy take a look at
claude

# Inside Claude Code, run a fundamental immediate:
# > What mannequin are you working?
# An area mannequin ought to reply with out making any Anthropic API calls.

# To verify no exterior calls are being made, run with verbose logging:
claude --verbose

# Search for traces exhibiting requests going to localhost:11434
# relatively than api.anthropic.com

 

Full working sequence from scratch:

curl -fsSL https://ollama.com/set up.sh | sh          # 1. Set up Ollama
ollama pull glm-4.7-flash:newest                       # 2. Pull mannequin (~4 GB)
export ANTHROPIC_BASE_URL="http://localhost:11434"     # 3. Redirect Claude Code
export ANTHROPIC_API_KEY="ollama"                      # 4. Set placeholder auth
export ANTHROPIC_AUTH_TOKEN="ollama"
export ANTHROPIC_DEFAULT_SONNET_MODEL="glm-4.7-flash:newest"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="glm-4.7-flash:newest"
export ANTHROPIC_DEFAULT_OPUS_MODEL="glm-4.7-flash:newest"
claude                                                  # 5. Launch

 

Backend 2: LM Studio

 
LM Studio is the appropriate alternative if you would like a graphical interface for looking and managing fashions relatively than working fully within the terminal. Since model 0.4.1, it features a native Anthropic-compatible /v1/messages endpoint — the identical path Claude Code expects — so no translation layer or proxy is required.

Conditions:

  • macOS, Home windows, or Linux
  • GPU with 6+ GB VRAM beneficial (CPU-only is feasible however sluggish)
  • Obtain from lmstudio.ai or use the CLI installer for headless servers

Set up and configure LM Studio:

# On a server or VM with out a GUI -- CLI installer
curl -fsSL https://releases.lmstudio.ai/cli/set up.sh | bash

# Or obtain the desktop app from https://lmstudio.ai for GUI use

 

GUI setup steps:

  1. Open LM Studio and seek for a coding mannequin (search “qwen coder” or “devstral”).
  2. Obtain the mannequin. LM Studio handles quantization choice robotically.
  3. Go to the Native Server tab (the <> icon within the left sidebar).
  4. Set the context measurement. LM Studio recommends beginning with a minimum of 25,000 tokens and growing for higher outcomes.
  5. Click on Begin Server.
  6. Observe the port (default: 1234) and replica the mannequin title precisely as proven.

 

Observe: Copy the mannequin identifier precisely. LM Studio shows the precise string you’ll want to cross to ANTHROPIC_DEFAULT_SONNET_MODEL. A mismatch right here is the most typical failure mode.

 

Configure Claude Code:

# Set the bottom URL to LM Studio's native server
export ANTHROPIC_BASE_URL="http://localhost:1234"
export ANTHROPIC_API_KEY="lm-studio"
export ANTHROPIC_AUTH_TOKEN="lm-studio"

# Change the mannequin title with what LM Studio reveals on your loaded mannequin
# Copy it precisely -- together with any model suffix or quantization tag
export ANTHROPIC_DEFAULT_SONNET_MODEL="qwen2.5-coder-32b-instruct"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen2.5-coder-32b-instruct"
export ANTHROPIC_DEFAULT_OPUS_MODEL="qwen2.5-coder-32b-instruct"

 

Or persistently in ~/.claude/settings.json:

{
  "env": {
    "ANTHROPIC_BASE_URL": "http://localhost:1234",
    "ANTHROPIC_API_KEY": "lm-studio",
    "ANTHROPIC_AUTH_TOKEN": "lm-studio",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "qwen2.5-coder-32b-instruct",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "qwen2.5-coder-32b-instruct",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "qwen2.5-coder-32b-instruct"
  }
}

 

Find out how to run:

# 1. Begin the LM Studio server from the GUI (Native Server tab > Begin Server)
# 2. Set surroundings variables
export ANTHROPIC_BASE_URL="http://localhost:1234"
export ANTHROPIC_API_KEY="lm-studio"
export ANTHROPIC_AUTH_TOKEN="lm-studio"
export ANTHROPIC_DEFAULT_SONNET_MODEL="your-model-name-here"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="your-model-name-here"
export ANTHROPIC_DEFAULT_OPUS_MODEL="your-model-name-here"
# 3. Launch
claude

 

Backend 3: llama.cpp

 
llama.cpp is the appropriate alternative if you want direct management over inference parameters — quantization sort, KV cache configuration, batch measurement, thread depend — or when you find yourself working on a server and need the bottom overhead. It has native Anthropic Messages API help, so no proxy or translation layer is required.

Conditions:

  • A GGUF-format mannequin file (obtain from Hugging Face; seek for “GGUF” variations of any mannequin)
  • CUDA-capable GPU for GPU inference, or CPU-only for slower inference
  • CMake and a C++ compiler for supply builds (on Linux/CUDA, supply is beneficial)

Set up llama.cpp:

# macOS -- Homebrew is easiest
brew set up llama.cpp

# Linux with CUDA -- construct from supply for greatest GPU efficiency
git clone https://github.com/ggml-org/llama.cpp
cd llama.cpp
cmake -B construct -DGGML_CUDA=ON          # Allow CUDA acceleration
cmake --build construct --config Launch   # Construct
# Binaries in ./construct/bin/

# Linux CPU-only construct
cmake -B construct
cmake --build construct --config Launch

# Home windows -- pre-built binaries accessible at:
# https://github.com/ggml-org/llama.cpp/releases
# Obtain the CUDA or CPU variant matching your {hardware}

 

Obtain a GGUF mannequin:

# Set up the Hugging Face CLI should you don't have it
pip set up huggingface-hub

# Obtain GLM-4.7-Flash in Q4_K_XL quantization (~4.5 GB)
# This quantization provides a superb measurement/high quality stability for coding
huggingface-cli obtain unsloth/GLM-4.7-Flash-GGUF 
  GLM-4.7-Flash-UD-Q4_K_XL.gguf 
  --local-dir ./fashions/

# Or obtain Qwen3-Coder in This fall quantization (~15 GB for 32B)
huggingface-cli obtain Qwen/Qwen3-Coder-32B-Instruct-GGUF 
  qwen3-coder-32b-instruct-q4_k_m.gguf 
  --local-dir ./fashions/

 

Begin the llama.cpp server:

# Begin llama-server with Anthropic API help and a 128K context window
llama-server 
  --model ./fashions/GLM-4.7-Flash-UD-Q4_K_XL.gguf 
  --alias "glm-4.7-flash"           # This title goes in ANTHROPIC_DEFAULT_SONNET_MODEL
  --port 8001 
  --ctx-size 131072                 # 128K context -- necessary for giant codebases
  --flash-attn                      # Reminiscence-efficient consideration, improves velocity
  --n-gpu-layers 99                  # Offload all layers to GPU; take away for CPU-only

# For CPU-only inference (no GPU):
llama-server 
  --model ./fashions/GLM-4.7-Flash-UD-Q4_K_XL.gguf 
  --alias "glm-4.7-flash" 
  --port 8001 
  --ctx-size 32768                  # Scale back context measurement on CPU to maintain reminiscence manageable
  --threads 8                        # Match your CPU core depend

 

Key flags defined:

  • --alias: the mannequin title string Claude Code will ship in requests. Set ANTHROPIC_DEFAULT_SONNET_MODEL to match this precisely.
  • --ctx-size: context window in tokens. 131072 = 128K. Bigger is best for codebase evaluation however makes use of extra VRAM. Scale back should you get out-of-memory errors.
  • --flash-attn: Flash Consideration reduces peak VRAM by processing consideration in smaller blocks. Allow it at any time when your construct helps it.
  • --n-gpu-layers 99: offloads all transformer layers to the GPU. The server robotically makes use of fewer layers if VRAM is tight.

Configure Claude Code:

export ANTHROPIC_BASE_URL="http://localhost:8001"
export ANTHROPIC_API_KEY="llama-cpp"
export ANTHROPIC_AUTH_TOKEN="llama-cpp"

# Should match the --alias you handed to llama-server precisely
export ANTHROPIC_DEFAULT_SONNET_MODEL="glm-4.7-flash"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="glm-4.7-flash"
export ANTHROPIC_DEFAULT_OPUS_MODEL="glm-4.7-flash"

 

Find out how to run:

# Terminal 1: begin the llama.cpp server
llama-server 
  --model ./fashions/GLM-4.7-Flash-UD-Q4_K_XL.gguf 
  --alias "glm-4.7-flash" 
  --port 8001 
  --ctx-size 131072 
  --flash-attn 
  --n-gpu-layers 99

# Terminal 2: configure and launch Claude Code
export ANTHROPIC_BASE_URL="http://localhost:8001"
export ANTHROPIC_API_KEY="llama-cpp"
export ANTHROPIC_AUTH_TOKEN="llama-cpp"
export ANTHROPIC_DEFAULT_SONNET_MODEL="glm-4.7-flash"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="glm-4.7-flash"
export ANTHROPIC_DEFAULT_OPUS_MODEL="glm-4.7-flash"
claude

 

The Full settings.json

 
Surroundings variable exports final solely so long as the terminal session. For a sturdy configuration, use ~/.claude/settings.json. Claude Code reads variables from this file at startup in order that they apply regardless of how Claude was launched — from the terminal, from a VS Code job, or from a script.

Here’s a production-ready settings.json with all variables defined:

{
  "env": {
    "ANTHROPIC_BASE_URL": "http://localhost:11434",

    "ANTHROPIC_API_KEY": "ollama",
    "ANTHROPIC_AUTH_TOKEN": "ollama",

    "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.7-flash:newest",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.7-flash:newest",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.7-flash:newest",

    "CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
  }
}

 

Why CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS: "1" issues:

When utilizing Claude Code by non-Anthropic backends, Claude Code provides Anthropic-specific experimental beta flags to request headers — flags that third-party and native servers don’t acknowledge. This causes Error: Sudden worth(s) for the anthropic-beta header on most native inference servers. Setting this variable to "1" strips these headers earlier than the request goes out, which eliminates the error with out affecting any core Claude Code performance.

Switching between backends:

In the event you work with a number of backends — Ollama for each day use, the Anthropic API for advanced duties — the cleanest strategy is sustaining separate shell scripts relatively than enhancing settings.json forwards and backwards:

# use-local.sh -- change to Ollama
export ANTHROPIC_BASE_URL="http://localhost:11434"
export ANTHROPIC_API_KEY="ollama"
export ANTHROPIC_AUTH_TOKEN="ollama"
export ANTHROPIC_DEFAULT_SONNET_MODEL="glm-4.7-flash:newest"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="glm-4.7-flash:newest"
export ANTHROPIC_DEFAULT_OPUS_MODEL="glm-4.7-flash:newest"
echo "Claude Code → native Ollama (glm-4.7-flash)"

 

# use-anthropic.sh -- change again to the Anthropic API
unset ANTHROPIC_BASE_URL
unset ANTHROPIC_AUTH_TOKEN
unset ANTHROPIC_DEFAULT_SONNET_MODEL
unset ANTHROPIC_DEFAULT_HAIKU_MODEL
unset ANTHROPIC_DEFAULT_OPUS_MODEL
# ANTHROPIC_API_KEY ought to already be set to your actual key in your rc file
echo "Claude Code → Anthropic API"

 

Supply both script in your present session:

supply ./use-local.sh
claude

# Whenever you want the true API for a posh job:
supply ./use-anthropic.sh
claude

 

Greatest Native Fashions for Claude Code in 2026

 
{Hardware} is the primary constraint. For Claude Code with native fashions to be genuinely usable for coding duties relatively than only a demo, intention for 32 GB of RAM — Apple Silicon unified reminiscence or PC RAM. 16 GB is viable with smaller quantized fashions and CPU offload, however technology velocity might be noticeably slower on multi-step agentic duties.

 

Mannequin VRAM Wanted Context Strengths License Pull Command
glm-4.7-flash 8 GB 128K Software calling, quick, low VRAM Apache 2.0 ollama pull glm-4.7-flash
devstral-small-2:24b 16 GB 32K Agentic coding workflows Apache 2.0 ollama pull devstral-small-2:24b
qwen3-coder 20 GB 128K Code technology, directions Apache 2.0 ollama pull qwen3-coder
qwen3.5:27b 20 GB 256K Robust all-round, enormous context Apache 2.0 ollama pull qwen3.5:27b
gemma4:26b 20 GB 256K Reasoning, 77% coding bench Gemma License ollama pull gemma4:26b

 

Troubleshooting Frequent Points

 

  1. Connection refused when launching Claude Code: The inference server isn’t working. That is the most typical difficulty and the simplest to diagnose.
    # Examine if Ollama is working
    curl http://localhost:11434
    # Anticipated: "Ollama is working"
    
    # Examine if LM Studio server is working
    curl http://localhost:1234/v1/fashions
    # Ought to return a JSON checklist of loaded fashions
    
    # Examine if llama-server is working
    curl http://localhost:8001/well being
    # Ought to return {"standing":"okay"}
    
    # If not working -- begin the server first, then launch Claude Code
    ollama serve          # Ollama
    # LM Studio: use the GUI Native Server tab
    # llama.cpp: run the llama-server command from the Backend 3 part

     

  2. Mannequin not discovered or unknown mannequin error: The mannequin title in your ANTHROPIC_DEFAULT_SONNET_MODEL doesn’t match what the server is aware of.
    # Checklist all fashions Ollama has accessible
    ollama checklist
    
    # The mannequin title in ANTHROPIC_DEFAULT_SONNET_MODEL should match EXACTLY
    # together with the tag -- "glm-4.7-flash:newest" not "glm-4.7-flash"
    
    # Confirm with a direct API name to substantiate what the server sees
    curl http://localhost:11434/v1/fashions

     

  3. Software calls failing or returning errors: For streaming instrument calls, which Claude Code makes use of when executing features or scripts, Ollama model 0.14.3-rc1 or later is required. Earlier variations within the 0.14.x collection had incomplete streaming instrument name help.
    # Examine your Ollama model
    ollama model
    
    # If beneath 0.14.3, replace Ollama
    curl -fsSL https://ollama.com/set up.sh | sh

     

  4. anthropic-beta header error:

    You will note: Error: Sudden worth(s) for the anthropic-beta header. This occurs as a result of Claude Code provides Anthropic-specific experimental beta flags that native servers don’t acknowledge. Repair it by including this to your settings.json env block:

    "CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"

     

  5. Reverting to the Anthropic API:
    # Shell session -- unset the redirect variables
    unset ANTHROPIC_BASE_URL
    unset ANTHROPIC_AUTH_TOKEN
    unset ANTHROPIC_DEFAULT_SONNET_MODEL
    unset ANTHROPIC_DEFAULT_HAIKU_MODEL
    unset ANTHROPIC_DEFAULT_OPUS_MODEL
    
    # Then make sure that your actual API secret's set
    echo $ANTHROPIC_API_KEY
    # Ought to present your sk-ant-... key, not a placeholder
    
    # In the event you used settings.json -- take away or remark out the env block
    # and restart Claude Code

     

  6. Gradual technology velocity: For agentic Claude Code duties, technology velocity issues as a result of every instrument name is a spherical journey. If velocity is insufficient:
    • Swap to a smaller or extra aggressively quantized mannequin (Q4_K_M as an alternative of Q8).
    • Allow --flash-attn in llama.cpp if not already set.
    • Scale back context measurement (--ctx-size); bigger contexts are slower to prefill.
    • On Ollama, set OLLAMA_NUM_GPU_LAYERS=99 in your surroundings to pressure most GPU offload.

 

Conclusion

 
What used to require fragile adapters and hacks is now a five-step course of. Set up the inference backend, pull a mannequin, set three surroundings variables, and Claude Code routes to your native machine as an alternative of Anthropic’s API. The configuration takes below 5 minutes upon getting the mannequin downloaded.

The sensible result’s a coding assistant that prices nothing to run after setup, has no price limits, retains your code fully in your machine, and covers the overwhelming majority of actual coding use circumstances at high quality ranges that weren’t accessible in native fashions a 12 months in the past. Begin with Ollama and glm-4.7-flash — it has the bottom {hardware} requirement, probably the most constant tool-calling help, and the quickest path to a working setup. As soon as that’s working, scale up the mannequin based mostly in your {hardware} and the standard stage you really need.
 
 

Shittu Olumide is a software program engineer and technical author captivated with leveraging cutting-edge applied sciences to craft compelling narratives, with a eager eye for element and a knack for simplifying advanced ideas. You too can discover Shittu on Twitter.



Related Articles

Latest Articles