Best Local LLMs for Codex CLI

OpenAI's coding agent, driven by a local model via its built-in Ollama provider

Codex CLI is OpenAI's agentic terminal coder. Out of the box it talks to the GPT-5 family, but the CLI ships with Ollama and LM Studio as first-class open-source providers (built into the openai/codex repo), so you can point it at a local model through config.toml and get the same terminal agent loop without an OpenAI account. Codex drives the modern Responses API, which Ollama exposes at /v1/responses, making local tool-calling work end to end. This page ranks the open-weight models that hold up in Codex's tool-call-heavy loop.

Best pick
Qwen3.6 35B-A3BAgent-tuned MoE with the strongest open-weight tool-calling here; 100K+ context, runs on a 24GB Mac.
What Codex needs
Reliable structured tool-calling over long sessions, plus the context window set high enough to hold the growing agent loop. A model that mangles tool_calls breaks Codex no matter how good its code is.
Table 1Tier list

Codex local LLM tier list

11 models
SS: Best in class2
ModelSizeRAMWhyRun
Qwen3.6 35B-A3B35B32GBAgent-tuned MoE with the strongest open-weight tool-calling here; 100K+ context, runs on a 24GB Mac.
Qwen3.5 35B-A3B Instruct35B32GBProven agentic MoE with reliable tool calls; disables internal CoT so the agent drives reasoning.
AA: Strong, reliable3
ModelSizeRAMWhyRun
Qwen2.5 Coder 14B14B16GBTrained for tool use; the most dependable mid-size coding workhorse for a terminal agent CLI.
Gemma 4 31B31B32GBLow tool-call error rates in agentic testing; run with thinking off.
Qwen3 30B30B32GBCapable agentic MoE; reliable tool calls and 256K context for repo-scale work.
BB: Usable with caveats3
ModelSizeRAMWhyRun
LFM2 24B-A2B Instruct24B24GBLiquid's tool-dispatch MoE, efficient on-device agent, fits ~14.5GB; lighter coding depth.
Qwen2.5 Coder 7B7B8GBSolid 8GB fallback with real tool-use training; weaker on long multi-step chains.
Mistral Small 22B22B32GBDecent function calling, fits ~32GB Macs, but long tool sequences can hit format errors.
CC: Works, but not recommended3
ModelSizeRAMWhyRun
DeepSeek-R1 Distill Qwen 14B14B16GBStrong reasoning, but R1 distills drop tool calls into content instead of the tool_calls array.
Phi-4 14B14B24GBLacks proper tool-calling; fine as a chat model, unreliable as an agent.
Qwen3.5 4B Instruct4B6GBAgent-tuned but too small to stay coherent across the long agentic loop.

Tiers weigh tool-calling reliability, context window, and coding quality for Codex specifically. A model can rank higher for one tool than another. RAM figures are for Q4 quantization. Sources are listed below.

Setup

Local setup notes

Install the Codex CLI and Ollama (both run locally; the CLI needs no OpenAI account for this path). Then set the provider and model in ~/.codex/config.toml: select the built-in `ollama` provider (it targets localhost:11434) and pick your model, e.g. `model = "qwen3.6:35b-a3b"`. Raise the context window well above Ollama's 4K default (16K minimum, 32K+ for the agentic loop) so the model can hold Codex's tool definitions.

FAQ

Frequently asked questions

Can Codex CLI run on a local model?
Yes. The Codex CLI (openai/codex) ships Ollama and LM Studio as built-in open-source model providers, selected in ~/.codex/config.toml, and it speaks the Responses API that Ollama exposes at /v1/responses. No OpenAI account is required for the local path.
Which local model is best for Codex CLI?
Qwen3.6 35B-A3B leads: agent-tuned tool-calling with 100K+ context, running on a 24GB Mac. Qwen3.5 35B-A3B is the proven agentic MoE alternative. On 16GB, Qwen2.5 Coder 14B is the dependable workhorse; on 8GB, the 7B.
Does Codex CLI need an OpenAI account for the local setup?
No. The local path uses the built-in ollama provider pointed at localhost:11434, so no API key and no billing. The chat/completions API was deprecated by OpenAI in early 2026, which is why the Responses API, which Ollama also exposes, is the supported path for local tool-calling.
Sources

Sources

Directory

Other AI coding tools

Related

Explore more