Introduction

 
Visualize this: a multi-agent workflow that reads recordsdata, writes patches, runs assessments, and iterates throughout 4 companies, making 400 API calls in a single afternoon. The notification arrives. You could have crossed the gentle restrict once more. Each token prices cash, each immediate sends your proprietary code to a third-party server, and the speed limits interrupt long-running classes — the one resolution is paying extra.

Gemma 4 26B MoE prompts solely 3.8 billion of its 26 billion parameters per ahead go. It scores 77.1% on LiveCodeBench v6 and 86.4% on τ2-bench agentic device use — the benchmark that particularly assessments what occurs when a mannequin has to name instruments, execute steps, and deal with errors throughout a multi-step workflow. The earlier technology, Gemma 3 27B, scored 6.6% on that very same benchmark. That’s not a small improve. It’s the distinction between a mannequin that can’t reliably name instruments and one that may run a Claude Code agentic loop with out always malforming its operate name parameters.

This text builds the total stack: Ollama serving Gemma 4 regionally, the Modelfile that stops context window failures in agentic classes, the settings.json that wires Claude Code to the native endpoint, a verification script that confirms all the pieces is working earlier than you apply it to actual code, and an sincere rundown of what breaks and repair it. The viewers is engineers who already perceive what massive language fashions (LLMs) are and what agentic loops price. No hand-holding on the fundamentals.

 

Why Gemma 4?

 
Launched on April 2, 2026 underneath Apache 2.0, Gemma 4 is Google DeepMind’s most succesful open-weight mannequin household up to now. 4 variants shipped: E2B (2B efficient), E4B (4B efficient), 26B MoE, and 31B Dense. The 26B MoE makes use of 128 small consultants and prompts solely 8 per token plus one shared professional, delivering near-31B high quality at dramatically decrease compute price.

Earlier Gemma variations used a customized Google license with business use restrictions ambiguous sufficient that enterprise authorized groups routinely flagged it as a blocker. Gemma 4 is Apache 2.0, a primary for the Gemma household. In case your group needs to embed this in inner tooling, ship merchandise on high of it, or run it in manufacturing pipelines with out authorized assessment overhead, that change issues operationally.

 

// The Numbers That Matter for Coding Brokers

 

Benchmark Gemma 3 27B Gemma 4 26B MoE Gemma 4 31B Dense
τ2-bench (agentic device use) 6.6% ~79% 86.4%
LiveCodeBench v6 29.1% 77.1% 80.0%
GPQA Diamond 42.4% 82.3% 84.3%
AIME 2026 (math) 20.8% 88.3% 89.2%
Area AI ELO 1365 1441 1452

 

// {Hardware} Necessities

Earlier than pulling an 18 GB mannequin, know what you’re truly working with. The Gemma 4 household was designed to span edge gadgets via workstations, and the 4 variants replicate that vary.

 

Variant Ollama tag Energetic params VRAM at This fall Context window
Edge 4B gemma4:e4b 4B ~6 GB 128K
26B MoE gemma4:26b 3.8B ~16–18 GB 256K
31B Dense gemma4:31b 31B ~24–32 GB 256K

 

// Putting in Ollama, Gemma 4, and Claude Code

Step 1: Set up Ollama

# macOS and Linux -- one-line set up
curl -fsSL  | sh

# Confirm model -- should be 0.14.0+ for Anthropic Messages API assist
# The Anthropic-compatible endpoint was added in January 2026
ollama model
# Anticipated: ollama model is 0.22.x or larger (as of Might 2026)

# Home windows: obtain the native installer from 
# WSL2 is beneficial if you would like GPU passthrough on Home windows

 

After set up, Ollama begins as a background service on port 11434. Confirm it’s up:

curl 
# Anticipated response: Ollama is operating

 

Step 2: Pull Gemma 4

# The 26B MoE -- beneficial for this setup (~18 GB obtain)
ollama pull gemma4:26b

