Codex CLI (--oss) with a local model: setup for Ollama or LM Studio
Codex CLI is OpenAI's open-source (Apache-2.0) terminal coding agent. Its --oss mode runs against a local Ollama or LM Studio server, and Ollama can launch it with a ready-made profile; it suits people who want OpenAI's agent loop on a machine that can hold a 64k context.
At a glance
- Type
- cli
- Licence
- Apache-2.0
- Latest release
- 0.163.0 (2026-10-15)
- Status
- Maintained
- Local backends
- ollama, lmstudio, openai-compatible
- Needs native tool calling
- Yes
- MCP support
- Not verified
- Recommended minimum context
- 64,000 tokens
- Start-up prompt
- ~25,450 tokens (single third-party measurement)
- GitHub stars
- Not verified
How to set it up with a local model
Pick your backend. Each command has its own Copy button. Where a step uses an example model, swap in the one you run; the table below lists the ones that fit your machine.
Install it (macOS / Linux):
curl -fsSL https://chatgpt.com/codex/install.sh | shStart Ollama with a 64k context window (or set the context slider in the Ollama app's settings).
OLLAMA_CONTEXT_LENGTH=64000 ollama serveIn a second terminal, pull a tool-capable coding model (replace qwen3-coder:30b with any model you prefer).
ollama pull qwen3-coder:30bQuickest path: let Ollama launch Codex with a dedicated profile; /model inside Codex switches between your installed tool-capable models.
ollama launch codexOr run Codex in OSS mode against Ollama with a specific model.
codex --oss -m qwen3-coder:30bOptionally make Ollama the default local provider for --oss.
~/.codex/config.tomloss_provider = "ollama"
Other ways to install
npm
npm install -g @openai/codexHomebrew
brew install --cask codexCheck that it works
Start a session and ask Codex to list the project files. With Ollama, run `ollama ps` in another terminal and check that CONTEXT shows at least 64000 and PROCESSOR shows the GPU.
ollama psWhich local models fit, by machine
Checked by this site's engine at the context Codex CLI needs, with 32 GB of system RAM for MoE offload. A Mac counts three quarters of unified memory as usable.
| Machine | Model | Quant | Context | Fit | Ollama |
|---|---|---|---|---|---|
| 12 GB GPU | Qwen 3.5 9B | Q4_K_M | 64,000 | Comfortable (8.4 GB of 12 GB) | qwen3.5:9b |
| Qwen 3.6 35B-A3B | Q4_K_M | 64,000 | With CPU offload (MoE) (23.3 GB of 12 GB) | qwen3.6:35b-a3b | |
| 16 GB GPU | Qwen 3.5 9B | Q4_K_M | 64,000 | Comfortable (8.4 GB of 16 GB) | qwen3.5:9b |
| Qwen 3.6 35B-A3B | Q4_K_M | 64,000 | With CPU offload (MoE) (23.3 GB of 16 GB) | qwen3.6:35b-a3b | |
| 24 GB GPU | Qwen3.8 27B | Q4_K_M | 64,000 | Tight (21.9 GB of 24 GB) | qwen3.8:27b |
| Qwen 3.6 27B | Q4_K_M | 64,000 | Tight (21.9 GB of 24 GB) | qwen3.6:27b | |
| Qwen 3.6 35B-A3B | Q4_K_M | 65,536 | Tight (23.3 GB of 24 GB) | qwen3.6:35b-a3b | |
| 32 GB GPU | Qwen3.8 27B | Q4_K_M | 64,000 | Comfortable (21.9 GB of 32 GB) | qwen3.8:27b |
| Qwen 3.6 27B | Q4_K_M | 64,000 | Comfortable (21.9 GB of 32 GB) | qwen3.6:27b | |
| Qwen 3.6 35B-A3B | Q4_K_M | 65,536 | Comfortable (23.3 GB of 32 GB) | qwen3.6:35b-a3b | |
| Qwen3-Coder 30B-A3B (MoE) | Q4_K_M | 65,536 | Comfortable (25.7 GB of 32 GB) | qwen3-coder:30b | |
| Devstral Small 2 24B | Q4_K_M | 64,000 | Comfortable (25.8 GB of 32 GB) | devstral-small-2:24b | |
| Mac, 64 GB | Qwen 3.6 35B-A3B | Q8_0 | 131,072 | Comfortable (40.7 GB of 48 GB) | — |
Your exact machine: filter the matrix or check any model in the analyzer.
Common problems with local models
- Ollama's Codex guide asks for a context window of at least 64k tokens; LM Studio's guide says more than ~25k. Codex sends a large system prompt, so stay at the higher figure.
- If oss_provider is unset and you pass no --local-provider, the interactive CLI prompts you to choose, and `codex exec` exits with an error.
- Custom [model_providers.<id>] entries support only wire_api = "responses", so a server must speak the OpenAI Responses API; the ids ollama and lmstudio are reserved.
- When launched through `ollama launch codex`, the /model picker lists only installed, tool-capable models; pull extra models before launching.
Other coding agents
How they rank for local models: the best agent harness for local LLMs.
- OpenCode
- Qwen Code
- Cline
- Kilo Code
- Aider
- Pi coding agent
- Claude Code
- Crush
- Goose
- OpenHands
- Zed agent
- GitHub Copilot BYOK
- Continue (discontinued)
- Roo Code (discontinued)
- Void (discontinued)