Skip to content

How-ToGPU

How to Use OpenAI Codex CLI With Ollama to Code With a Local AI Model

OpenAI's Codex CLI coding agent can run on a model served by Ollama on your own graphics card. We show how to install it, choose a tool-calling model such as gpt-oss:20b, raise Ollama's context length to the 64K it recommends, launch Codex and keep it sandboxed on Windows.

By , Systems & Technical Editor

5 min read

How to Use OpenAI Codex CLI With Ollama to Code With a Local AI Model

The steps below follow Ollama's Codex integration guide, OpenAI's Codex documentation and the Ollama FAQ, all read on 25 November 2026.

Codex CLI is OpenAI's coding agent for the terminal. OpenAI says it runs locally on your computer, and it can work on the files in your project and run commands, within the permissions and approval settings you give it. Normally it talks to OpenAI's cloud models, but it can also use an open model served by Ollama on your own PC. That keeps the model and your prompts on your own machine, at the cost of using a smaller model than the ones in the cloud.

What you need

  • Ollama, installed and up to date. Ollama on Windows and macOS updates itself; click its taskbar or menu bar icon and choose Restart to update when an update is waiting.

  • A model that supports tool calling. An agent works by calling tools, such as reading files and running commands, and Ollama's guide says Codex's model picker lists your installed tool-capable models. OpenAI's gpt-oss models are the obvious starting point: Ollama's guide uses them in its examples, and Ollama describes them as designed for agentic tasks.

  • Enough VRAM. gpt-oss:20b is a 14GB download in Ollama's library, so a 16GB graphics card is a sensible minimum. gpt-oss:120b is 65GB, which is beyond any single consumer graphics card without heavy offloading to system RAM. Our guide to running gpt-oss locally explains the sizes in more detail.

  • A project folder, ideally under Git so you can review and undo the agent's changes.

Step 1: Install Codex CLI

On Windows, OpenAI's README gives this PowerShell command:

powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"

On macOS or Linux, use:

curl -fsSL https://chatgpt.com/codex/install.sh | sh

If you already have Node.js, npm install -g @openai/codex works too, and that's the command Ollama's guide uses.

Step 2: Download a model

Open a terminal and pull the model you want to use, for example:

ollama pull gpt-oss:20b

Pull any other tool-capable models you'd like to try as well. Ollama's guide says models you've pulled before launching will appear in Codex's model picker.

Step 3: Raise Ollama's context length to 64K

This is the step people miss. Ollama's Codex guide says to use a context window of at least 64K tokens. Ollama's own default depends on your VRAM: 4K on cards with less than 24GB, 32K for 24GB to 48GB, and 256K for 48GB or more. So on most gaming graphics cards you'll need to change it. There are two ways:

  • In the Ollama app: open its settings and move the context length slider to 64K.

  • From the command line: start the server with OLLAMA_CONTEXT_LENGTH=64000 ollama serve. On Windows, Ollama's FAQ explains how to add a variable such as OLLAMA_CONTEXT_LENGTH under Edit environment variables for your account, after quitting Ollama from the taskbar; start it again afterwards.

Ollama warns that a larger context needs more memory, so a model that fitted your card at 4K may spill into system RAM at 64K, which slows it down. Our explainer on LLM context length and VRAM shows why.

Step 4: Launch Codex through Ollama

The quickest route is one command:

ollama launch codex

According to Ollama, this refreshes the model catalogue and uses a dedicated Codex profile for that session. Once Codex is running, type /model to switch between your installed tool-capable models without restarting.

Two related commands are useful. ollama launch codex --config sets things up without starting Codex, and ollama launch codex --restore removes the Ollama profile and the generated model catalogue if you want Codex back to its normal settings. If your copy of Ollama doesn't recognise launch, update it first.

Step 4 (alternative): Start Codex manually

You can also point Codex at Ollama yourself with its --oss flag:

codex --oss -m gpt-oss:20b

For a permanent setup, Ollama's guide shows a profile file at ~/.codex/ollama-launch.config.toml that sets the model, names Ollama as the provider and points the base URL at http://localhost:11434/v1/. You then start Codex with codex --profile ollama-launch.

