← Blog

How-to5 min read

Running Claude Code and Codex with Ollama: local models, 64k context, and setup

How to connect Claude Code and Codex to local models with Ollama (`ollama launch`, `--oss`, 64k context, manual env vars), and switch per session in Mirasim.

Mirasim's agent and model picker, where Claude Code or Codex sessions can switch to a local Ollama or mlx-lm modelMirasim's agent and model picker, where Claude Code or Codex sessions can switch to a local Ollama or mlx-lm model

The short answer

Both Claude Code and Codex work with Ollama in one command: ollama launch claude connects Claude Code through Ollama's Anthropic-compatible API, and ollama launch codex launches Codex with an Ollama profile where /model switches between your installed models. Pick a model that supports tool calling and set a context length of at least 64k tokens for real repositories.

Claude CodeCodex CLI
Quick launchollama launch claudeollama launch codex
Manual launchSet ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN=ollama, ANTHROPIC_API_KEY=""codex --oss -m <model>
Recommended context64k tokens or higherAt least 64k tokens
Undo / switch backUnset the three env vars and check /statusollama launch codex --restore

Claude Code with Ollama

Start with ollama launch claude to pick a local or Ollama cloud model interactively. For scripts or CI, pass --model and --yes, with Claude Code arguments after --. If you prefer to wire the environment yourself, point Claude Code at http://localhost:11434.

Quick launch, scripted run, and manual env vars for Claude Code
# Interactive launch
ollama launch claude

# Non-interactive run (pulls model if needed; args after -- go to Claude Code)
ollama launch claude --model gemma4:cloud --yes -- -p "how does this repository work?"

# Manual local setup
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3.5
  • Use Ollama's cloud without installing Ollama locally: set ANTHROPIC_BASE_URL=https://ollama.com, ANTHROPIC_AUTH_TOKEN="$OLLAMA_API_KEY", and ANTHROPIC_API_KEY="".
  • Settings can override shell vars: if Claude Code still talks to Anthropic, check your Claude settings file for an existing base URL or credential, then run /status to verify the active endpoint.
  • What works and what doesn't: chat, file edits, command execution, subagents, vision and thinking work with compatible models; Anthropic-hosted features such as Remote Control require connecting to api.anthropic.com.

Codex CLI with Ollama

Install the Codex CLI (npm install -g @openai/codex) and run ollama launch codex. Ollama refreshes its local model catalog and starts Codex with a dedicated profile; pull extra tool-capable models with ollama pull <model> beforehand, then switch anytime inside Codex with /model.

Quick launch, manual --oss flag, and restoring Codex defaults
# Launch Codex with Ollama
ollama launch codex

# Configure only (without launching), or remove the Ollama profile later
ollama launch codex --config
ollama launch codex --restore

# Manual launch using Codex's built-in --oss flag
codex --oss -m gpt-oss:120b

Local models per session in Mirasim (Ollama and mlx-lm)

Managing shell variables for Claude Code and --restore profiles for Codex gets tedious when you want a local model for quick edits and Claude or GPT for harder tasks. Mirasim handles local inference natively alongside your cloud accounts.

  • Ollama plus mlx-lm on macOS: Mirasim detects what is installed, can start the backend for you, and pulls or deletes Ollama models with progress — or connect any other OpenAI-compatible local server as a custom provider.
  • Per-session switching, zero credit cost: pick “API key” under “Paying with” in the composer and choose your local model for one pane, while the pane beside it runs on Claude, ChatGPT, or Mirasim credit. Local-model sessions use zero Mirasim credit, and Mirasim bridges protocols so Claude Code works with OpenAI-compatible local servers too.

Questions

Do I need a Claude or ChatGPT subscription to use Ollama?
No. Both Claude Code and Codex CLI are free to install and can run against a local Ollama server without a paid plan.
Why do some Ollama models fail to edit files?
Coding agents rely on tool calling to read files and run commands. Pick a model tagged for tools in Ollama's library and give it a 64k+ context window.
Can I use DeepSeek Harness with Ollama too?
Yes — Ollama provides ollama launch dsh as well. See our DeepSeek Harness install guide for the flags.

Sources

Checked on November 29, 2026 against Ollama's official integration guides (docs.ollama.com/integrations/claude-code and docs.ollama.com/integrations/codex). Check those pages for newly supported models and flags.

Keep reading