Run Codex with LM Studio Locally: Setup, Model Selection and Troubleshooting
To run Codex with LM Studio, start LM Studio’s server on port 1234 and launch Codex with --oss. The fastest way to troubleshoot this setup is to check model discovery, the Responses endpoint and a real repository task in that order.
1. Start LM Studio and check model discovery
Install current versions of LM Studio and Codex CLI. Download a model that your machine can load, preferably one that supports structured tool calls. Start the server from the Developer screen or run these commands in a terminal where lms is available. On Windows PowerShell use curl.exe or call the URL with Invoke-RestMethod.
lms server start --port 1234
curl --fail-with-body http://127.0.0.1:1234/v1/modelsLook for a JSON data array with model IDs. Copy the exact id of the intended model. If the server requires authentication, use its configured bearer token in your diagnostic requests and configure the client accordingly.
2. Launch Codex with the local provider
codex --oss
codex --oss -m ibm/granite-4-microThe first line uses the documented default workflow, which can download a model. The second line selects a specific model, using an example from the official integration guide. Substitute an available model ID when using your own weights. If Codex offers a choice of local providers, select LM Studio. Verify your installed CLI’s options with codex --help before persisting a provider preference.
3. Isolate the Responses endpoint before debugging the agent
Codex uses POST /v1/responses. A successful request to /v1/models proves discovery, and a working chat completion proves text generation. A direct Responses request checks the API path Codex actually needs. Replace the model placeholder with the ID from step one.
curl --fail-with-body http://127.0.0.1:1234/v1/responses \
-H 'Content-Type: application/json' \
-d '{"model":"MODEL_ID_FROM_V1_MODELS","input":"Reply with the word ready."}'Expect a successful HTTP status and a response containing output text. Check LM Studio’s server logs while running Codex to confirm incoming requests use the intended local model.
4. Run a small repository task with a measurable outcome
- Open a disposable sample project with existing tests. Start with an empty working-tree diff.
- Ask Codex to read one test file and summarize the behavior it covers. Confirm the named file exists.
- Ask it to add a single test for an uncovered boundary case. Keep the change inside the test file.
- Review
git diffand run the project’s targeted test command. A plausible patch still needs a test result. - If the model can answer but cannot read a file or produce a usable edit, switch to a model with stronger tool use before increasing permissions.
Fix common Codex and LM Studio errors
| Symptom | What to verify |
|---|---|
| Connection refused | Check the local server and port. In WSL or containers, verify the address from the environment where Codex runs. |
| Model not found | Compare the requested identifier with the exact ID returned by /v1/models. |
| 404 on Responses | Check the endpoint path, app version and active provider. Directly test /v1/responses. |
| Tool calls appear as prose | Try a tool-capable model with its default chat template and test a single simple file read. |
| Early context exhaustion | Keep the first task small. LM Studio recommends above roughly 25K context for Codex workflows when hardware allows. Confirm the loaded context in the server, not just the model’s advertised maximum. |
| Very slow first response | Separate model loading, prompt processing and generation. Repeat one short request with the model warm. |
FAQ
Can I run the model on another computer?
LM Link supports using a model from a linked inference machine while the coding client runs on your laptop. First verify the local API and the remote model independently. See the LM Link integration guide.
Will any GGUF work well?
A model can respond to text and still struggle with an agent’s tools. Pick by available memory, context and how often it produces correct results on your project. Start with the Inkling 2 Mini sizing guide if you are considering that model.
