Skip to content
Pocket Grove
App guides

Ollama with Claude Code and Codex: Local Model Setup

Published · 9 min read

Original research brief: . Sources reviewed: .

Looking for an app to help with this? Try Ollama Connect.

Quick answer: Ollama has official integrations for both tools. Run ollama launch claude or ollama launch codex, or set them up by hand. For Claude Code, point ANTHROPIC_BASE_URL at http://localhost:11434. For Codex, use codex --oss. Both need a context window of at least 64k tokens. Expect smaller local models to handle fewer tasks well than the hosted models.

Claude Code and Codex are coding agents. They read your repository, run commands and edit files. Normally they talk to Anthropic's or OpenAI's hosted models. Ollama can stand in for those models, so the agent runs on a model on your own machine.

This guide sticks to what each tool's official docs say. Where the sources disagree on what is "supported", it says so. If you have not set up Ollama yet, start with the Ollama local network setup guide.

Who documents what

Three sets of docs cover this. They do not all say the same thing.

Setting or claim Ollama docs Claude Code docs Codex docs
ollama launch claude / ollama launch codex Yes No No
ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN Yes, for Ollama Yes, for LLM gateways n/a
Non-Claude models in Claude Code Shown as working "Doesn't support routing Claude Code to non-Claude models" n/a
codex --oss, oss_provider = "ollama" --oss shown n/a Yes
[model_providers] with base_url Yes (ollama-launch profile) n/a Yes
64k+ context window Yes, for both tools No No

The main thing to note: Anthropic's gateway page says Anthropic "doesn't support routing Claude Code to non-Claude models through any gateway". The Ollama route works because Ollama exposes an endpoint Claude Code can talk to. If something breaks, ask Ollama for help, not Anthropic.

How to use Ollama with Claude Code

The quick way: ollama launch

Ollama's Claude Code page puts the one-command route first. It works the same on macOS, Windows and Linux:

ollama launch claude

It also shows a non-interactive form. Everything after -- goes to Claude Code:

ollama launch claude --model qwen3.5 --yes -- -p "how does this repository work?"

qwen3.5 is one of the example model names on Ollama's page. Pull a model you have room for first (ollama pull <model>).

The manual way: environment variables

If Claude Code is not installed yet, the Ollama page gives the official installers.

macOS or Linux:

curl -fsSL https://claude.ai/install.sh | bash

Windows (PowerShell):

irm https://claude.ai/install.ps1 | iex

Then set three variables and start Claude Code with a local model. On macOS or Linux:

export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3.5

What each one does:

  • ANTHROPIC_BASE_URL tells Claude Code where to send requests. Here, that is your Ollama server.
  • ANTHROPIC_AUTH_TOKEN is sent as a bearer token. A bearer token is just a credential in a request header. Ollama does not check it locally, so ollama is a placeholder.
  • ANTHROPIC_API_KEY="" clears any real Anthropic key so it is not used by mistake.

The Claude Code gateway docs add one useful detail. If you set only ANTHROPIC_BASE_URL with no credential variable, a saved claude.ai login stays the active credential. That is why the Ollama page sets ANTHROPIC_AUTH_TOKEN too.

Ollama also warns that "Claude settings can override shell variables". If Claude Code still talks to the wrong place, check your Claude settings file, then run /status inside Claude Code to see what it is using.

What works and what doesn't

Ollama's page is clear about the limits:

  • "Basic chat and file edits work with compatible models."
  • "Hosted WebSearch and advanced tool controls are not fully supported."

The model also needs to support tools (tool calling, which is how the agent asks to read a file or run a command). A model without tool support cannot drive an agent.

How to use Ollama with Codex

The quick way: ollama launch codex

Install the Codex CLI first. It is an npm package, so you need Node.js on macOS, Windows or Linux:

npm install -g @openai/codex

Then:

ollama launch codex

Ollama says this refreshes the model list and uses a dedicated Codex profile for that session. Two related commands:

ollama launch codex --config    # set up without launching
ollama launch codex --restore   # remove the Ollama profile and model list

Inside Codex, /model switches between installed Ollama models that support tools. Run ollama pull <model> before launching so a model shows up in the picker.

The manual way: --oss

Codex has a built-in "open source" mode for local providers. Ollama's page shows:

codex --oss
codex --oss -m gpt-oss:120b

gpt-oss:120b is the example in Ollama's docs. It is a large model, so pick one that fits your machine.

The Codex docs explain how --oss chooses a provider. You can pick one per run with --local-provider, or set a default in your config. If neither is set, the interactive CLI asks you, and codex exec (the non-interactive mode) exits with an error. To make Ollama the default, add this to ~/.codex/config.toml:

oss_provider = "ollama"

The profile way: a custom provider

Ollama also documents a full profile. Save it as ~/.codex/ollama-launch.config.toml:

model = "gpt-oss:120b"
model_provider = "ollama-launch"
model_catalog_json = "/Users/you/.codex/model.json"

