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

Updated Nov 19, 2026 · By Ari Vale

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: https://docs.vast.ai/guides/reference/referral-program?ref_id=623346).

## The short answer

To use Ollama with Codex, run `ollama launch codex`. Ollama refreshes Codex's model catalog and uses a dedicated Codex profile for the session. Without the launcher, add the `--oss` flag: `codex --oss -m gpt-oss:20b`. For a permanent setup, Ollama's docs give an `ollama-launch` profile in a TOML file that points Codex at http://localhost:11434/v1/ using the Responses API. Ollama asks for at least 64k context for Codex, and at 64k our VRAM engine puts gpt-oss 20B at about 15.6 GiB and gpt-oss 120B at about 71.2 GiB. Inside Codex, type `/model` to switch between your installed tool-capable Ollama models. (Docs re-checked Nov 14, 2026.)

- **Fastest:** `ollama launch codex` (undo it with `ollama launch codex --restore`)
- **One-off:** `codex --oss -m gpt-oss:20b`
- **Permanent:** a profile TOML, then `codex --profile ollama-launch`
- **Context:** at least 64k, per Ollama's Codex page

## The fast way: `ollama launch codex`

```shell
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](https://github.com/openai/codex). Out of the box it signs in with your ChatGPT account and bills through your OpenAI plan, per [OpenAI's Codex CLI docs](https://learn.chatgpt.com/docs/codex/cli). 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](https://aliteq.com/run-coding-agents-on-local-models-ollama).

> **Updated November 14, 2026**
>
> Written on Ollama v0.34.4 and Codex CLI rust-v0.157.0 (Sep 25, 2026). Re-checked November 14, 2026 against Ollama v0.40.16 (November 9) and Codex rust-v0.169.0 (November 13). Two changes since September: Ollama's Codex page now documents `/model` switching inside Codex, and OpenAI's Windows docs now describe a native Windows sandbox, so WSL is no longer the only route on Windows. Codex ships almost daily, so check the linked pages if a flag has moved. We quote the docs; we haven't benchmarked Codex on local models ourselves.

![Flat illustration of two people on a sofa looking at a laptop together, with a small glowing box on the side table](https://media.aliteq.com/media/software/how-to-use-ollama-with-codex-cli-2026.jpg)
Codex CLI, pointed at a model running in the same room. · Illustration generated with Higgsfield

## Step 1: install Codex CLI

```shell
# 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](https://aliteq.com/windows-vs-linux-for-local-ai) 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](https://aliteq.com/how-to-manage-local-ai-models-ollama).

## 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](https://docs.ollama.com/context-length) 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:

```shell
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

```shell
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](https://aliteq.com/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

```shell
# 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`:

```toml
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](https://aliteq.com/how-to-run-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 about 15.6 GB of VRAM.

- 12GB card (12 GB): does not fit
- 16GB card (16 GB): fits
- 24GB card (24 GB): fits

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](https://aliteq.com/multi-gpu-local-ai) rigs or a big unified-memory Mac, not a gaming PC. The full breakdowns are on [best GPU for gpt-oss 20B](https://aliteq.com/cost-to-run/gpt-oss-20b#best-gpu) and [best GPU for gpt-oss 120B](https://aliteq.com/cost-to-run/gpt-oss-120b#best-gpu), and [cost to run gpt-oss 120B](https://aliteq.com/cost-to-run/gpt-oss-120b) prices renting one by the hour. An 80GB card such as the [A100 80GB SXM](https://aliteq.com/gpus/a100-80gb-sxm) or the [H100 SXM](https://aliteq.com/gpus/h100-sxm) holds it whole, and [where to rent an H100 cheapest](https://aliteq.com/cheapest-h100-rental) compares the providers.

**Want gpt-oss 120B but your GPU is too small** gpt-oss 120B needs about 71 GiB at 64k context, so a 16GB or 24GB card can't hold it. Rent an 80GB A100 by the hour; this link opens Vast.ai with Ollama and Open WebUI installed, ready to chat. Pull gpt-oss:120b there, then point your Codex profile's base_url at that server, for example through an SSH tunnel. [Rent an 80GB A100 with Ollama ready](https://cloud.vast.ai/?template_id=26e7446a7d6906ee366b620c84e1e422&ref_id=623346) (Referral link: we earn a commission if you buy.) Live A100 SXM4 prices on Vast.ai, from and typical: https://aliteq.com/vast-ai-pricing

## 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:

```shell
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](https://aliteq.com/how-to-use-ollama-with-claude-code)) and OpenCode ([ollama launch opencode](https://aliteq.com/how-to-use-ollama-with-opencode)). For gpt-oss 120B on a smaller card, [llama.cpp's --n-cpu-moe](https://aliteq.com/n-cpu-moe-llama-cpp-what-it-actually-does) keeps its experts in system RAM, and [gpt-oss-120b hardware requirements](https://aliteq.com/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](https://aliteq.com/local-ai-coding-assistant-vs-code) guide covers that route.

Picking a model other than gpt-oss? Our [best local LLM for coding on a single GPU](https://aliteq.com/best-local-llm-for-coding-single-gpu) ranks the options by card size, the [best local coding model for OpenCode](https://aliteq.com/best-local-coding-model-for-opencode) applies just as well to Codex, and [Qwen3 Coder vs GitHub Copilot](https://aliteq.com/qwen3-coder-vs-github-copilot) weighs local against paid. If replies are slow at 64k, see [how to speed up local LLM inference](https://aliteq.com/how-to-speed-up-local-llm-inference); on a 16GB card, the [16GB model guide](https://aliteq.com/best-local-llm-16gb-vram) shows what else fits.

**Need a managed 80GB GPU for a team coding agent** If your team wants a coding model running all day on a big card without picking a marketplace host, Runpod runs pods in Secure Cloud datacenters with one-click templates, and serverless endpoints for apps. Pay by the hour; live rates are on our cloud GPU price page. [Rent an 80GB H100 on Runpod](https://console.runpod.io/signup?ref=nuninlts) (Referral link: we earn a commission if you buy.) Live H100 SXM prices on Runpod, from and typical: https://aliteq.com/runpod-pricing

Compare every provider's hourly rate on our [cloud GPU price page](https://aliteq.com/cloud-gpu).

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](https://aliteq.com/how-to-run-a-local-llm-on-your-pc-beginners-guide) guide. Related guides: [OpenClaw vs Hermes Agent: which to run on a local model](https://aliteq.com/run-openclaw-hermes-local-model-ollama), [Should you use Ollama or LM Studio to run AI on your own PC?](https://aliteq.com/ollama-vs-lm-studio-which-should-you-use), [Open WebUI or LM Studio: which should you use to run local AI?](https://aliteq.com/open-webui-vs-lm-studio).

## "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](https://github.com/ollama/ollama/issues/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

**Q: How do I fix "context deadline exceeded" in Ollama?**

A: 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.

**Q: How do I use Ollama with Codex CLI?**

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

**Q: Does Codex CLI need a ChatGPT subscription with Ollama?**

A: 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`.

**Q: What context length does Codex need with Ollama?**

A: 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`.

**Q: Can I run gpt-oss 120B with Codex locally?**

A: 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.

**Q: Does Codex CLI work on Windows?**

A: 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.

**Q: How do I switch models in Codex with Ollama?**

A: 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.

**Q: How do I undo ollama launch codex?**

A: Run ollama launch codex --restore. It removes the Ollama launch profile and the generated model catalog, so Codex goes back to your normal setup.

## Sources

- [Ollama docs — Codex CLI integration, incl. /model switching and --restore (accessed Sep 25 and Nov 14, 2026)](https://docs.ollama.com/integrations/codex)
- [OpenAI — Codex on Windows, Windows sandbox (MXC, elevated, unelevated) (read Nov 14, 2026)](https://developers.openai.com/codex/windows)
- [OpenAI Codex releases (rust-v0.169.0, Nov 13, 2026; read Nov 14, 2026)](https://github.com/openai/codex/releases)
- [OpenAI — Codex CLI docs (accessed Sep 25, 2026)](https://learn.chatgpt.com/docs/codex/cli)
- [OpenAI Codex on GitHub (Apache-2.0)](https://github.com/openai/codex)
- [Ollama docs — Context length (accessed Sep 25, 2026)](https://docs.ollama.com/context-length)
- [Ollama docs — FAQ (accessed Sep 25, 2026)](https://docs.ollama.com/faq)
- [Ollama library — gpt-oss tags](https://ollama.com/library/gpt-oss/tags)
- [Higgsfield plans and pricing (official page, checked Dec 2, 2026)](https://higgsfield.ai/pricing?fpr=lax-8e2251&fp_sid=how-to-use-ollama-with-codex-cli--md)
- [Illustration generated with Higgsfield](https://higgsfield.ai?fpr=lax-8e2251&fp_sid=how-to-use-ollama-with-codex-cli--md)
- [Ollama docs, Troubleshooting: logs and OLLAMA_DEBUG (official docs, read Nov 19, 2026)](https://docs.ollama.com/troubleshooting)
- [Ollama GitHub issue #17484, Error: context deadline exceeded (read Nov 19, 2026)](https://github.com/ollama/ollama/issues/17484)

---

Canonical: https://aliteq.com/how-to-use-ollama-with-codex-cli

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