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.
Codex local LLM tier list
11 models| Model | Size | RAM | Why | Run |
|---|---|---|---|---|
| Qwen3.6 35B-A3B | 35B | 32GB | Agent-tuned MoE with the strongest open-weight tool-calling here; 100K+ context, runs on a 24GB Mac. | |
| Qwen3.5 35B-A3B Instruct | 35B | 32GB | Proven agentic MoE with reliable tool calls; disables internal CoT so the agent drives reasoning. |
| Model | Size | RAM | Why | Run |
|---|---|---|---|---|
| Qwen2.5 Coder 14B | 14B | 16GB | Trained for tool use; the most dependable mid-size coding workhorse for a terminal agent CLI. | |
| Gemma 4 31B | 31B | 32GB | Low tool-call error rates in agentic testing; run with thinking off. | |
| Qwen3 30B | 30B | 32GB | Capable agentic MoE; reliable tool calls and 256K context for repo-scale work. |
| Model | Size | RAM | Why | Run |
|---|---|---|---|---|
| LFM2 24B-A2B Instruct | 24B | 24GB | Liquid's tool-dispatch MoE, efficient on-device agent, fits ~14.5GB; lighter coding depth. | |
| Qwen2.5 Coder 7B | 7B | 8GB | Solid 8GB fallback with real tool-use training; weaker on long multi-step chains. | |
| Mistral Small 22B | 22B | 32GB | Decent function calling, fits ~32GB Macs, but long tool sequences can hit format errors. |
| Model | Size | RAM | Why | Run |
|---|---|---|---|---|
| DeepSeek-R1 Distill Qwen 14B | 14B | 16GB | Strong reasoning, but R1 distills drop tool calls into content instead of the tool_calls array. | |
| Phi-4 14B | 14B | 24GB | Lacks proper tool-calling; fine as a chat model, unreliable as an agent. | |
| Qwen3.5 4B Instruct | 4B | 6GB | Agent-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.
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.
Get told when a better model fits your MacBook Air M5 16 GB
Get one email when a new open-weight model is a better fit for this machine.
For: MacBook Air M5 16 GB
You'll also get the weekly ModelFit email. By signing up you agree to our Privacy Policy. Unsubscribe from either email anytime, in one click.
Frequently asked questions
Can Codex CLI run on a local model?
Which local model is best for Codex CLI?
Does Codex CLI need an OpenAI account for the local setup?
Sources
- openai/codex: "a coding agent from OpenAI that runs locally on your computer"
- model-provider-info: built-in open-source providers (ollama :11434, lmstudio :1234) in the repo source
- Codex CLI: configuration reference (model_provider in config.toml)
- Ollama: /v1/responses OpenAI-compatible endpoint support
Other AI coding tools
- Claude CodeAnthropic's terminal coding agent, driven by a local modelCLI agent
- OpenCodeOpen-source terminal coding agent (Ollama / OpenAI-compatible)CLI agent
- OpenClawSelf-hosted agentic assistant with first-class Ollama supportSelf-hosted agent
- AiderTerminal AI pair-programmer with its own edit-format leaderboardTerminal pair-programmer
- ClineAutonomous coding agent for VS Code (formerly Claude Dev)IDE extension
- Roo CodeAutonomous VS Code agent with modes (a Cline fork)IDE extension
- Continue.devOpen-source chat, edit & autocomplete for VS Code / JetBrainsIDE extension
- GooseBlock's open-source autonomous developer agent (MCP-driven)CLI agent
- Open Claude CodeOpen-source Claude Code CLI reimplementation, with an undocumented endpoint override for local modelsCLI agent