# When you wait, verify the obtain is progressing
ollama ps
# Exhibits at present downloading or operating fashions

# Elective: additionally pull the 31B for comparability on succesful {hardware}
ollama pull gemma4:31b

# Affirm the pull accomplished
ollama listing
# Ought to present gemma4:26b with measurement and modification date

 

Step 3: Set up Claude Code

# Stipulations: Node.js 18 or later
node --version   # Affirm you're on 18+

# Set up Claude Code CLI globally
npm set up -g @anthropic-ai/claude-code

# Confirm the set up
claude --version

 

With Ollama operating and Gemma 4 pulled, the pure subsequent intuition is to export the surroundings variables and launch Claude Code instantly.

 

The Modelfile

 
Ollama‘s default context window for Gemma 4 is 4K tokens. Gemma 4’s precise context window is 128K–256K. That 4K default will not be a suggestion — it’s what Ollama will use until you override it. In a Claude Code agentic session that reads supply recordsdata, holds dialog historical past, and maintains device name outcomes throughout a number of turns, 4K tokens is exhausted in seconds.

With out the context override, Claude Code loses monitor of file contents mid-edit, forgets earlier directions, and produces fragmented adjustments. Particularly: when an agent tries to refactor a 200-line service class, it cleanly forgets the second half exists. The agent doesn’t elevate an error. It simply silently works on an incomplete view of the file and produces partially appropriate output that breaks downstream.

The repair is a Modelfile that bakes the right context measurement and different inference parameters right into a named mannequin variant. Create this file:

# ~/.ollama/Modelfiles/gemma4-claude
# Gemma 4 26B MoE variant tuned for Claude Code agentic classes.
# Bakes context window, temperature, and system immediate into the mannequin
# so each Claude Code session begins with the right configuration.
#
# Construct with:
#   mkdir -p ~/.ollama/Modelfiles
#   ollama create gemma4-claude -f ~/.ollama/Modelfiles/gemma4-claude

FROM gemma4:26b

# Context window -- 65536 tokens (64K) is the tested-safe ground for actual
# codebases with out triggering swap on 16-18 GB VRAM techniques.
# Enhance to 131072 (128K) in case you have headroom on 24 GB+ techniques.
# Don't go above 131072 until you will have profiled your reminiscence utilization
# underneath load -- Ollama pre-allocates the total KV cache upfront.
PARAMETER num_ctx 65536

# Temperature -- 0.2 is intentionally low for agentic coding.
# Increased temperature introduces variability in device name parameter
# formatting that causes Claude Code's device validator to reject calls.
# For artistic duties, you'll set this larger. For agentic loops: low.
PARAMETER temperature 0.2

# top_p -- nucleus sampling threshold. 0.9 retains technology targeted
# whereas avoiding the repetition loops that top_p=1.0 can produce on
# lengthy agentic classes.
PARAMETER top_p 0.9

# repeat_penalty -- penalizes the mannequin for repeating tokens.
# 1.15 helps forestall device name loops the place Gemma 4 retries the identical
# failed device name with practically equivalent parameters indefinitely.
PARAMETER repeat_penalty 1.15

# num_predict -- most tokens per response. 4096 is enough for
# most code patches. Enhance to 8192 should you usually generate
# massive recordsdata in a single technology.
PARAMETER num_predict 4096

# System immediate -- reinforces coding agent habits and express
# device use self-discipline. Gemma 4 advantages from being reminded to
# decide to device calls relatively than describing what it could do.
SYSTEM """You're a senior software program engineer working as a coding agent.

When working with code:
- Learn recordsdata earlier than enhancing them. By no means assume file contents.
- Make one targeted change at a time and confirm it earlier than continuing.
- When a device name fails, study the error rigorously earlier than retrying.
  Don't retry with equivalent parameters. Diagnose first.
- Favor surgical edits over full file rewrites.
- Run assessments after every significant change, not after a batch of adjustments.
- In case you are unsure in regards to the codebase construction, learn extra recordsdata
  relatively than guessing.

Be exact and methodical. Keep away from explaining what you're about to do
when you possibly can merely do it."""

 