One thing to watch: model names ending in -cloud, such as gpt-oss:120b-cloud, run on Ollama's cloud service rather than your graphics card. Stick to models without that suffix if you want everything to stay local.

Step 5: Work safely on Windows

Codex runs the commands it suggests inside a sandbox that limits which files it can write and whether it can use the network. OpenAI's Windows documentation says Codex can run natively in PowerShell rather than needing WSL. It lists three Windows sandbox types: MXC, which it recommends on compatible devices because it needs no administrator setup; an "elevated" fallback that needs administrator-approved setup; and an "unelevated" fallback with weaker network isolation. For the standalone CLI, OpenAI says you can prefer MXC by adding prefer_mxc = true under [features] in Codex's config.toml.

Even with a sandbox, read each change before you accept it, and commit your work to Git often so you can roll back.

Ollama's guide says that when you use its Codex profile, Codex's web searches are carried out by Ollama, which requires signing in with ollama signin. That sends search requests to an online service, so if you want a fully offline setup, Ollama shows how to turn it off for a session:

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

Other local coding agents

If Codex isn't for you, we have similar guides for Claude Code with Ollama, OpenCode with Ollama and Goose with Ollama. Our round-up of the best local AI coding assistants compares the wider field.

Our verdict

Codex CLI is one of the easiest coding agents to run locally, because Ollama's ollama launch codex command does most of the setup for you. The two things that matter are a tool-calling model that fits your VRAM, such as gpt-oss:20b on a 16GB card, and raising Ollama's context length to at least 64K. Expect a local model to be less capable than OpenAI's cloud models, and review everything it changes.

The bottom line

Codex CLI is one of the easiest coding agents to run locally, because Ollama's ollama launch codex command does most of the setup for you. The two things that matter are a tool-calling model that fits your VRAM, such as gpt-oss:20b on a 16GB card, and raising Ollama's context length to at least 64K. Expect a local model to be less capable than OpenAI's cloud models, and review everything it changes.

Sources

  1. 01Ollama: Codex CLI integration
  2. 02Ollama: Context length
  3. 03Ollama: FAQ
  4. 04Ollama: gpt-oss model library
  5. 05OpenAI: Codex GitHub repository
  6. 06OpenAI: Codex Windows sandbox documentation

About the author

Marcus Thorne

Systems & Technical Editor

Marcus writes Forge PC's step-by-step build, troubleshooting and system optimisation guides. His background spans Windows kernel and power-state diagnostics, UEFI/BIOS configuration, NVMe storage arrays, ATX 3.1 power delivery and running local AI and LLM workloads on consumer graphics cards.

More from Marcus Thorne

Read next

How to Use Nearby Sharing in Windows 11 to Send Files Between PCs

How-To

How to Use Nearby Sharing in Windows 11 to Send Files Between PCs

How to use Nearby sharing in Windows 11: the Bluetooth LE and Wi-Fi requirements, checking Bluetooth LE support in Device Manager, turning it on, the My devices only vs Everyone nearby privacy choice, sending files, photos and links, tips for faster transfers and fixes for common problems.

Marcus Thorne5 min

Best Free Controller Software for PC in 2026

Best Picks

Best Free Controller Software for PC in 2026

The best free controller software for PC in 2026: Steam Input for most people, x360ce for wheels, joysticks and Xbox-only games, AntiMicroX for mapping a controller to keyboard and mouse, and DS4Windows, which still works but was archived in March 2026, with each tool's requirements, limits and maintenance status.

Hannah Vance6 min

Logitech G HUB vs Razer Synapse 4: Which Peripheral Software Is Better?

Versus

Logitech G HUB vs Razer Synapse 4: Which Peripheral Software Is Better?

Logitech G HUB vs Razer Synapse 4 compared: Windows, Arm64 and Mac support, offline use, macros and profiles, onboard memory limits, LIGHTSYNC, Chroma and Windows Dynamic Lighting, Synapse's browser version and claimed speed gains, extras, the end of Logitech Gaming Software downloads and what to do if you mix brands.

Callum Reid7 min