Local model runs in Codex are for coding prompts that should stay on a workstation or lab machine instead of going to a hosted model. The Codex CLI can hand the prompt to Ollama or LM Studio while still working against the repository path selected for the task.
The local provider must expose an OpenAI-compatible API with a model identifier that Codex can request. Ollama normally listens on http://localhost:11434/v1, LM Studio normally listens on http://localhost:1234/v1, and --local-provider selects which local backend answers the run.
The model must already be loaded or pullable by the provider before the prompt starts. Keep the first run short, point Codex at the repository with -C when the current shell is elsewhere, and keep the provider listener on localhost unless another machine intentionally needs access.
Related: How to route Codex to a local model
Related: How to troubleshoot local models in Codex
$ curl --silent http://localhost:11434/v1/models
{"object":"list","data":[{"id":"gpt-oss:20b","object":"model","created":1765244842,"owned_by":"library"}]}
For LM Studio, replace port 11434 with 1234 and use the returned id value.
Related: How to use Ollama models with Codex
Related: How to use LM Studio models with Codex
$ codex exec --oss --local-provider ollama -m gpt-oss:20b -C ~/repo "Reply with exactly: OK" OpenAI Codex v0.139.0 -------- workdir: /home/user/repo model: gpt-oss:20b provider: ollama -------- codex OK
Use lmstudio with an LM Studio model ID when that server owns the run. The provider line should match the backend selected with --local-provider.
Related: How to fix the Codex trusted-directory error
$ codex exec --oss --local-provider ollama -m gpt-oss:20b -C ~/repo --output-last-message /tmp/codex-local.txt "Reply with exactly: OK" OK
--output-last-message overwrites the destination file when it already exists.
$ cat /tmp/codex-local.txt OK
$ rm /tmp/codex-local.txt