Construct the variant:

# Create the Modelfiles listing if it doesn't exist
mkdir -p ~/.ollama/Modelfiles

# Save the Modelfile content material from above to this path, then construct:
ollama create gemma4-claude -f ~/.ollama/Modelfiles/gemma4-claude

# Confirm the variant was created
ollama listing
# Ought to present gemma4-claude alongside gemma4:26b

# Fast smoke check -- confirm it masses and responds
ollama run gemma4-claude "What's the time complexity of binary search and why?"
# Count on a transparent, concise technical response inside a number of seconds

 

Wiring Claude Code to the Native Mannequin

 
With the mannequin variant constructed, the configuration layer connects Claude Code to Ollama. Two surroundings variables are the core of this, however three extra variables forestall the most typical failure modes.

Ollama’s Anthropic-compatible endpoint is at , not /v1. The /v1 path is Ollama’s OpenAI-compatible layer. Claude Code makes use of the Anthropic Messages API protocol, which maps to the foundation endpoint. Utilizing the /v1 path will produce authentication errors or surprising habits.

 

// World Settings — ~/.claude/settings.json

This configuration applies to each Claude Code session throughout all initiatives. It’s the proper selection until you’re switching between native and cloud fashions ceaselessly per mission.

{
  "env": {
    "ANTHROPIC_BASE_URL": "

    "ANTHROPIC_AUTH_TOKEN": "ollama",

    "ANTHROPIC_API_KEY": "",

    "ANTHROPIC_MODEL": "gemma4-claude",

    "ANTHROPIC_DEFAULT_SONNET_MODEL": "gemma4-claude",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "gemma4-claude",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "gemma4-claude",

    "CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
  }
}

 

Why every variable issues:

  • ANTHROPIC_BASE_URL redirects all Claude Code API calls from Anthropic’s servers to your native Ollama occasion.
  • ANTHROPIC_AUTH_TOKEN should be set to any non-empty string; Ollama ignores the worth however Claude Code requires the header to be current.
  • ANTHROPIC_API_KEY: “” explicitly empties the important thing so Claude Code can not fall again to an actual Anthropic API key if one occurs to be set in your shell surroundings. With out this, a misconfigured ANTHROPIC_BASE_URL may silently fail over to the paid API.
  • ANTHROPIC_MODEL is the first mannequin identify Claude Code sends in requests. Set this to your customized Modelfile variant, gemma4-claude not gemma4:26b. The uncooked mannequin tag doesn’t carry the context window override.
  • ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL, and ANTHROPIC_DEFAULT_OPUS_MODEL: Claude Code internally routes completely different job sorts to completely different mannequin tiers. Setting all three to the identical native mannequin ensures each request lands at your Ollama occasion no matter which tier Claude Code internally selects.
  • CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS: “1” strips the Anthropic-specific beta headers that Claude Code provides to requests. Native inference servers don’t acknowledge these headers and reject requests that embrace them. Setting this variable prevents that error with out affecting any core Claude Code performance.

 

// Per-Mission Configuration — .claude/settings.json

For initiatives the place you need native inference remoted out of your international setup — non-public repositories, delicate codebases, or initiatives with particular mannequin necessities — use a project-level settings file as a substitute:

# In your mission root
mkdir -p .claude

cat > .claude/settings.json << 'EOF'
{
  "env": {
    "ANTHROPIC_BASE_URL": "
    "ANTHROPIC_AUTH_TOKEN": "ollama",
    "ANTHROPIC_API_KEY": "",
    "ANTHROPIC_MODEL": "gemma4-claude",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "gemma4-claude",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "gemma4-claude",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "gemma4-claude",
    "CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
  }
}
EOF

 

