Connecting Local LLMs to Coding Assistants: Configuration and Troubleshooting Guide
Many developers want to run open-source models locally for code privacy and cost control, but coding assistants like Claude Code use the Anthropic Messages protocol while local inference frameworks typically expose OpenAI-compatible APIs. This guide explains how to bridge that gap—either by connecting directly through an Anthropic-compatible endpoint or by using LiteLLM as a protocol translation proxy—covering prerequisites, step-by-step configuration, a layered troubleshooting approach, security practices, and model evaluation tips.
Background: Why Local Models Don’t Plug Directly into Coding Assistants
More developers want to run open-source models locally to protect code privacy and gain a controllable, low-cost way to make API calls. However, coding assistants like Claude Code default to cloud-hosted commercial models and use the Anthropic Messages protocol (with requests sent to /v1/messages). Local inference frameworks typically expose different interfaces—most commonly OpenAI-compatible APIs—so you can’t simply point the assistant at a local server.
The solution is protocol translation. The coding assistant sends an Anthropic-formatted request; an intermediate proxy rewrites it into a format the local framework understands, then converts the response back. This way, the client only needs a new base URL and credentials to switch from cloud to local.
Whether you can skip the proxy depends on your inference framework’s version. Newer versions of Ollama provide an Anthropic-compatible API and can be connected directly. Other frameworks or older versions require a proxy. Check each project’s official documentation for specifics.
1. Choose Your Integration Path
| Path | When to Use | Core Configuration |
|---|---|---|
| Path A: Direct connection | The inference framework offers an Anthropic-compatible API (e.g., newer Ollama versions) | Point ANTHROPIC_BASE_URL at the inference framework |
| Path B: Proxy translation | The framework only offers an OpenAI-compatible API, or is an older version (e.g., LM Studio) | Point ANTHROPIC_BASE_URL at the LiteLLM proxy, which connects to the inference framework |
The check is simple: review your framework’s version and documentation to confirm whether it explicitly supports the Anthropic Messages API. When in doubt, choose Path B—it works with most frameworks.
2. Prerequisites
- Node.js 18 or later: required to install Claude Code.
- Claude Code: install via npm with
npm install -g @anthropic-ai/claude-code. Runclaude --versionafterward to confirm the version. - A local inference framework: using Ollama as an example, install it, run
ollama pull qwen3:0.6bto download a model, and note the output ofollama --versionfor troubleshooting against documentation. - LiteLLM (Path B only): requires Python 3.9 or later. Install with
pip install 'litellm[proxy]'.
3. Path A: Direct Connection with Ollama
3.1 Set Environment Variables
export ANTHROPIC_AUTH_TOKEN=ollamaexport ANTHROPIC_BASE_URL=http://localhost:11434
Set ANTHROPIC_BASE_URL to the service root only—do not append /v1. Claude Code automatically appends /v1/messages, and an extra path segment will cause request errors.
To make these persistent, add both lines to ~/.bashrc or ~/.zshrc.
3.2 Verify the Service
Confirm Ollama is running and can list models:
curl http://localhost:11434/api/tags
The returned JSON should include qwen3:0.6b.
3.3 Launch and Test
claude --model qwen3:0.6b
Once in the interactive session, type “who are you”. A text response means the pipeline works.
Note: a 0.6B-parameter model is fine for verifying connectivity, but it’s weak at tasks coding assistants rely on, such as tool calling and multi-step code edits. For real development work, switch to a larger model—see Section 7.
4. Path B: Protocol Translation with LiteLLM
4.1 Write the Proxy Configuration
Create a config.yaml file:
model_list:- model_name: qwen3-locallitellm_params:model: ollama/qwen3:0.6bapi_base: http://localhost:11434general_settings:master_key: sk-local-test-123
Field descriptions:
model_nameis the model name visible to clients;claude --modelmust use exactly this name.litellm_params.modelfollows the formatollama/model-name, indicating Ollama serves as the upstream.api_baseis the upstream framework’s address. If the framework runs on another machine, use its IP instead.master_keyis the proxy’s own access key, which clients use as their token. You can omit it to run without authentication, but setting one is recommended on a LAN.
4.2 Start the Proxy
litellm --config config.yaml --port 4000
If the startup log shows Uvicorn running with no errors, the proxy is ready.
4.3 Test the Proxy Independently
Before launching Claude Code, test the proxy with curl:
curl http://localhost:4000/v1/messages \-H "content-type: application/json" \-H "x-api-key: sk-local-test-123" \-H "anthropic-version: 2023-06-01" \-d '{"model":"qwen3-local","max_tokens":64,"messages":[{"role":"user","content":"hello"}]}'
In the returned JSON, the type field should be message and include a content array. If you get an HTML page or a 404 instead, the path or service address is wrong—proceed to Section 5 for troubleshooting.
4.4 Configure the Client and Launch
export ANTHROPIC_AUTH_TOKEN=sk-local-test-123export ANTHROPIC_BASE_URL=http://localhost:4000claude --model qwen3-local
The token must match the proxy’s master_key, and the name after --model must match model_name. A mismatch in either will cause authentication failures or “model not found” errors.
5. Troubleshooting: A Layered Approach
Troubleshoot in a fixed order across three layers: client environment variables, proxy logs, upstream inference framework logs. Confirm each layer’s output before moving to the next.
5.1 Authentication Failures (401 or 403)
- Step 1: Check that
ANTHROPIC_AUTH_TOKENmatches the proxy’smaster_key. - Step 2: Review the proxy logs. If the request is rejected at the proxy layer, the problem is in the proxy configuration.
- Step 3: If the proxy accepted the request, check whether its calls to the upstream require authentication. Ollama doesn’t need a token by default; frameworks like LM Studio may.
5.2 Request Path Errors (404)
Two common causes:
ANTHROPIC_BASE_URLends with an extra/v1, producing/v1/v1/messages. Remove the extra path segment.- The model name requested by the client doesn’t match the proxy’s
model_name. The proxy returns 404 when it can’t find the model.
How to tell them apart: use the curl command from Section 4.3 to hit the proxy directly. If curl succeeds but Claude Code fails, the issue is in the client environment variables. If curl also fails, the problem is in the proxy configuration.
5.3 Model Response Timeouts
- Check whether the model size matches your hardware. Large models on CPU-only setups generate very slowly—the first token may take minutes.
- If using a proxy, check its timeout settings and increase them if needed.
- Review the inference framework’s logs. If they show insufficient VRAM or memory, switch to a smaller model or a quantized version.
5.4 Connection Refused
A Connection refused error means nothing is listening on the target port. Check in order: whether the inference framework is running, whether the port number is correct, and whether the proxy is still running.
6. Networking and Security
Local services typically listen on 127.0.0.1 by default, allowing access only from the same machine. Change the listen address to 0.0.0.0 only when other machines on the LAN need access, and only on trusted networks or over a VPN.
When exposing a service remotely, follow these practices:
- Use a reverse proxy such as Nginx or Caddy to provide TLS encryption, so tokens and code aren’t transmitted in plaintext.
- Set up a firewall allowlist that permits only specific IPs to reach the port.
- Rotate the proxy’s
master_keyregularly, and never commit keys to a code repository. - Review the proxy’s logging configuration to avoid writing full prompts containing sensitive code or secrets into log files.
- Download and review install scripts before running them, rather than piping untrusted scripts straight into a shell.
7. Model Selection and Evaluation
Model size alone doesn’t determine coding performance. Real-world results depend on task type, hardware, and the model’s tool-calling ability. Rather than relying on intuition, run a simple evaluation on your own codebase:
- Pick 10 real tasks from your project—for example, fixing a known failing test, adding unit tests for a function, or refactoring duplicated code.
- For each candidate model, record whether the task was completed, how much manual correction was needed, and the end-to-end response time.
- Choose based on combined success rate and latency. A common setup is a smaller model for everyday completion and simple Q&A, and a larger model for complex edits.
Base your evaluation on tasks from your own projects, because public benchmark scores don’t necessarily reflect your actual workflow.
8. Two Habits for Better Output Quality
First, use separate sessions for different projects. Mixing context from multiple projects confuses the model about conventions and reduces output quality.
Second, create a CLAUDE.md file in each project’s root directory describing the tech stack, directory structure, coding standards, and test commands. Claude Code reads this file as persistent instructions, which is more reliable than repeating the same context every session.
Also, local inference continuously consumes memory and GPU resources. Use system monitoring tools to watch utilization, and unload unused models before hitting resource limits to avoid unresponsive services.
Conclusion
The key to connecting a local model to a coding assistant is confirming protocol compatibility: connect directly when possible, and use a translation proxy when it isn’t. Follow the order in this guide—verify the inference framework first, then the proxy, then launch the client—and troubleshoot layer by layer (client, proxy, upstream). This approach usually pinpoints the cause quickly.
