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.
Optional: web search
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.