Claude Code reads the project-level .claude/settings.json when it exists, overriding international settings for that mission. Add .claude/settings.json to your .gitignore if the settings comprise something environment-specific, or commit it if you would like all the group operating native inference on that mission.

 

// Verifying the Setup

Earlier than operating Claude Code towards an actual codebase, confirm three issues: Ollama is serving appropriately, the mannequin responds to API calls within the Anthropic Messages format, and gear calling particularly works. The third level is non-negotiable: device calling is how Claude Code reads recordsdata, writes patches, and executes instructions. A mannequin that can’t format device calls appropriately will loop and fail on primary agentic duties.

Stipulations:

pip set up httpx   # Async HTTP shopper for the verification script

 

The complete verification script:


#!/usr/bin/env python3
"""
verify_local_setup.py

Verifies the total Claude Code + Ollama + Gemma 4 stack earlier than use.
Runs three checks in sequence:
  1. Ollama well being and mannequin availability
  2. Primary Anthropic Messages API name
  3. Instrument calling round-trip

Stipulations:
  pip set up httpx

Easy methods to run:
  python verify_local_setup.py

Anticipated output on a working setup:
  [PASS] Ollama is operating on localhost:11434
  [PASS] Mannequin 'gemma4-claude' is accessible
  [PASS] Anthropic Messages API name profitable
  [PASS] Instrument calling: mannequin produced a legitimate tool_use block
  All checks handed -- Claude Code + Ollama + Gemma 4 is prepared.
"""

import httpx
import json
import sys

# ── Configuration ─────────────────────────────────────────────────────────────
OLLAMA_BASE_URL = "
MODEL_NAME      = "gemma4-claude"   # Should match your Modelfile variant identify
TIMEOUT         = 120.0             # Seconds -- technology might be sluggish on first name


def check_ollama_health() -> bool:
    """
    Test 1: Confirm Ollama is operating and responding.
    Hits the foundation endpoint which returns 'Ollama is operating' when wholesome.
    """
    print("nCheck 1: Ollama well being")
    attempt:
        response = httpx.get(OLLAMA_BASE_URL, timeout=5.0)
        if "Ollama is operating" in response.textual content:
            print(f"  [PASS] Ollama is operating on {OLLAMA_BASE_URL}")
            return True
        else:
            print(f"  [FAIL] Surprising response: {response.textual content[:100]}")
            return False
    besides httpx.ConnectError:
        print(f"  [FAIL] Can not connect with {OLLAMA_BASE_URL}")
        print("         Is Ollama operating? Strive: ollama serve")
        return False


def check_model_available() -> bool:
    """
    Test 2: Confirm the precise mannequin variant is accessible in Ollama.
    Makes use of the /api/tags endpoint which lists all pulled fashions.
    """
    print("nCheck 2: Mannequin availability")
    attempt:
        response = httpx.get(f"{OLLAMA_BASE_URL}/api/tags", timeout=5.0)
        knowledge     = response.json()
        fashions   = [m["name"] for m in knowledge.get("fashions", [])]

        # Normalize: Ollama might add ":newest" if not specified
        normalized = [m.split(":")[0] for m in fashions]

        if MODEL_NAME in fashions or MODEL_NAME in normalized:
            print(f"  [PASS] Mannequin '{MODEL_NAME}' is accessible")
            return True
        else:
            print(f"  [FAIL] Mannequin '{MODEL_NAME}' not discovered")
            print(f"         Accessible fashions: {', '.be part of(fashions) or 'none'}")
            print(f"         Run: ollama create {MODEL_NAME} -f ~/.ollama/Modelfiles/gemma4-claude")
            return False
    besides Exception as e:
        print(f"  [FAIL] Error checking mannequin listing: {e}")
        return False


