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
Steps to use Ollama models with Codex:
- List the model IDs exposed through Ollama's OpenAI-compatible endpoint.
$ 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.
- Post a short Responses request to the same model.
$ 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.
- Run Codex with the Ollama provider and target repository path.
$ 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.
- Save the final Ollama-backed reply when another command or review step needs the result.
$ 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.
- Read the saved reply and confirm it contains only the final assistant message.
$ cat /tmp/codex-ollama.txt OK
- Remove the sample output file if it was only used for the smoke test.
$ rm /tmp/codex-ollama.txt
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.