OctoLink GEO

Codex Desktop & Ollama: A Guide to Integrating Local AI Models (5 Paths Explored)

Author Editor
Codex Desktop & Ollama: A Guide to Integrating Local AI Models (5 Paths Explored)

Learn how to connect Codex Desktop—OpenAI’s local programming agent—to Ollama’s open-source models without an OpenAI API key. This guide covers key...

Codex Desktop Ollama Local AI Models Programming Agent OpenAI API Integration AI Development Tools

Codex Desktop, OpenAI’s local terminal-based programming agent, has recently expanded its compatibility to work with local Ollama models, eliminating the need for an OpenAI API key. In June 2026, OpenAI Codex team member @thsottiaux shared on X that Codex App, CLI, and SDK can now point to any OpenAI-compatible API, not just GPT series models. Ollama quickly responded by adding shortcuts like `ollama launch codex` and `ollama launch codex-app`, which support models such as GLM-5.2, Kimi-K2.7-Code, and gpt-oss:120b. These shortcuts enable full use of Codex’s agent loop, tool execution, and project memory features without relying on OpenAI’s cloud services.

Before diving into integration, there are three critical preconditions to meet:

  • Ollama Version 0.30+: Profile v2 support requires Ollama 0.30 or higher. Check your version with `ollama --version`; upgrade using commands like `brew upgrade ollama` (for macOS Homebrew). Older versions use deprecated profile formats that Codex 0.134+ no longer accepts.
  • 64k+ Context Window: Codex’s agent loop accumulates tool outputs, code diffs, and snippets rapidly. While Ollama recommends 32k tokens, community testing shows 64k+ is optimal to avoid mid-task truncation and tool call confusion.
  • User-Level Config File: Provider settings must be in the user-level config (~/.codex/config.toml for macOS/Linux/WSL, %USERPROFILE%\.codex\config.toml for Windows). Project-level configs cannot override model provider fields.

Here are the integration paths to connect Codex Desktop with Ollama:

Path A: Fastest (Beginner-Friendly)

Use `ollama launch codex` to let Ollama handle all configuration. Steps:

  • Install Codex CLI: `npm install -g @openai/codex` (if not already installed).
  • Pull models: `ollama pull glm-5.2` (reasoning-focused), `ollama pull kimi-k2.7-code` (agentic programming), or `ollama pull gpt-oss:120b` (OpenAI’s open-source model).
  • Launch Codex CLI: `ollama launch codex` or Codex App: `ollama launch codex-app`.

This command refreshes the model catalog, writes provider settings to config.toml, and generates a profile file. To configure without launching: `ollama launch codex --config`. To restore original settings: `ollama launch codex --restore`.

Path B: Temporary Sessions with --oss Flag

For non-persistent setups, use the `--oss` flag:

  • Default OSS provider: `codex --oss` (uses `oss_provider` from config.toml).
  • Specify model: `codex --oss -m glm-5.2` or `codex --oss -m gpt-oss:120b-cloud` (Ollama Cloud variant).

Set the default OSS provider in config.toml: `oss_provider = "ollama"` (or "lmstudio"). Ensure `ollama serve` is running and the target model is pulled.

Path C: Manual Configuration (Power Users)

For flexibility (e.g., switching between GPT and local models), manually edit config files:

  1. Register Ollama as a provider in ~/.codex/config.toml:
    [model_providers.ollama-launch]
    name = "Ollama"
    base_url = "http://localhost:11434/v1/"
    wire_api = "responses"
    Note: `wire_api = "responses"` is mandatory—Codex uses OpenAI’s Responses API, not Chat Completions, so omitting this causes 404 errors.
  2. Create a profile file (~/.codex/ollama-launch.config.toml) with:
    model = "glm-5.2"
    model_provider = "ollama-launch"

Sources

  • CSDN Blog Post: "Codex Desktop Integrates Local Ollama Models: A Complete Guide to Five Paths" (Original Chinese title: Codex Desktop 接入本地 Ollama 模型:五条路径全解析) - Link

Related reading