def check_messages_api() -> bool:
    """
    Test 3: Ship a primary Anthropic Messages API name to the native endpoint.
    Verifies the request format, mannequin routing, and primary technology work.
    Makes use of the identical /v1/messages path and request schema that Claude Code makes use of.
    Notice: Claude Code makes use of  (root), not /v1.
    The Anthropic-compatible API is at /api/chat or the foundation -- Ollama routes it.
    """
    print("nCheck 3: Anthropic Messages API name")

    payload = {
        "mannequin": MODEL_NAME,
        "max_tokens": 100,
        "messages": [
            {
                "role": "user",
                "content": "Reply with exactly: VERIFICATION_OK"
            }
        ]
    }

    headers = {
        "Content material-Kind":      "utility/json",
        "x-api-key":         "ollama",            # Required by the API spec; worth ignored regionally
        "anthropic-version": "2023-06-01"         # Required model header
    }

    attempt:
        response = httpx.publish(
            f"{OLLAMA_BASE_URL}/v1/messages",
            json=payload,
            headers=headers,
            timeout=TIMEOUT
        )

        if response.status_code != 200:
            print(f"  [FAIL] HTTP {response.status_code}: {response.textual content[:200]}")
            return False

        knowledge = response.json()

        # Anthropic Messages API response construction:
        # { "content material": [{"type": "text", "text": "..."}], "stop_reason": "..." }
        content_blocks = knowledge.get("content material", [])
        text_blocks    = [b for b in content_blocks if b.get("type") == "text"]

        if not text_blocks:
            print(f"  [FAIL] No textual content content material in response: {json.dumps(knowledge, indent=2)}")
            return False

        response_text = text_blocks[0].get("textual content", "")
        print(f"  [PASS] Anthropic Messages API name profitable")
        print(f"         Mannequin response: {response_text[:80]}")
        return True

    besides Exception as e:
        print(f"  [FAIL] Request failed: {e}")
        return False


def check_tool_calling() -> bool:
    """
    Test 4: Confirm device calling works end-to-end.
    That is an important test for Claude Code agentic use.
    Claude Code depends on the mannequin appropriately producing tool_use blocks
    for each file operation, shell command, and code execution.

    Sends a easy device definition and a immediate that ought to set off it.
    Verifies the mannequin returns a tool_use block (not simply textual content describing the decision).
    """
    print("nCheck 4: Instrument calling verification")

    # A minimal device definition utilizing the Anthropic operate calling schema
    instruments = [
        {
            "name": "read_file",
            "description": "Read the contents of a file at the given path.",
            "input_schema": {
                "type": "object",
                "properties": {
                    "path": {
                        "type": "string",
                        "description": "The absolute or relative file path to read"
                    }
                },
                "required": ["path"]
            }
        }
    ]

    payload = {
        "mannequin": MODEL_NAME,
        "max_tokens": 256,
        "instruments": instruments,
        # Drive the mannequin to name a device relatively than reply in textual content.
        # tool_choice: {"kind": "any"} requires any device use.
        # Take away this if testing whether or not the mannequin self-selects instruments.
        "tool_choice": {"kind": "any"},
        "messages": [
            {
                "role": "user",
                "content": "Read the file at /tmp/test.py and show me its contents."
            }
        ]
    }

    headers = {
        "Content material-Kind":      "utility/json",
        "x-api-key":         "ollama",
        "anthropic-version": "2023-06-01"
    }

    attempt:
        response = httpx.publish(
            f"{OLLAMA_BASE_URL}/v1/messages",
            json=payload,
            headers=headers,
            timeout=TIMEOUT
        )

        if response.status_code != 200:
            print(f"  [FAIL] HTTP {response.status_code}: {response.textual content[:200]}")
            return False

        knowledge           = response.json()
        content_blocks = knowledge.get("content material", [])
        tool_blocks    = [b for b in content_blocks if b.get("type") == "tool_use"]

        if not tool_blocks:
            print("  [FAIL] Mannequin didn't produce a tool_use block")
            print("         This implies device calling will not be working appropriately.")
            print("         Agentic Claude Code classes will fail on file operations.")
            print(f"         Full response: {json.dumps(knowledge, indent=2)}")
            return False

        tool_call  = tool_blocks[0]
        tool_name  = tool_call.get("identify", "")
        tool_input = tool_call.get("enter", {})

        print(f"  [PASS] Instrument calling: mannequin produced a legitimate tool_use block")
        print(f"         Instrument referred to as: {tool_name}")
        print(f"         Parameters:  {json.dumps(tool_input)}")

        # Sanity test: did it name the appropriate device with the appropriate parameter?
        if tool_name == "read_file" and "path" in tool_input:
            print(f"         Instrument identify and parameter are appropriate.")
        else:
            print(f"         WARNING: Surprising device identify or lacking 'path' parameter.")
            print(f"         The mannequin referred to as a device however not the anticipated one.")

        return True

    besides Exception as e:
        print(f"  [FAIL] Request failed: {e}")
        return False


