A provider default can affect more than one repository. Codex saves local-model routing in user settings, so a named profile can select a workstation model while ordinary sessions retain their usual backend.

You need the Codex CLI, curl, a text editor, and an existing Git repository. Ollama must be running with a downloaded, tool-capable model that fits the machine's memory.

Repository content can reach the selected provider, and a local inference endpoint does not prevent tools from using the network. Sensitive work needs a trusted endpoint and appropriate tool permissions as well as a limited working directory.

Steps to route Codex to a local model:

  1. List the model IDs exposed by Ollama.
    $ curl --fail --silent --show-error http://localhost:11434/v1/models

    The profile's model value must exactly match an ID returned by this endpoint. An empty list means no model is available; a connection error means the server is unreachable.
    Related: How to use Ollama models with Codex

  2. Open ~/.codex/local-ollama.config.toml in your text editor.

    If the file does not exist, create it at that path. A custom CODEX_HOME places this file in that directory instead, beside config.toml. This is a separate profile file; the ordinary user config.toml stays unchanged.

  3. Set the profile's top-level routing values to the following local configuration.
    ~/.codex/local-ollama.config.toml
    model_provider = "ollama"
    model = "qwen3:0.6b"

    If either key already exists at top level, replace its existing line instead of adding a duplicate. If a key is absent, insert its line before the first table header such as [tui], or at the end if there are no tables. Other settings and tables stay in place. These keys do not belong inside a [profiles.local-ollama] table.

    If the inventory lists a different downloaded model, replace qwen3:0.6b with that exact ID. The two lines are the complete contents for a new profile.
    Related: How to set the default model in Codex

  4. Save ~/.codex/local-ollama.config.toml in your editor.

    A new Codex process loads the saved profile when selected with --profile local-ollama. The profile supplies both model and provider; no separate --oss or -m flag is needed. Explicit command-line overrides take priority over the saved values.
    Related: How to override Codex configuration for a single run

  5. Start a fresh Codex run with the saved local profile.
    $ codex exec --profile local-ollama -C ~/repo \
      "What is 17 plus 25? Reply with just the number."

    Here, ~/repo is your existing repository. The startup header should show provider: ollama and model: qwen3:0.6b, or the ID saved in your profile, followed by a completed answer giving 42. CPU inference can take minutes even for a short prompt. A header alone does not show that inference worked; a connection error or an unfinished response needs troubleshooting.
    Related: How to fix the Codex trusted-directory error
    Related: How to troubleshoot local models in Codex

Share this guide