`ollama launch codex`, the --oss flag, or a permanent profile, plus the 64k context Codex needs and what gpt-oss 20B vs 120B costs in VRAM at that length.
Codex CLI is OpenAI's terminal coding agent, open source under Apache-2.0. Out of the box it signs in with your ChatGPT account and bills through your OpenAI plan, per OpenAI's Codex CLI docs. With Ollama you can run it against a model on your own hardware instead. OpenAI's open-weight gpt-oss models are the ones Ollama's docs use in every example. Here's the setup, pinned to today's versions. For how it compares with Claude Code and OpenCode, see the three-way comparison.
Codex CLI, pointed at a model running in the same room. · Illustration generated with Higgsfield
Step 1: install Codex CLI
# Ollama's docs
npm install -g @openai/codex
# or OpenAI's standalone installer (macOS / Linux)
curl -fsSL https://chatgpt.com/codex/install.sh | sh
On Windows, OpenAI's docs say Codex CLI runs through WSL (Windows Subsystem for Linux). If Ollama runs natively on Windows and Codex runs inside WSL, the two need to be able to reach each other on port 11434. That's the one Windows-specific wrinkle to plan for.
Step 2: give Ollama 64k of context
Ollama's Codex page is blunt: "Use a context window of at least 64k tokens for Codex." Its context-length page lists the defaults: 4k under 24 GiB of VRAM, 32k at 24–48 GiB, 256k at 48 GiB and up. On most home GPUs you have to raise it yourself:
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
ollama ps # CONTEXT column should read 64000; PROCESSOR should be 100% GPU
Step 3 (fast path): ollama launch codex
ollama launch codex # configure + start a session
ollama launch codex --config # configure without launching
ollama launch codex --restore # remove Ollama's launch profile and model catalog
Per Ollama's docs, ollama launch codex "refreshes the model catalog and uses a dedicated Codex profile for that session." I like that --restore exists. It means trying the local route doesn't permanently change your normal Codex setup.
Step 3 (manual path): --oss or a profile
# one-off, from Ollama's docs
codex --oss
codex --oss -m gpt-oss:20b
# Ollama's cloud-hosted variant (runs on Ollama's servers, not your GPU)
codex --oss -m gpt-oss:120b-cloud
For a setup that survives restarts, Ollama's docs give this profile. Save it as ~/.codex/ollama-launch.config.toml, change the model to one you've pulled, then run codex --profile ollama-launch:
model = "gpt-oss:20b"
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"
wire_api = "responses" is what makes Codex talk to Ollama over OpenAI's Responses API. The docs' own example uses gpt-oss:120b. I've changed it to the 20B model because that's the one most people can actually run; see the next section.
Our engine. Ollama's gpt-oss:20b download is 14 GB, a bit above our Q4_K_M weight estimate, so treat 16GB as tight and set OLLAMA_KV_CACHE_TYPE=q8_0 (≈14.1 GiB).
gpt-oss 120B is a different class of machine: about 71.2 GiB at 64k on our engine, and a 65 GB download in the Ollama library. That's 80GB-class GPUs, multi-GPU rigs or a big unified-memory Mac, not a gaming PC. The full breakdowns are on best GPU for gpt-oss 20B and best GPU for gpt-oss 120B, and cost to run gpt-oss 120B prices renting one by the hour.
Web search goes through Ollama
One detail worth knowing: when Codex runs through the Ollama profile, its web-search requests are executed by Ollama, for local and cloud models alike, and you need ollama signin to use that service. If you want a fully offline session, the docs show how to switch search off:
Run ollama launch codex, or run codex --oss -m <model> for a one-off session. For a permanent setup, create ~/.codex/ollama-launch.config.toml with base_url http://localhost:11434/v1/ and wire_api "responses", then run codex --profile ollama-launch (Ollama docs, accessed 25 Sep 2026).
Does Codex CLI need a ChatGPT subscription with Ollama?
Normally Codex CLI signs in with your ChatGPT account and bills through your OpenAI plan. With the --oss flag or the Ollama profile, it sends requests to your local Ollama server instead. Codex's web search through that profile runs on Ollama's service and needs ollama signin.
What context length does Codex need with Ollama?
Ollama's Codex page says at least 64k tokens. Ollama's defaults are 4k (under 24 GiB VRAM) or 32k (24–48 GiB), so set OLLAMA_CONTEXT_LENGTH=64000 and confirm it with ollama ps.
Can I run gpt-oss 120B with Codex locally?
Only on big hardware. Our engine puts it at about 71.2 GiB at 64k context (Q4_K_M), and Ollama's download is 65 GB. gpt-oss 20B (about 15.6 GiB at 64k) is the realistic local pick. The docs also show a cloud variant, gpt-oss:120b-cloud.
Does Codex CLI work on Windows?
OpenAI's docs say Windows support is through WSL. If Ollama runs natively on Windows, make sure Codex inside WSL can reach Ollama on port 11434.