def principal():
    print("=" * 60)
    print("Claude Code + Ollama + Gemma 4 Setup Verification")
    print("=" * 60)

    checks = [
        check_ollama_health,
        check_model_available,
        check_messages_api,
        check_tool_calling,
    ]

    outcomes = [check() for check in checks]

    print("n" + "=" * 60)
    handed = sum(outcomes)
    complete  = len(outcomes)

    if all(outcomes):
        print(f"All {complete} checks handed.")
        print("Claude Code + Ollama + Gemma 4 is prepared.")
        print(f"nLaunch with: claude")
        sys.exit(0)
    else:
        failed_checks = [i + 1 for i, r in enumerate(results) if not r]
        print(f"{handed}/{complete} checks handed. Failed: {failed_checks}")
        print("Resolve the failures above earlier than utilizing Claude Code regionally.")
        sys.exit(1)


if __name__ == "__main__":
    principal()

 

Easy methods to run:

pip set up httpx
python verify_local_setup.py

 

Agentic Job Walkthrough

 
With verification passing, here’s what an actual agentic session seems to be like. The duty: take an present Python module with no assessments, analyze it, write a check suite, run the assessments, and repair any failures.

# Navigate to a mission listing
cd ~/initiatives/my-service

# Affirm Claude Code sees the native configuration
claude --version
# Confirm it doesn't immediate for an Anthropic API key -- if it does,
# the settings.json will not be being learn appropriately

# Begin an agentic session
claude

# Inside Claude Code, give the agent a concrete job:
# > Analyze the UserService class in src/user_service.py.
# > Write a pytest check suite protecting all public strategies.
# > Run the assessments and repair any failures.
# > The purpose is a clear pytest run with no skips.

 

What the Claude Code device name hint seems to be like throughout this session:

→ read_file("src/user_service.py")
  Studying 247 traces...

→ list_files("src/")
  Discovered: user_service.py, fashions.py, db.py, exceptions.py

→ read_file("src/fashions.py")
  Studying 89 traces...

→ write_file("assessments/test_user_service.py", [test content])
  Written: 312 traces

→ bash("python -m pytest assessments/test_user_service.py -v 2>&1")
  Working 14 assessments...
  FAILED assessments/test_user_service.py::test_update_email_invalid
    AssertionError: Anticipated ValidationError, obtained None

→ read_file("src/user_service.py")  [targeted re-read of update_email method]
  ...

→ write_file("assessments/test_user_service.py", [corrected test])
  Patched test_update_email_invalid assertion

→ bash("python -m pytest assessments/test_user_service.py -v 2>&1")
  14 handed in 1.23s

 

Gemma 4 handles this sample reliably — studying recordsdata earlier than enhancing, operating assessments after adjustments, and diagnosing failures from error output relatively than retrying blindly. The habits on advanced architectural choices throughout many recordsdata is the place cloud fashions nonetheless have an edge. For the duty above (evaluation, check technology, and focused fixes), the native setup is absolutely succesful.

