Ollama-backed Codex runs keep coding prompts on the local workstation while Codex still works from the repository that owns the task. The run succeeds when Ollama exposes the model through its local OpenAI-compatible API and Codex is explicitly routed to the Ollama provider.
The --oss flag selects the local open-source provider route, and --local-provider ollama chooses Ollama for that run. Codex asks the provider for model details and sends the prompt to POST /v1/responses, so the model value passed with -m must match an identifier visible through /v1/models.
Pull or load the model in Ollama before starting the Codex prompt. Keep the Ollama listener on localhost unless remote access is intentional, and run Codex inside the target Git repository or use -C so the trusted-workspace check does not stop the local-model smoke test.
Related: How to use local models with Codex
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","owned_by":"library"}]}
Use the returned id value as the -m model argument. If the model is missing, pull it with Ollama before running Codex.
$ curl --silent --request POST http://localhost:11434/v1/responses \
--header "Content-Type: application/json" \
--data '{"model":"gpt-oss:20b","input":"Reply with exactly: OK"}'
{"id":"resp_123","object":"response","status":"completed","model":"gpt-oss:20b"
##### snipped #####
"text":"OK"}
Ollama documents /v1/responses support from version 0.13.3. Update Ollama if /v1/models works but this request fails.
$ 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
--local-provider ollama keeps this run on Ollama even if another local provider is configured elsewhere.
$ codex exec --oss --local-provider ollama -m gpt-oss:20b -C ~/repo --output-last-message /tmp/codex-ollama.txt "Reply with exactly: OK" OK
--output-last-message writes only the final assistant message and overwrites the destination file when it already exists.
$ cat /tmp/codex-ollama.txt OK
$ rm /tmp/codex-ollama.txt