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.


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 Code | Codex CLI | |
|---|---|---|
| Quick launch | ollama launch claude | ollama launch codex |
| Manual launch | Set ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN=ollama, ANTHROPIC_API_KEY="" | codex --oss -m <model> |
| Recommended context | 64k tokens or higher | At least 64k tokens |
| Undo / switch back | Unset the three env vars and check /status | ollama 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.
# 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", andANTHROPIC_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
/statusto 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.
# 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:120bLocal 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-lmon 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.
Chapter 16 · Models, accounts and quota › Local models → Setting up Ollama and mlx-lm in Mirasim (app and CLI).
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 dshas well. See our DeepSeek Harness install guide for the flags.
Article · Is Claude Code free? What it costs, and how to run it for free or for less → All free and cheaper ways to run Claude Code.
Article · Is Codex free? What the free plans include, and how to run Codex on local models → Is Codex free? Free plan limits, local models and Codex for Open Source.
Article · How to download, install and start DeepSeek Harness (DSH) → Running DeepSeek Harness with Ollama (`ollama launch dsh`).
Article · Using an API key with Claude Code and Codex: setup, custom endpoints, and switching back → Using an API key or custom OpenAI-compatible gateway with Claude Code and Codex.
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

Fixing OpenAI and Codex 403 “unsupported_country_region_territory”
Why OpenAI and Codex return 403 unsupported_country_region_territory, how to fix false positives on VPNs or cloud IPs, and compliant alternatives.

Running Claude Code and Codex on Amazon Bedrock, Vertex AI, and Microsoft Foundry
Connect Claude Code and Codex to Amazon Bedrock, Vertex AI, and Microsoft Foundry: env vars, config.toml, auth, model pinning, and limits.

Using Claude Code with Chrome and Codex Browser: live debugging, Playwright, and previews
How to connect Claude Code to Chrome (extension, console logs, login limits) and use Codex Browser or Playwright, plus live dev-server previews in Mirasim.