What to observe for: When you see the agent produce “Invalid device parameters” errors after which retry with the identical parameters repeatedly, the temperature is simply too excessive, or the mannequin will not be utilizing the gemma4-claude Modelfile variant. Each temperature and the context window override are baked into the variant; the uncooked gemma4:26b tag doesn’t carry them.

 

// What Breaks and Easy methods to Repair It

  1. Instrument Parameter Formatting Errors

    • Symptom: Claude Code stories Invalid device parameters repeatedly. The agent apologizes and retries with equivalent or practically equivalent parameters, then loops.
    • Trigger: That is documented within the Ollama GitHub points. The mannequin produces device name JSON that doesn’t match the schema Claude Code expects. Mostly: flawed subject names, lacking required fields, or nested objects the place scalars are anticipated.
    • Repair: Affirm you’re operating gemma4-claude (the Modelfile variant) not gemma4:26b instantly. The temperature: 0.2 and system immediate within the Modelfile considerably cut back this. If the difficulty persists, drop the temperature to 0.1 within the Modelfile and rebuild.
  2. Context Window Swapping to Disk

    • Symptom: Technology slows to a crawl after a number of turns. ollama ps exhibits GPU utilization dropping. The OS is paging the KV cache to disk.
    • Repair:
      # Choice 1: Cut back context window within the Modelfile
      # Edit ~/.ollama/Modelfiles/gemma4-claude
      # Change: PARAMETER num_ctx 65536
      # To:     PARAMETER num_ctx 32768
      # Then rebuild: ollama create gemma4-claude -f ~/.ollama/Modelfiles/gemma4-claude
      
      # Choice 2: Allow KV cache quantization to scale back reminiscence footprint
      export OLLAMA_KV_CACHE_TYPE=q8_0
      # This quantizes the KV cache itself, lowering reminiscence at a small high quality price
      # Restart Ollama after setting this: pkill ollama && ollama serve

       

  3. Mannequin Unloading Between Agent Turns

    • Symptom: Noticeable cold-start delay at the start of every Claude Code message. Ollama is unloading the mannequin after an inactivity timeout and reloading it for every request.
    • Repair:
      # Preserve the mannequin loaded indefinitely throughout your work session
      export OLLAMA_KEEP_ALIVE=-1
      
      # Or set it in your shell profile for everlasting impact
      echo 'export OLLAMA_KEEP_ALIVE=-1' >> ~/.zshrc
      
      # Alternatively, use the Ollama API to pin the mannequin
      curl /api/generate 
        -d '{"mannequin": "gemma4-claude", "keep_alive": -1}'
      # This pins the mannequin till you explicitly unload it or restart Ollama

       

  4. Beta Header Rejection Errors

    • Symptom: Claude Code produces Surprising worth(s) for the anthropic-beta header errors on launch or mid-session.
    • Repair: Affirm CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS: "1" is in your settings.json. When you set it by way of shell export as a substitute of settings.json, confirm it’s exported in the identical shell session the place claude is operating:
      echo $CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS
      # Should print: 1

       

Wrapping Up

 
The stack described on this article will not be a proof of idea. It’s a working manufacturing configuration that engineers have been operating day by day since Ollama added Anthropic Messages API assist in January 2026. The Modelfile will not be elective; it’s the distinction between a device that works and one which silently produces incomplete outputs on multi-file duties. The verification script catches configuration points earlier than they floor mid-session as complicated agent failures.

The setup constructed on this article is a personal, zero-per-token-cost coding agent that handles the vast majority of day by day engineering duties — code evaluation, check technology, focused refactoring, and debugging — at technology speeds which are usable on trendy {hardware}.

This setup will not be a alternative for cloud inference on advanced architectural reasoning throughout massive codebases or SWE-bench class duties that require deep repository understanding at scale.
 
 

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