Local inference puts the model server beside the files used by a coding assistant. Codex can use a local model to read a repository file and answer a question about the project.
Before first use, the local provider needs a downloaded model with tool support and a running API server. The client needs the Codex CLI, curl, and Bash or zsh, with an existing Git project containing a README.
File access and command execution follow the active Codex approval and sandbox policies. A read-only README summary exercises both the model connection and a repository tool without requiring a code change.
Steps to use local models with Codex:
- Choose the running local provider for this shell session.
provider=ollama api=http://localhost:11434/v1
For LM Studio, the corresponding values are:
provider=lmstudio api=http://localhost:1234/v1
The provider API should listen on loopback unless remote access is intentionally secured. A reachable unauthenticated listener lets other clients submit work to the model.
- List the model IDs exposed by the selected server.
$ curl --fail --silent --show-error "$api/models" {"object":"list","data":[{"id":"qwen3:4b-instruct-2507-q4_K_M","object":"model","created":1793572840,"owned_by":"library"}]}
A connection error means the selected server is unavailable. An empty model list needs resolving in the provider before a task can start.
- Select a tool-capable model ID from the returned inventory.
$ model=qwen3:4b-instruct-2507-q4_K_M
The value must match a returned id exactly. Each provider has its own inventory; an Ollama tag does not identify an LM Studio model. A listed model is available, but reading a file through Codex also requires tool support. The server needs enough context capacity for Codex's instructions and the project input.
- Run a read-only README task in your existing project.
The prompt and file content used by the task go to the selected model server. Codex tools follow the active permissions, so the project should contain only data suitable for that server.
$ codex exec --oss --local-provider "$provider" \ -c model_provider="$provider" -m "$model" -C ~/repo \ "Read README.md using a shell command and summarize what this project does. Do not change any files."
The -C value is your existing project's directory; ~/repo is the example path. The prompt names that project's existing README.md. On Codex CLI 0.166.0, the explicit model_provider override also keeps the turn's provider aligned with the local selection. Without it, the run can report that the chat uses Ollama while the current provider is OpenAI. These options apply only to this run. Loading a model and processing the Codex instructions can take minutes.
Related: How to fix the Codex trusted-directory error - Confirm that Codex shows a README-reading tool action and a summary matching the file.
exec /bin/bash -lc 'cat README.md' in /home/reader/repo succeeded in 0ms: # Meadow Notes Meadow Notes is a small command-line app for organizing plain-text notes by topic. It lists the notes in a folder and searches their titles without a database. ##### snipped ##### codex **Project Summary** Meadow Notes is a lightweight command-line tool that organizes plain-text notes by topic. It allows users to: ##### snipped #####
The run header should identify your selected provider and model. A model name alone does not prove tool use; the shell action, README contents, and resulting project summary show that the repository task completed. A reply without a file-reading action leaves that unconfirmed.
Related: How to troubleshoot local models in Codex