aliteq.

Type to search every guide, tool and GPU page.

How to use Ollama with Codex CLI, with ollama launch codex and local gpt-oss

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 ValeLinks and sources checked Updated Published 6 min read
Flat illustration of two people on a sofa looking at a laptop together, with a small glowing box on the side table

This page has referral links: we earn a commission if you buy, at no cost to you.

Our Vast referral code: 623346 (link: https://cloud.vast.ai/?ref_id=623346). New users get no bonus from it; we earn 3% of what referred users spend (Vast's referral program docs).

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).

Share
Share on X

The fast way: `ollama launch codex`

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.

Flat illustration of two people on a sofa looking at a laptop together, with a small glowing box on the side table
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.

gpt-oss 20B or 120B: what fits at 64k

gpt-oss 20B at 64k context needs ≈15.6 GiB
gpt-oss 20B · Q4_K_M · 64k context · fp16 KV needs ≈15.6 GB
12GB card12 GBover 3.5999999999999996 GB
16GB card16 GBfits
24GB card24 GBfits
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. An 80GB card such as the A100 80GB SXM or the H100 SXM holds it whole, and where to rent an H100 cheapest compares the providers.

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:

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

Pros

  • + Open source (Apache-2.0), and `--restore` cleanly undoes the Ollama setup
  • + Ollama's docs are built around OpenAI's own open-weight gpt-oss models
  • + Profile TOML makes the local setup permanent and switchable

Cons

  • − Windows needs either Codex's native sandbox setup or WSL2
  • − Needs 64k context: about 15.6 GiB for gpt-oss 20B on our engine
  • − Web search depends on Ollama's service and a sign-in

Comparing tools? The same one-command setup exists for Claude Code (ollama launch claude) and OpenCode (ollama launch opencode). For gpt-oss 120B on a smaller card, llama.cpp's --n-cpu-moe keeps its experts in system RAM, and gpt-oss-120b hardware requirements lists what holds it whole. If you'd rather work inside VS Code than a terminal, our local AI coding assistant for VS Code guide covers that route.

Picking a model other than gpt-oss? Our best local LLM for coding on a single GPU ranks the options by card size, the best local coding model for OpenCode applies just as well to Codex, and Qwen3 Coder vs GitHub Copilot weighs local against paid. If replies are slow at 64k, see how to speed up local LLM inference; on a 16GB card, the 16GB model guide shows what else fits.

Compare every provider's hourly rate on our cloud GPU price page.

This guide is part of our how to run a local AI model on your own PC in 2026 — a genuinely simple beginner's guide guide. Related guides: OpenClaw vs Hermes Agent: which to run on a local model, Should you use Ollama or LM Studio to run AI on your own PC?, Open WebUI or LM Studio: which should you use to run local AI?.

"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.

Found this useful? Share it

Share
Share on X

Founder & chief editor

Ari Vale

Founder and chief editor of Aliteq (a PC hardware shop from 2019, now a US-based publication). Ari Vale is my pen name: I stay anonymous, the work doesn't. I research the questions people actually ask, check every price and limit against the vendor's own pages, and write down what I'd choose and why. I use the cloud-GPU and AI-video services I write about.

Work out the hardware

GPUs in this article

Specs, the AI models each one runs, and where to buy or rent it.

Email list

Local AI, only the changes that matter

A new model your GPU can actually run, a GPU price move worth acting on, or a fix that saves you an evening. Nothing in between.

Written and sent by hand. One-click unsubscribe in every email. Emails may contain referral links.

Keep reading