Ollama v0.40 on Linux: Launch Claude Code & Deferred MCP
This deep-dive covers ollama launch claude linux with actionable analysis, practical implications, and expert insights.
Quick answer: Upgrade to Ollama v0.40.19 on Linux with curl -fsSL https://ollama.com/install.sh | sh, lock a 64k+ context window by adding Environment="OLLAMA_CONTEXT_LENGTH=64000" via sudo systemctl edit ollama, and launch terminal agents with ollama launch claude or ollama launch opencode so MCP tools use deferred loading instead of exhausting local VRAM.
Shipping across November 2026 from v0.40.16 through v0.40.19 (with v0.40.20-rc1 tagged on November 28), Ollama turned ollama launch into a first-class orchestrator for terminal coding agents on Linux. Instead of hand-wiring ANTHROPIC_BASE_URL exports or watching 20 Model Context Protocol (MCP) servers consume your entire prompt budget on turn one, the v0.40 series introduces deferred MCP tool loading, stricter model routing, and updated llama.cpp (b12651) and llama-server backends.
If you already track local runtime trade-offs in our llama.cpp v1.0 vs Ollama on Linux guide or compare throughput in vLLM vs Ollama production benchmarks, this walkthrough shows how to configure ollama launch cleanly on Ubuntu and Debian workstations.
What Changed in Ollama v0.40.17 Through v0.40.19 for Agents
Before v0.40.17, connecting an agentic CLI to a local model broke down in two predictable places: every registered MCP server serialized its full JSON schema upfront, and strict schema filtering stripped custom keywords that tool runners expected. The November 2026 point releases address both bottlenecks directly.
| Release Tag | Date | Key Agent & Linux Runtime Changes |
|---|---|---|
v0.40.16 |
Nov 9, 2026 | ollama launch claude always routes to the selected model; /v1/responses honors truncation; /v1/models returns [] instead of null |
v0.40.17 |
Nov 10, 2026 | Deferred tool loading in ollama launch claude; JSON schema keywords preserved; OpenCode thinking metadata; Vulkan mmap fix for Linux iGPUs |
v0.40.18 |
Nov 24, 2026 | Bumps bundled llama.cpp backend to b12651; drops legacy NVIDIA JetPack 5 support |
v0.40.19 |
Nov 26, 2026 | Updates llama-server and tightens short-history and buffer compaction paths |
Deferred tool loading is the standout win for Linux developers running 8B to 32B coding weights. Rather than injecting dozens of MCP tool schemas into every turn, Claude Code advertises lightweight stubs and loads full MCP tool definitions only when the model requests them.
Step 1: Upgrade Ollama on Linux and Verify the Binary
On Ubuntu, Debian, Fedora, or Arch Linux, run the official installer to update the daemon and systemd unit to v0.40.19, then confirm both the client and server version:
curl -fsSL https://ollama.com/install.sh | sh
ollama --version
systemctl status ollama --no-pager
If you run coding models alongside local MCP servers, make sure those MCP processes do not have unrestricted filesystem or shell access. Pair your agent runtime with the isolation patterns in our guide on how to sandbox local MCP servers on Linux with systemd.
Step 2: Lock a 64k Context Window in systemd
The single most common failure when pairing ollama launch with Claude Code or OpenCode happens silently: Ollama picks default context windows based on detected VRAM:
- Under 24 GiB VRAM: 4,096 tokens (
4k) by default - 24 GiB to 48 GiB VRAM: 32,768 tokens (
32k) by default - 48 GiB VRAM or more: 262,144 tokens (
256k) by default
Both Claude Code and OpenCode require at least 64,000 tokens to index repository trees, read multi-file diffs, and process tool outputs reliably. On a 12 GB or 16 GB NVIDIA GPU, leaving the default 4k limit causes constant context eviction and broken tool loops. Override the systemd service instead of setting transient shell variables:
sudo systemctl edit ollama
Add the environment override inside the drop-in editor and save:
[Service]
Environment="OLLAMA_CONTEXT_LENGTH=64000"
Reload systemd and restart the daemon, then verify that your model loads onto the GPU with the full context budget:
sudo systemctl daemon-reload
sudo systemctl restart ollama
ollama run qwen3.5 "Reply with OK"
ollama ps
Check the PROCESSOR and CONTEXT columns in ollama ps. You want 100% GPU (or high GPU offload) and 64000 or higher under CONTEXT. If your workstation relies on CPU spillover, watch latency closely or test quantized weights first.
Step 3: Launch Claude Code, OpenCode, or Codex via ollama launch
The ollama launch command configures and starts supported terminal agents (claude, opencode, codex, and droid) without manual config edits. Install Claude Code first if it is not on your PATH:
curl -fsSL https://claude.ai/install.sh | bash
ollama launch claude --model qwen3.5
For headless scripts, cron jobs, or CI containers where interactive model pickers would hang, pass --yes alongside --model (--yes requires --model and automatically pulls missing weights), then forward agent flags after --:
ollama launch claude --model qwen3.5 --yes -- -p "Audit this repo for shell injection risks"
If you prefer an open-source terminal agent, OpenCode works out of the box with local models and reads thinking options from model metadata as of v0.40.17:
curl -fsSL https://opencode.ai/install | bash
ollama launch opencode --model qwen3.5
Note the configuration precedence rule: ollama launch opencode injects an inline configuration for the selected model without overwriting ~/.config/opencode/opencode.json. If you only want Ollama to generate provider configuration without launching an interactive terminal session, run:
ollama launch opencode --config
If you run headless inference on a separate Linux box or prefer an OpenAI-compatible daemon workflow, compare this workflow against running LM Studio headless on Linux with llmster and lms CLI.
Step 4: Verify Deferred MCP Tool Loading and Model Offloading
When you pair Claude Code with multiple Model Context Protocol servers, prompt bloat used to trigger immediate KV cache pressure on 12 GB to 24 GB Linux GPUs. With deferred tool loading active in ollama launch claude (v0.40.17+), MCP server tool schemas stay unloaded until the agent explicitly resolves a tool name for the current subtask.
To confirm your local GPU is handling the active session without falling back to slow system RAM, open a second terminal while an agent run is active and inspect the live runner state:
ollama ps
Verify two fields in the output table: PROCESSOR should report 100% GPU rather than a CPU split, and CONTEXT should show 64000 (or your configured target) rather than 4096. If the model drops to partial CPU offload on a 16 GB card, step down to a tighter quantization tag or reduce concurrent background services before raising context further. Note also that starting in v0.40.17, toggling context shift settings no longer forces a full model reload, making iterative tuning faster during long sessions.
Step 5: Manual Anthropic API Fallback and Cloud Routing
When integrating custom scripts or debugging Claude Code directly against Ollama's Anthropic-compatible /v1/messages endpoint, you can set the environment variables explicitly without the launcher:
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3-coder
For larger repositories that exceed local VRAM, Ollama also supports passing --model gemma4:cloud via ollama launch claude, or hitting https://ollama.com directly with OLLAMA_API_KEY set as ANTHROPIC_AUTH_TOKEN. Keep in mind that Ollama's Anthropic compatibility layer supports messages, streaming, and function calling, while hosted web search and strict tool-choice controls remain partially limited compared to native Anthropic endpoints.
Troubleshooting Ollama v0.40 Coding Agents on Linux
- Claude Code ignores local routing and calls Anthropic servers: User or project settings in
~/.claude/settings.jsonoverride exported shell environment variables. Remove stale base URL or API key overrides there, launch viaollama launch claude --model qwen3.5, and run/statusinside Claude Code to verify the active endpoint. - Models defined in opencode.json are missing from the launcher picker:
ollama launchreads models installed in Ollama rather than custom entries inside~/.config/opencode/opencode.json. Pull the model withollama pull <model>or invokeopencodedirectly when using custom external providers. - Tool calls fail with malformed schema errors: Ensure you are running Ollama
v0.40.17or newer so unmodeled JSON schema keywords are preserved in tool payloads rather than silently dropped. - Shared-memory Linux iGPU fails with "Failed to allocate pinned memory": Upgrade to
v0.40.17+, which switches Vulkan integrated GPU buffers tommapallocation. - Context shift tweaks appear to ignore changes or stall VRAM: In
v0.40.17+, changing context shift settings no longer triggers a full model reload, though modifyingOLLAMA_CONTEXT_LENGTHstill requires restarting the systemd unit and confirming withollama ps.
All terminal commands, code snippets, and configuration parameters in this guide were verified in our testing environment before publication. Adjust configuration paths to match your specific distribution.
Was this technical analysis helpful?
Your feedback informs our benchmark updates and ongoing article audits.
FAQ
Frequently Asked Questions
Structured for search engines and AI answer systems (AEO/GEO).
Starting in Ollama v0.40.17, ollama launch claude supports Claude Code's deferred tool loading so MCP tool definitions load on demand instead of flooding the initial prompt. The release also preserves unmodeled JSON schema keywords in tool definitions, while v0.40.18 and v0.40.19 update the underlying llama.cpp and llama-server backends.
By default, Ollama assigns only a 4k context window on GPUs with under 24 GiB of VRAM. Coding agents such as Claude Code and OpenCode require at least 64,000 tokens. Set Environment="OLLAMA_CONTEXT_LENGTH=64000" in your systemd override and verify the allocation with ollama ps.
Pass both --model and --yes, followed by a double dash separator and any agent flags: ollama launch claude --model qwen3.5 --yes -- -p "summarize this repository". The --yes flag skips interactive prompts and pulls the model if it is not already stored locally.
No. Running ollama launch opencode starts OpenCode with an inline provider configuration for the selected model while preserving ~/.config/opencode/opencode.json. If you want Ollama to write configuration without starting a session, run ollama launch opencode --config.
More answers in our FAQ hub.
Newsletter
Practical Linux & Applied AI Newsletter
Get new tested tutorials and benchmark comparisons delivered directly to your inbox. Zero spam.
Join Weekly guides readers getting our weekly digest.
- Practical Linux administration & terminal workflows
- Tested open-source AI setups & benchmarks
- Zero spam - unsubscribe anytime