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.
Ari Vale·Links and sources checked ·Updated ·Published ·6 min read
This page has referral links: we earn a commission if you buy, at no cost to you.
Our Runpod referral code: nuninlts (link: https://console.runpod.io/signup?ref=nuninlts). A new account that signs up with Google through it and loads $10 gets a one-time bonus credit, a fixed $5 for European customers and a random $5 to $500 elsewhere (Runpod says most get $5), valid 90 days; we earn 3% of Pod and 5% of Serverless spend for the first 6 months (Runpod's referral docs).
ollama pull gpt-oss:20b # pull every model you want in the picker first
ollama launch codex # configure Codex for Ollama and start a session
# inside Codex: /model # switch between installed Ollama models, no restart
ollama launch codex --restore # undo: remove the Ollama profile and model catalog
Per Ollama's Codex page (read November 14, 2026), the launcher refreshes Codex's model catalog and uses a dedicated profile for that session. Inside Codex, /model switches between your installed, tool-capable Ollama models without a restart, and each model keeps its own context window, vision and thinking settings. Pull extra models before launching so they appear in the picker. Give the model 64k of context first (step 2 below).
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 Codex docs (read November 14, 2026) describe a native Windows sandbox for Codex in PowerShell, with WSL2 as the Linux alternative. Native is the simpler match for a native Windows install of Ollama, since both sit on localhost. If you run Codex inside WSL instead, it needs to reach Ollama on port 11434 on the Windows side. That's the one Windows-specific wrinkle to plan for. Short on disk for models? See how to delete Ollama models.
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." It's useful 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. We've changed it to the 20B model because that's the one most people can actually run; see the next section. The same base_url setting is how you point Codex at any Ollama server, which our guide to running local AI as an API server explains.
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).
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:
"Error: context deadline exceeded" with ollama launch codex
This error means a request to Ollama ran out of time before it finished. Ollama's docs have no page for it. In Ollama's GitHub issues (for example #17484) it comes up in two moments: while a model is still downloading, and while a big model is loading into memory. Try these in order:
Download the model on its own first. Run ollama pull <model> and let it finish before ollama launch codex. If the pull stalls, run the same command again.
On a work or school network with a proxy, set HTTPS_PROXY for the Ollama server, not HTTP_PROXY, and install the proxy's certificate as a system certificate. Ollama's FAQ says both.
For a big model on a slow first load, run ollama run <model> "hi" once, check ollama ps shows it loaded, then launch.
If it still fails, set OLLAMA_DEBUG=1, restart Ollama and read server.log. On Windows it's in %LOCALAPPDATA%\Ollama, per Ollama's troubleshooting page.
Quick answers
How do I fix "context deadline exceeded" in Ollama?
It means a request timed out, usually while a model is downloading or loading. Run ollama pull <model> on its own first, set HTTPS_PROXY (not HTTP_PROXY) if you are behind a proxy, load a big model once with ollama run before ollama launch codex, and check server.log with OLLAMA_DEBUG=1 if it keeps failing.
How do I use Ollama with Codex CLI?
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 Sep 25, 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?
Yes. OpenAI's docs (read Nov 14, 2026) describe a native Windows sandbox for Codex in PowerShell, with WSL2 as the alternative. If Codex runs inside WSL and Ollama runs natively on Windows, make sure Codex can reach Ollama on port 11434.
How do I switch models in Codex with Ollama?
Pull the models first with ollama pull, then start with ollama launch codex and type /model inside Codex. It lists your installed, tool-capable Ollama models and switches without a restart.
How do I undo ollama launch codex?
Run ollama launch codex --restore. It removes the Ollama launch profile and the generated model catalog, so Codex goes back to your normal setup.