[model_providers.ollama-launch]
name = "Ollama"
base_url = "http://localhost:11434/v1/"
wire_api = "responses"

Then run codex --profile ollama-launch.

Two rules from the Codex docs matter here. First, ollama is a reserved provider ID, so a custom provider needs its own name, like ollama-launch above. Second, Codex ignores model_provider and model_providers in a project's .codex/config.toml. Put them in the config in your home folder instead.

On web search, Ollama says its profile sends web-search requests through Ollama's service, so you need ollama signin. To turn it off for a session:

codex --profile ollama-launch -c 'web_search="disabled"'

Set the context length to 64k or more

This is the setting people most often miss. The context window is how much text the model can hold at once: your prompt, the files the agent reads and its own notes. Coding agents fill it fast.

Both Ollama integration pages ask for at least 64k tokens. Ollama's context-length page says agents and coding tools "should be set to at least 64000 tokens". It also lists the defaults, which depend on your graphics memory (VRAM):

VRAM Default context
Under 24 GiB 4k
24–48 GiB 32k
48 GiB or more 256k

So on many laptops the default is far too small. You can raise it with the slider in the Ollama app's settings, or when starting the server. On macOS or Linux:

OLLAMA_CONTEXT_LENGTH=64000 ollama serve

Then check what was actually allocated:

ollama ps

The CONTEXT column shows the context size. The PROCESSOR column shows whether the model is on the GPU or partly on the CPU. Ollama warns that a larger context needs more memory, and advises avoiding CPU offload for best performance. For more on that trade-off, read Ollama context length and memory.

Be honest about the limits

Local models are usually much smaller than the hosted models these agents were built around. In practice that means:

  • They may follow multi-step instructions less reliably.
  • They may struggle with large repositories, even at 64k context.
  • A model that fits in memory at 4k may not fit at 64k.
  • Some features, such as hosted web search in Claude Code, are not fully supported.

A sensible way to start is a small, clear task in a small repository. If the results are poor, try a model with better tool support, or a bigger one if your machine can hold it. Our list of small LLMs for a home Mac is a good starting point. Ollama also offers cloud models through the same integrations, but that sends your code off your machine, so it is a different privacy choice.

If you are still deciding which agent to use at all, see Codex vs Claude Code: how to work with each and the AI software development lifecycle explained.

Using Ollama on another computer

Both tools take a base URL, so the model does not have to run on the same machine. You could run Ollama on a desktop with a big GPU and point the agent at http://192.168.1.42:11434 (Claude Code) or http://192.168.1.42:11434/v1 (Codex) instead of localhost. The server must be set to listen on your network first. Our setup guide covers OLLAMA_HOST, and Ollama port 11434 covers connection errors.

Ollama's local API has no authentication. Anyone who can reach port 11434 can use it. Keep it on your home network, or use a VPN such as Tailscale or an SSH tunnel when you are away. Never forward port 11434 to the internet. See using Ollama away from home safely.

The same home server can serve your phone as well. When you want to ask a quick question away from your desk, Ollama Connect chats with the Ollama host you already run. It is on iPhone and Android. It connects directly to your host, and your chats stay on your phone.

Setup checklist

  • Ollama is installed and a tool-capable model is pulled.
  • Context length is 64k or more (ollama ps confirms it).
  • Claude Code: ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN=ollama and an empty ANTHROPIC_API_KEY are set, or you used ollama launch claude.
  • Codex: codex --oss, oss_provider = "ollama" or ollama launch codex.
  • Provider settings live in ~/.codex/config.toml, not a project config.
  • Port 11434 is not open to the internet.

Sources

Frequently asked questions

Can I use Ollama with Claude Code?
Yes. Ollama documents an integration: run ollama launch claude, or set ANTHROPIC_BASE_URL to your Ollama server, ANTHROPIC_AUTH_TOKEN to ollama and ANTHROPIC_API_KEY to an empty value. Note that Anthropic says it does not support routing Claude Code to non-Claude models, so support comes from Ollama, not Anthropic.
How do I use Ollama with Codex?
Run ollama launch codex, or start Codex with the --oss flag and pick a model with -m. The Codex docs also let you set oss_provider to ollama in your user config file so Codex uses Ollama by default.
What context length does Ollama need for coding agents?
Both Ollama integration pages ask for at least 64k tokens. Ollama's default can be as low as 4k on machines with less than 24 GiB of VRAM, so raise it in the Ollama app settings or with OLLAMA_CONTEXT_LENGTH.
Will a local model work as well as Claude or GPT in these tools?
Usually not. Local models are typically smaller, and Ollama says only basic chat and file edits work with compatible models in Claude Code, while hosted web search and advanced tool controls are not fully supported.
Can I point Claude Code or Codex at Ollama on another computer?
Both tools take a base URL, so you can use another machine's address instead of localhost. Ollama's API has no authentication, so keep that traffic on your home network or a VPN such as Tailscale and never expose port 11434 to the internet.

The app behind this guide

Ollama Connect

See the features and screenshots, or open the App Store from this guide.

Related guides