Web Asset House Guides
Local AI

Use Codex CLI With Local Ollama Models: ollama launch codex, the --oss Flag and a Persistent Profile

By Web Asset House Studio ·

Note: Some future links on this site may be affiliate links. We never claim hands-on testing; guides are researched from the public sources listed in each article.

How we wrote this: A summary of Ollama's official Codex CLI integration page and its context length page, plus OpenAI's Codex CLI documentation (all linked below), checked October 29, 2026. Commands are quoted from those docs; we don't claim to have run them on any particular machine. Codex and Ollama both change quickly, so check the docs for your version.

Codex CLI is OpenAI's coding agent for the terminal: per OpenAI's docs, it can inspect files in your project, make edits and run the tools already installed on your machine. Ollama documents how to point it at models you serve locally, so a coding session can run against a model on your own hardware. This is the Codex counterpart to our guide on using Claude Code with Ollama.

Before you start: context length

Ollama's integration page has one requirement up front: use a context window of at least 64k tokens for Codex. Its context length page explains why that matters: Ollama's default context depends on your GPU memory:

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

Ollama says tasks that need a large context, such as agents and coding tools, should be set to at least 64,000 tokens, and that a larger context needs more memory. You can set it with the slider in the Ollama app's settings, or when starting the server:

OLLAMA_CONTEXT_LENGTH=64000 ollama serve

Then check the allocation with ollama ps: the CONTEXT column shows the context in use, and PROCESSOR shows whether the model is fully on the GPU. Ollama recommends avoiding offloading to the CPU for best performance. Our context length guide and the AI model memory calculator help you estimate whether a model fits.

Step 1: install Codex CLI

Ollama's page installs it with npm:

npm install -g @openai/codex

OpenAI's Codex CLI docs also list a standalone installer for macOS and Linux, plus Windows, npm and Homebrew options. Use whichever the official docs list for your system.

Step 2: the quick setup

Ollama's one-command setup:

ollama launch codex

What Ollama says it does:

Two related commands:

ollama launch codex --config    # configure without launching
ollama launch codex --restore   # remove the Ollama launch profile and generated model catalog

Codex needs models that support tool calling, since it works by calling tools to read files and run commands. See our tool calling guide for what that means.

Manual setup with --oss

If you'd rather run Codex directly, Ollama documents the --oss flag:

codex --oss

Pick a specific model with -m:

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

Ollama's page also shows a cloud variant (gpt-oss:120b-cloud). Cloud models run on Ollama's servers, not your machine; if you want everything to stay local, see our guide to Ollama local-only mode.

A persistent profile

For a configuration that sticks, Ollama's docs show a profile file at ~/.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 start Codex with that profile:

codex --profile ollama-launch

The base_url is Ollama's local OpenAI-compatible endpoint on port 11434, and wire_api = "responses" uses the Responses API that Ollama's OpenAI compatibility layer supports. Replace the example path and model with your own.

Web search

Ollama says Codex web-search requests sent through the Ollama profile are executed by Ollama for both local and cloud models, and you need to sign in with ollama signin to use the web-search service (see our Ollama web search guide). To turn web search off for a session:

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

Good habits

OpenAI's Codex docs suggest creating Git checkpoints before and after a task so you can revert changes, and Codex has a /permissions command to choose what it's allowed to do. Both are worth using with any model, local or not. If something fails, our Ollama troubleshooting guide explains where the server logs are.

Sources

← All Local AI guides · All guides