Cursor is one of the most popular AI code editors, and a lot of people want to run it with a free local model through Ollama or LM Studio instead of paying for cloud tokens.
It is possible, but not in the way most people first try. Typing http://localhost:11434 into Cursor’s settings simply hangs, and the reason surprises almost everyone.
This guide explains exactly how to use a local model in Cursor in November 2026: why localhost does not work, how to set up a secure tunnel with ngrok or Cloudflare step by step, the right Cursor settings, which features work with a local model (and which never will), how to stop the override breaking your other models, and what to do instead if you need real offline privacy.
- Cursor has no official local mode. AI requests go through Cursor’s servers, so they cannot reach
localhoston your PC. - The working method: run Ollama, expose it with a tunnel (ngrok or Cloudflare), then in Cursor Settings > Models turn on Override OpenAI Base URL with your tunnel URL +
/v1and add the model name. - Works: Chat, Agent and inline edit (Ctrl/Cmd + K) when your model is selected. Does not work: Tab autocomplete, which always uses Cursor’s own model.
- Catch: with the override on, Cursor’s own Composer and Grok models stop working until you turn it off. Claude and Gemini use their own key toggles and are not affected.
- Privacy: the model runs on your GPU, but prompts still pass through Cursor’s servers. For fully local coding, use Claude Code or an open editor extension with Ollama instead.
Why localhost Does Not Work in Cursor
When you chat in Cursor, your editor does not talk to the model directly. It sends the request to Cursor’s backend, which builds the final prompt (adding code context, rules and tools) and then calls the model provider.
So when you set the base URL to http://localhost:11434/v1, Cursor’s servers try to reach “localhost”, which means their own machine, not yours. The request never arrives and chat just spins. A home network address like 192.168.1.20 fails for the same reason.
The fix is to give your local model a public HTTPS address that forwards to your PC. That is what a tunnel does.
As of the latest third-party reviews (October 2026), Cursor still has no official local or offline mode, so this override is a community-proven workaround rather than a supported feature, and it could change in a future update.
What You Need
- Cursor, updated to the latest version.
- Ollama (or LM Studio) running on your PC. New to it? Follow our Ollama install guide.
- A GPU with enough VRAM for a coding model with tool calling. 16 GB is a practical minimum for useful agent work, 24 GB+ is better.
- A tunnel tool: ngrok (free account) or Cloudflare’s
cloudflared. - About 15 minutes.
Step 1: Set Up Ollama and a Coding Model
- Install Ollama and check it runs:
ollama --version - Pull a model that supports tool calling (needed for Agent mode). Examples from Ollama’s own coding integration docs:
ollama pull qwen3.5 - Raise the context window. Ollama defaults to 4,096 tokens, which is far too small for Cursor’s large prompts. Start Ollama with a bigger default:
# macOS / Linux OLLAMA_CONTEXT_LENGTH=32768 ollama serve # Windows PowerShell $env:OLLAMA_CONTEXT_LENGTH=32768; ollama serveUse 65536 if your VRAM allows. Ollama’s coding guides recommend 64k+ for agents.
- Test the OpenAI-compatible endpoint locally:
curl http://localhost:11434/v1/modelsNote the exact model ID it returns, for example
qwen3.5:latest.
More model commands and tips are in our Ollama guide and Ollama API guide.
Step 2: Expose Ollama With a Secure Tunnel
Pick one option. Option A is the safest because it adds a password-like token so only Cursor can use your GPU.
Option A: ngrok with a token (recommended)
- Create a free ngrok account and install the ngrok agent.
- Make a random token to act as your API key:
openssl rand -hex 32 - Save this as
policy.yaml, replacingYOUR_TOKEN:on_http_request: - expressions: - "!hasReqHeader('Authorization') || getReqHeader('Authorization')[0] != 'Bearer YOUR_TOKEN'" actions: - type: deny config: status_code: 401 - actions: - type: add-headers config: headers: host: localhostThe first rule blocks anyone without your token. The second rewrites the Host header, which Ollama needs.
- Start the tunnel:
ngrok config add-authtoken <YOUR_NGROK_AUTHTOKEN> ngrok http 11434 --traffic-policy-file policy.yaml - Copy the public URL ngrok prints (an
ngrok-free.devaddress on the free plan). Test it:curl https://your-name.ngrok-free.dev/v1/models -H "Authorization: Bearer YOUR_TOKEN"
Option B: Cloudflare quick tunnel
Ollama’s FAQ gives this command:
cloudflared tunnel --url http://localhost:11434 --http-host-header="localhost:11434"
It prints a random trycloudflare.com URL. Be careful: this quick tunnel has no password, so anyone who finds the URL can use your GPU. Only keep it running while you work, or put Cloudflare Access in front of it.
Option C: plain ngrok (quick test only)
ngrok http 11434 --host-header="localhost:11434"
Same warning as Option B: no authentication.
Step 3: Configure Cursor
- Open Cursor Settings (gear icon, or Ctrl/Cmd + Shift + J) and go to Models.
- Under API Keys, turn on OpenAI API Key and paste your token (
YOUR_TOKENfrom Option A). For Options B and C, any text such asollamaworks. - Turn on Override OpenAI Base URL and enter your tunnel URL with
/v1on the end, for examplehttps://your-name.ngrok-free.dev/v1. - Click Add model (or “+ Add custom model”) and type the model ID exactly as
/v1/modelsreturned it, such asqwen3.5:latest. - While testing, turn off other models so Cursor cannot quietly fall back to a hosted one.
- Click Verify. Then open a chat, choose your model in the model picker and send a short prompt.
- With ngrok, open
http://localhost:4040to watch each request arrive. If nothing shows up, Cursor is not reaching your tunnel.
Which Cursor Features Work With a Local Model
| Feature | Works with local model? | Notes |
|---|---|---|
| Chat / Ask | Yes | When your model is selected |
| Agent | Yes, if the model supports tools | Weak models may loop or ignore tools; needs a big context |
| Inline edit (Ctrl/Cmd + K) | Yes | Select your model in the inline picker |
| Tab autocomplete | No | Always uses Cursor’s built-in model, whatever keys you set |
| Composer / Grok models | Break while override is on | See switching back |
| Claude and Gemini models | Unaffected | They use their own Anthropic or Google key toggles |
| Offline use | No | Cursor’s servers and internet are still required |
Which Local Models to Use
| Your VRAM | What to expect | Advice |
|---|---|---|
| 8 GB | Small models; chat and simple edits only | Skip Agent mode; use Ctrl/Cmd + K on small selections |
| 12-16 GB | Mid-size quantized coding models | Good for chat and inline edits, basic agent tasks with 32k context |
| 24-32 GB | Larger coding models with 64k context | Usable Agent mode on real projects |
| 48 GB+ or 2 GPUs | The biggest open coding models | Closest to cloud quality |
Pick models tagged “tools” on Ollama’s library, since Agent mode depends on tool calling. Context eats VRAM fast, so if you hit out-of-memory errors, lower OLLAMA_CONTEXT_LENGTH or use a smaller quantization. Our CUDA out of memory fix covers more options.
Using LM Studio Instead of Ollama
- In LM Studio, load your model and open the Developer tab.
- Start the server. It listens on port 1234 with an OpenAI-compatible
/v1API. - Increase the model’s context length in the load settings.
- Run the same tunnel commands from Step 2 with port
1234instead of11434. - Configure Cursor exactly as in Step 3, using the model ID LM Studio shows.
Switching Back to Cursor’s Own Models
A Cursor staff reply on the official forum (September 2026) confirms that the OpenAI key and base URL override apply to every model except Claude and Gemini, including Cursor’s Composer and Grok. Those hosted models reject requests carrying your custom key, and running both at once is not currently supported.
- Open Cursor Settings > Models.
- Turn off OpenAI API Key (this also disables the override).
- Re-enable the Cursor models you turned off.
- Turn the key back on when you want your local model again.
If You Need Real Offline Privacy
With this setup your model runs on your GPU, but Cursor still routes every prompt, including your code, through its servers. If your goal is that code never leaves your machine, Cursor is the wrong tool today. Better options:
- Claude Code with Ollama: the Claude Code CLI can talk directly to
localhost:11434with no tunnel. See how to run Claude Code with a local model. - Open WebUI: a private ChatGPT-style interface for your local models. Our Open WebUI setup guide walks through it.
- VS Code extensions that call Ollama directly from your editor, with no third-party server in between.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Chat spins forever, nothing in ngrok inspector | Base URL is localhost or a LAN IP | Use the public tunnel URL plus /v1 |
| 401 Unauthorized | Key in Cursor does not match your token | Paste the same token in Cursor’s OpenAI API Key field |
| 403 Forbidden from Ollama | Host header not rewritten | Keep the add-headers rule, or use --host-header="localhost:11434" |
| “Invalid model” or “model is required” | Model name does not match exactly | Copy the ID from /v1/models, including the tag |
| “This model does not support custom API keys” | Override is on while using Composer or Grok | Turn off the OpenAI key to use those models |
| Agent ignores files or loops | Model lacks tool calling or context is too small | Use a tools-capable model and raise OLLAMA_CONTEXT_LENGTH |
| Replies cut off or forget earlier code | 4,096-token default context | Set 32k-64k context and restart Ollama |
| Very slow replies | Model spilling into system RAM | Use a smaller model or quant; check ollama ps shows 100% GPU |
| Tunnel URL stopped working | Quick tunnels change each restart | Update the base URL in Cursor, or use ngrok’s fixed free domain |
My Take
Using a local model in Cursor works well enough for chat and Ctrl + K edits, and it is a nice way to save money on simple tasks. But you lose Tab with your own model, you have to juggle the override to use Cursor’s models, and your code still passes through Cursor’s servers.
If cost is the reason, it is worth it on a 24 GB+ GPU. If privacy is the reason, use Claude Code or Open WebUI with Ollama instead, where everything genuinely stays on your PC.
FAQ
Can Cursor use a local LLM?
Yes, for Chat, Agent and inline edit, by pointing the Override OpenAI Base URL setting at a tunnel to Ollama or LM Studio. Tab autocomplete always uses Cursor’s own model.
Why can’t Cursor connect to localhost:11434?
Cursor sends requests from its own servers, which cannot reach your PC’s localhost. You need a public HTTPS tunnel.
Does Cursor work offline with Ollama?
No. Cursor’s AI features need its servers and an internet connection, even when the model runs on your GPU.
Is using a local model in Cursor free?
The model itself is free to run. Check Cursor’s pricing page for which plans allow custom API keys and models, as plans changed in October 2026.
Is my code private with a local model in Cursor?
Not fully. Prompts and code still go through Cursor’s servers on the way to your tunnel. Turn on Privacy Mode and read Cursor’s policy, or use a fully local tool.
Which is better for local coding, Cursor or Claude Code?
For fully local work, Claude Code with Ollama, because it connects to localhost directly. For Cursor’s editor features, Cursor with a tunnel.
Can I use LM Studio with Cursor?
Yes. Start LM Studio’s server on port 1234, tunnel it, and use the same Cursor settings with the LM Studio model ID.




