Connecting Terminal Coding Tools to Local Models Through a Compatibility Proxy: A Complete Configuration Guide

    This guide explains how to connect a Claude Code–style terminal coding tool to a locally hosted model through LiteLLM and Ollama. It covers the architecture, installation, proxy configuration, request validation, environment variables, model and hardware selection, troubleshooting, and security practices.

    Connecting Terminal Coding Tools to Local Models Through a Compatibility Proxy: A Complete Configuration Guide

    Many developers want to use AI coding tools in the terminal without sending internal source code to a cloud service. A common approach is to run an open-source coding model locally and connect the coding tool to it.

    Although this may appear to require changing only a single URL, protocol mismatches often make the setup fail. This guide explains the entire workflow in a reproducible order, with commands and expected results for each step.

    1. Requirements and Limitations

    This guide uses a Claude Code–style terminal coding tool as an example. These tools communicate with models through the Anthropic Messages API, typically using the /v1/messages endpoint.

    The following prerequisites are assumed:

    • A machine capable of running a quantized model with 7B to 14B parameters. A dedicated GPU with at least 16 GB of VRAM, or a device with sufficient unified memory, is recommended.
    • Python 3.9 or later and a working terminal environment, such as macOS, Linux, or WSL.
    • The coding tool has been obtained through its official distribution channel and can be launched from the command line.

    This guide does not cover every detail of native Windows environments. Windows users can follow the same steps in WSL.

    Keep in mind that local models are usually less capable than leading cloud models, especially when handling complex reasoning across multiple files. A practical approach is to use a local model for routine coding, code explanations, and small refactors, then switch to a cloud model for more difficult tasks.

    2. Architecture: Why a Compatibility Proxy Is Required

    The coding tool sends requests in Anthropic format, while local inference frameworks such as Ollama expose their own APIs by default. Ollama’s base URL, http://localhost:11434, does not provide an Anthropic-compatible /v1/messages endpoint. If you point ANTHROPIC_BASE_URL directly to Ollama, requests will fail.

    The solution is to place a compatibility proxy between the two components:

    1. The coding tool sends requests to the proxy, which listens on 127.0.0.1:4000.
    2. The proxy converts Anthropic-formatted messages, system prompts, and tool definitions into a format understood by the backend model.
    3. The proxy converts the model’s output, including streamed text and tool-call instructions, back into Anthropic format.
    4. Ollama performs the actual inference and listens on 127.0.0.1:11434.

    This guide uses LiteLLM as the proxy. LiteLLM is an open-source Python tool that supports Anthropic and OpenAI API formats and can map multiple backend models to a unified model name. Its proxy also supports master-key authentication, which is useful for shared deployments.

    3. Step-by-Step Configuration

    Step 1: Install and Verify the Local Model

    After installing Ollama, pull a coding model. This example uses qwen2.5-coder:7b:

    1. ollama pull qwen2.5-coder:7b
    2. ollama list
    3. curl http://localhost:11434/api/version

    The output of ollama list should include qwen2.5-coder:7b. The curl command should return JSON containing a version number.

    If the request fails with a connection error, run ollama serve or verify that the Ollama desktop application is running.

    Step 2: Install LiteLLM and Create the Configuration

    Create a dedicated virtual environment for the proxy to avoid dependency conflicts with other projects:

    1. python3 -m venv ~/llm-proxy
    2. source ~/llm-proxy/bin/activate
    3. pip install 'litellm[proxy]'

    Create ~/llm-proxy/config.yaml with the following content. local-coder is the model name exposed by the proxy and will be used by the coding tool:

    1. model_list:
    2. - model_name: local-coder
    3. litellm_params:
    4. model: ollama/qwen2.5-coder:7b
    5. api_base: http://localhost:11434
    6. general_settings:
    7. master_key: os.environ/LITELLM_MASTER_KEY

    The master_key is read from an environment variable rather than being stored in the configuration file. Generate a random key and export it:

    1. export LITELLM_MASTER_KEY="sk-local-$(openssl rand -hex 16)"

    This variable is valid only for the current terminal session. To keep it available, store it in ~/.zshrc or a password manager. Do not commit it to a source repository.

    Step 3: Start the Proxy and Verify the Request Path

    Start the service inside the proxy’s virtual environment, binding it only to the local loopback address:

    1. litellm --config ~/llm-proxy/config.yaml --host 127.0.0.1 --port 4000

    Open another terminal and first check the model list. The expected output should include local-coder:

    1. curl http://127.0.0.1:4000/v1/models \
    2. -H "Authorization: Bearer $LITELLM_MASTER_KEY"

    Next, send a real request in Anthropic format. The expected response is JSON whose content array contains an item with "type": "text":

    1. curl http://127.0.0.1:4000/v1/messages \
    2. -H "Content-Type: application/json" \
    3. -H "x-api-key: $LITELLM_MASTER_KEY" \
    4. -H "anthropic-version: 2023-06-01" \
    5. -d '{"model":"local-coder","max_tokens":128,"messages":[{"role":"user","content":"Explain recursion in one sentence."}]}'

    Both requests must succeed before you launch the coding tool. Together, they confirm that the proxy and backend are connected. If either request fails, troubleshoot the setup before continuing.

    Step 4: Point the Coding Tool to the Proxy

    The coding tool uses environment variables to determine the backend URL and credentials. The following variables apply only to the current shell session:

    1. export ANTHROPIC_BASE_URL=http://127.0.0.1:4000
    2. export ANTHROPIC_AUTH_TOKEN="$LITELLM_MASTER_KEY"
    3. export ANTHROPIC_MODEL=local-coder

    Move into a project directory and start the tool. You can also specify the model directly as an argument:

    1. cd ~/your-project
    2. claude --model local-coder

    After entering a session, ask the tool to explain a file in the current directory. If it responds normally, the complete path—from the coding tool to the proxy and then to the local model—is working.

    If you are using a newer version of the tool, the environment variable names may have changed. Check claude --help or the official documentation for the version you have installed.

    To switch back to a cloud model, start a new terminal session or clear the local configuration:

    1. unset ANTHROPIC_BASE_URL ANTHROPIC_AUTH_TOKEN ANTHROPIC_MODEL

    4. Model Selection and Hardware Planning

    Model selection mainly depends on three factors.

    First, prioritize coding ability. Models specifically trained or fine-tuned for code are generally more consistent than general-purpose chat models when completing long code blocks and following project-specific styles.

    Second, choose a sufficient context length. Coding tools place source files, conversation history, and tool results into the same context window. A context of several tens of thousands of tokens can be consumed quickly.

    When the context is too small, common symptoms include forgetting earlier instructions, producing contradictory edits, and truncating long files. Ollama uses a relatively small default context window. In newer versions, you can increase it with the OLLAMA_CONTEXT_LENGTH environment variable. Restart ollama serve after changing the setting.

    A larger context consumes more VRAM or system memory, so it must be balanced against the available hardware.

    Third, match the parameter count to your hardware. The following figures are approximate file sizes for Ollama’s default Q4 quantized models and are provided for reference only. Actual memory usage also depends on context length, the inference framework version, and the system’s available VRAM.

    Model size Approximate file size (Q4) Typical environment Suitable tasks
    7B About 5 GB At least 8 GB VRAM or 16 GB RAM Single-file completion, code explanations, simple edits
    14B About 9 GB At least 16 GB VRAM or 32 GB RAM Most everyday coding tasks
    32B About 20 GB At least 24 GB VRAM or 48 GB unified memory More complex refactoring and analysis

    As a rule of thumb, keep the model file size below approximately 80% of the available VRAM to leave room for the context cache. Model versions change quickly, so check the model’s documentation before making a final selection.

    5. Common Problems and Troubleshooting

    Problem 1: Connection refused. Confirm that the proxy process is still running and that it is using port 4000. Check ANTHROPIC_BASE_URL for extra spaces or a trailing slash, and make sure the protocol is http rather than https. The local proxy does not use encryption.

    Problem 2: HTTP 401 or authentication failure. The credential sent by the coding tool must exactly match LITELLM_MASTER_KEY. Two terminal windows may have different values. Make sure the proxy and coding tool are launched from environments that contain the same key.

    Problem 3: Model not found. The value passed to --model or assigned to ANTHROPIC_MODEL must match the model_name in config.yaml. In this example, it is local-coder.

    The Ollama model tag must also exactly match the value shown by ollama list, including the version tag after the colon.

    Problem 4: The proxy cannot connect to the backend. Run:

    1. curl http://localhost:11434/api/version

    If this request fails, Ollama is not running or the api_base port is incorrect.

    Problem 5: Tool calls fail or the model enters a loop. Coding tools depend on structured tool calls. Frequent output-parsing errors indicate that the current model may have insufficient function-calling capability. Try a model that explicitly supports tool calls.

    You can inspect the model information with:

    1. ollama show model-name

    Newer versions may display capability labels.

    Problem 6: Responses are extremely slow. Run:

    1. ollama ps

    Check the PROCESSOR column. If part of the model is running on the CPU, the model has not been loaded entirely into VRAM, which can significantly reduce speed. Try a smaller model or reduce the context length.

    6. Security and Cost Considerations

    The primary benefit of the local setup is that source code remains on your machine, but this depends on configuring the services correctly. Review the following checklist after each deployment.

    Check Requirement
    Proxy bind address Use only 127.0.0.1; do not use 0.0.0.0
    Model service port Keep port 11434 private and accessible only from the local machine
    Master key Use a long, randomly generated string; do not use the example value or commit it to a repository
    Key storage Store it in an environment variable or password manager, not as plaintext in config.yaml
    Request logs Disable verbose logging after debugging and regularly remove log files that contain source code
    Team sharing Place the proxy behind a TLS-enabled reverse proxy, issue separate keys to users, and restrict the allowed network ranges
    Permissions Run the proxy and model service as a regular user rather than an administrator

    The main costs of a local model are hardware and electricity. For frequent use, a local setup can be more economical than a cloud service billed by token usage. However, if your work often requires stronger reasoning capabilities, a hybrid approach is usually more practical: use the local model for routine tasks and switch to a cloud model for complex work.

    Conclusion

    Connecting a terminal coding tool to a local model comes down to three essentials:

    1. Use a compatibility proxy to translate between API protocols.
    2. Use environment variables to point the coding tool to the proxy.
    3. Validate each section of the request path with independent commands.

    Because every stage can be tested separately, problems can be isolated quickly. Once the setup is complete, start with simple tasks before using it on a real project. Coding models are improving rapidly, and the local development experience will continue to evolve with them.