LM Studio-backed Codex runs keep coding prompts on a local model server while Codex still works from the repository that owns the task. The run succeeds only when the LM Studio server is listening locally and the model name passed to Codex matches an identifier exposed by that server.
LM Studio exposes OpenAI-compatible model-list and Responses endpoints on its local server. Codex local-provider mode selects the LM Studio backend and sends the selected model identifier to the Responses endpoint.
Keep the server on the loopback interface unless another machine intentionally needs access, because any client that reaches the port can submit prompts to the loaded model. Use a model and context setting large enough for agent work; LM Studio recommends more than about 25k context for tools such as Codex because file context and tool output can grow quickly.
Related: How to use local models with Codex
Related: How to troubleshoot local models in Codex
$ lms server start --port 1234 --bind 127.0.0.1 Starting server... Waking up LM Studio service... Success! Server is now running on port 1234
127.0.0.1 keeps the API on the local machine. Bind to another address only when remote access is intentional and authentication is enabled.
Related: local-server-enable
$ lms server status The server is running on port 1234.
$ curl http://127.0.0.1:1234/v1/models
{"object":"list","data":[{"id":"openai/gpt-oss-20b","object":"model","owned_by":"lmstudio"}]}
Use the returned id value as the -m argument. If the model does not appear, download or load it in LM Studio first.
Related: model-download
$ curl -X POST http://127.0.0.1:1234/v1/responses \
-H "Content-Type: application/json" \
-d '{"model":"openai/gpt-oss-20b","input":"Reply with exactly: OK"}'
{"id":"resp_123","object":"response","status":"completed","model":"openai/gpt-oss-20b"
##### snipped #####
"text":"OK"}
If /v1/models works but /v1/responses fails, update LM Studio or reload the model before changing Codex flags.
Related: How to troubleshoot local models in Codex
$ codex exec --oss --local-provider lmstudio -m openai/gpt-oss-20b -C ~/repo "Reply with exactly: OK" OpenAI Codex v0.139.0 -------- workdir: /home/user/repo model: openai/gpt-oss-20b provider: lmstudio -------- codex OK
--local-provider lmstudio keeps the run on the LM Studio backend even when another local provider is configured elsewhere.
$ codex exec --oss --local-provider lmstudio -m openai/gpt-oss-20b -C ~/repo --output-last-message /tmp/codex-lmstudio.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-lmstudio.txt OK
$ rm /tmp/codex-lmstudio.txt