Configure an AI Coding Assistant in VSCode with a Private LLM: A Practical Guide

    This guide walks through connecting a command-line AI coding assistant to a private or self-hosted large language model and using it inside VSCode. It covers installation, environment checks, handling region-based startup restrictions, obtaining a compatible model API key, mapping model settings through environment variables, switching configurations, and validating the setup with test cases. A troubleshooting checklist and best practices for key management and team usage are also included.

    1. Background and Overall Approach

    As large language models spread quickly across software development, command-line AI coding assistants have become a standard part of many developers’ daily work. At their core, these tools are an interactive shell: they handle terminal interaction, context collection, file reading and writing, tool-call orchestration, and multi-turn conversation management. The actual language understanding, code generation, and reasoning come from the LLM service connected behind the shell.

    This layered “shell + model” design brings two direct benefits:

    1. Interaction is decoupled from model capability. The same shell can connect to models from different vendors, with different parameter sizes and context lengths, without changing how developers work.
    2. Data boundaries stay controllable. For organizations with sensitive code assets, model requests can be pointed at a privately deployed inference service, keeping source code from being sent to external public services.

    The core goal of this approach can be summarized in three steps:

    • Install and initialize the command-line coding tool locally.
    • Obtain a model API key that is compatible with mainstream tool-calling protocols.
    • Use configuration management to switch the tool’s backend model from the default service to a self-hosted or designated service, then verify it in a code editor.

    Different tools vary in the details. This guide focuses on a transferable, general methodology: first understand the configuration file hierarchy and precedence, then change parameters, and finally verify the connection with a minimal test case.


    2. Prerequisites and Key Concepts

    2.1 Runtime Environment

    • Operating system: Windows 10/11, macOS, and mainstream Linux distributions all work. Windows is used as the example here; commands differ slightly on other platforms.
    • Package manager: On Windows, the official package management tool is recommended for silent installation; on macOS, Homebrew can be used; on Linux, the distribution’s package manager or the official install script.
    • Editor: A modern code editor with an integrated terminal and extension system, so coding, running, and conversation can happen in one window.
    • Network and permissions: Outbound internet access, or access to an enterprise proxy; write permission to the local user directory (configuration files usually live in a hidden directory under the home directory).

    2.2 Three Easily Confused Concepts

    Concept Meaning Relation to This Guide
    Shell tool The client program that provides terminal interaction and tool-calling ability The object installed and configured here
    Model service The backend API that provides inference The target to be replaced
    Interface protocol The request/response format agreed between client and model service The key factor in whether a direct swap is possible

    Key point: A seamless swap through configuration alone is only possible when the model service’s interface protocol is compatible with the protocol family the shell tool supports. The mainstream compatibility directions today include the Anthropic-style message protocol and the OpenAI-style Chat Completions protocol; most newer model services offer one or more compatible endpoints. This guide uses a service compatible with the Anthropic message protocol as the example.


    3. Step 1: Install the Command-Line Coding Tool

    3.1 Official Installation

    Visit the tool’s official site and run the install command from its documentation. Common forms include:

    1. # macOS / Linux: install via the official script
    2. curl -fsSL <official-install-script-url> | bash
    3. # macOS: install via package manager
    4. brew install <tool-package-name>
    5. # Windows: silent install via package manager
    6. winget install <tool-package-name>

    3.2 Common Installation Obstacles

    Because distribution channels, mirror sources, and certificate chains differ, the official script may run into the following situations:

    • The install script download times out or is interrupted.
    • Binary resource downloads fail.
    • Installation succeeds, but the first run throws a network-related error.

    Recommended approach: Prefer the operating system’s own package manager (such as winget on Windows), which offers:

    1. Local mirrors or system sources, for better network stability.
    2. Automatic registration of the install path and the PATH environment variable.
    3. Unified uninstall and upgrade through the package manager, avoiding leftovers.

    3.3 Verify the Environment After Installation

    After installation, close and reopen the terminal window so PATH takes effect. Then run:

    1. claude --version
    2. # or
    3. claude doctor

    If a version number and basic environment information are printed, the installation succeeded. A region-check error at this point is normal and is handled in the next section.


    4. Step 2: Handle Region Access Restrictions and Complete Initialization

    4.1 Cause of the Error

    Some tools perform a “region/availability check” against the server at startup. When the outbound IP is judged to be outside the allowed region, the terminal prints a message like “not available in your region” and may abort the startup flow.

    4.2 How to Handle It

    Option 1: Solve it at the network layer (recommended)

    Use a compliant enterprise proxy or a trusted egress so the originating IP falls within the allowed region. This is the cleanest approach and changes no client state.

    Option 2: Skip the onboarding flow

    If you only need a locally configured custom model service, you can skip the first-run onboarding. The tool’s onboarding state is usually stored in a configuration file in the home directory:

    1. # Windows
    2. notepad.exe %USERPROFILE%\.claude.json
    3. # macOS / Linux
    4. nano ~/.claude.json

    Add or modify the following in the JSON object:

    1. {
    2. "hasCompletedOnboarding": true
    3. }

    Save the file, reopen the terminal, and run claude. The region error no longer appears and the tool enters its normal interactive interface.

    Note: .claude.json is a client-private configuration file, and fields may be added or removed across versions. Back up the original file before editing to avoid field conflicts after an upgrade.

    4.3 Directory Trust Confirmation

    The first time you enter a working directory, the tool asks whether to trust it (because it will read files and run commands there). Press Enter to confirm. To revoke trust, remove the corresponding directory entry from the configuration file.

    Exit the interactive interface with Ctrl + C twice, or type /exit.


    5. Step 3: Prepare a Model API Key

    5.1 Why You Need Your Own Key

    The shell tool contains no model weights. Its capability ceiling is determined by the model it connects to. Before use, you must do the following on a model service platform:

    1. Register and complete any required verification.
    2. Open the “API Keys” management page in the console.
    3. Create a new key and copy and save it immediately — most platforms, for security reasons, show the full key only once at creation; after the dialog closes it cannot be viewed again, only regenerated.
    4. Note the call address (Base URL) and the available model identifier (Model ID).

    5.2 General Selection Considerations

    Dimension Description
    Protocol compatibility Whether a compatible endpoint matching the shell tool is offered
    Context length Affects how much code can be fed in at once
    Response speed Interactive coding is sensitive to time-to-first-token
    Stability and rate limits Availability under high-frequency tool calls
    Data compliance Whether commercial code input is allowed, and what retention policy applies
    Billing Per-token or monthly; estimate against your own usage

    Suggestion: During development, start with a smaller model to verify the connection. Once tool calls, file reading/writing, and multi-turn conversation all work, switch to a larger model for better code understanding.


    6. Step 4: Switch Models with a Configuration Management Tool

    6.1 Pain Points of Manual Configuration

    Command-line coding tools usually read model configuration from two places:

    • The user-level configuration file (the env section in ~/.claude.json);
    • The project-level configuration file (the .claude/ directory in the working directory).

    The pain points of maintaining this by hand:

    1. Multiple configuration locations drift out of sync and are hard to troubleshoot.
    2. Switching frequently between “default service / private service / test service” leads to missed edits.
    3. The precedence between environment variables and configuration files is unclear.

    6.2 What a Configuration Management Tool Does

    A cross-platform configuration management tool can:

    • Save multiple sets of model connection parameters as “configuration profiles”.
    • Switch the active profile with one action.
    • Automatically write to the configuration file locations the tool reads, avoiding manual-edit mistakes.

    6.3 Key Parameter Mapping

    The core fields in a configuration profile map the model service’s interface information onto the shell tool’s environment variables:

    Shell Tool Environment Variable Meaning Source
    ANTHROPIC_BASE_URL Model service call address API address from the model platform console
    ANTHROPIC_AUTH_TOKEN Authentication token API key created on the model platform
    ANTHROPIC_MODEL Primary model identifier Model list page on the model platform
    ANTHROPIC_SMALL_FAST_MODEL Lightweight model identifier Used for auxiliary tasks such as generating conversation titles

    For a service compatible with the Anthropic protocol, the configuration looks like:

    1. {
    2. "env": {
    3. "ANTHROPIC_BASE_URL": "https://<model-service-address>/v1",
    4. "ANTHROPIC_AUTH_TOKEN": "sk-<your-key>",
    5. "ANTHROPIC_MODEL": "<primary-model-id>",
    6. "ANTHROPIC_SMALL_FAST_MODEL": "<lightweight-model-id>"
    7. }
    8. }

    The Model ID must match the platform documentation exactly, including capitalization and version suffix. A wrong value usually shows up as a 404 or “model not found” rather than an authentication failure — a common troubleshooting misconception.

    6.4 Configuration Precedence

    Understanding precedence helps with troubleshooting:

    1. Parameters passed explicitly on the command line;
    2. Project-level configuration;
    3. User-level configuration;
    4. Environment variables;
    5. The tool’s built-in defaults.

    When a switch does not take effect, first check whether a project-level configuration is overriding the user-level one.


    7. Step 5: Use It Inside a Code Editor

    7.1 Open the Integrated Terminal

    Open the integrated terminal in the editor via the menu or a shortcut (such as Ctrl + ` ). Its working directory defaults to the current project root, so the tool can automatically detect the project structure.

    7.2 Enter the Interactive Interface

    1. cd <your-project-directory>
    2. claude

    If prompted to choose a model on first entry, select the model corresponding to the profile activated in your configuration management.

    7.3 Common Interaction Modes

    • Chat mode: Type a natural-language request; the tool reads relevant files itself and suggests changes.
    • Specified-file mode: Name the file path in the question to reduce ineffective searching.
    • Plan mode: Have the tool output an implementation plan first, confirm it, then let it write changes. Suitable for larger changes.
    • Command mode: Type /help to see supported slash commands, such as /init (generate project documentation), /cost (view usage for the session), and /clear (clear context).

    7.4 Permissions and Safety Boundaries

    Because the tool can read and write files and run commands, it is recommended to:

    1. Place an ignore list in the project root so sensitive files are kept out of context.
    2. Enable the tool’s auditable mode for company code and retain operation logs.
    3. When using a model for the first time, validate its stability with read-only tasks (explaining code, suggesting tests) before opening write access.

    8. Step 6: Verify the Connection End to End

    After configuration, validate with a set of cases that progress from simple to advanced:

    Case 1: Basic connectivity

    1. Reply "connectivity is normal" and tell me the model identifier you are currently using.

    If the response is normal and the model identifier matches the configuration, authentication and routing are correct.

    Case 2: Context reading

    1. Read src/utils/format.ts and summarize its responsibility in three sentences.

    This verifies file reading and context injection.

    Case 3: Tool calling

    1. Add unit tests for the formatDate function in src/utils/format.ts and write them to tests/format.test.ts.

    This verifies the file-writing and command-execution path.

    Case 4: Multi-turn consistency

    1. Rewrite the tests you just wrote using a parameterized style.

    This verifies context retention.

    If any case fails, troubleshoot in the order “authentication → address → model identifier → network proxy → tool version”; the cause is usually found within five steps.


    9. Common Issues and Troubleshooting Checklist

    Symptom Possible Cause Fix
    Region restriction error at startup Outbound IP is outside the allowed range Use a compliant proxy, or skip the onboarding flow
    401 / authentication failure Key is wrong or has been revoked Regenerate the key and update the configuration profile
    404 / model not found Model identifier is misspelled Check character by character against the platform documentation
    Request timeout Network proxy is not applied or unreachable Check proxy environment variables and connectivity
    Configuration change has no effect Overridden by project-level configuration Trace the configuration files in precedence order
    Poor response quality Model capability does not match the task Switch to a larger model or adjust the prompt
    Context is truncated Context length exceeded Split the task or choose a long-context model

    10. Advanced Recommendations and Best Practices

    1. Configuration as code: Export model connection profiles for different environments as text and manage them in internal team documentation, so new members can apply them directly.
    2. Key management: Never commit API keys to a repository; inject them via the system keychain or environment variables. Enterprises can use a key management service for centralized distribution and rotation.
    3. Tiered model strategy: Use a lightweight model for simple completion and formatting, and a larger model for architecture design and complex refactoring, balancing cost and quality.
    4. Observability: Monitor model call volume, failure rate, and average latency, and connect to a unified logging service for capacity planning and fault localization.
    5. Continuous upgrades: The shell tool iterates quickly. Fix an upgrade window and validate configuration compatibility in a branch environment before upgrading.
    6. Team norms: Define which code may be sent to a model service and which may not, document it, and include it in the code review process.

    11. Summary

    Connecting a command-line AI coding assistant to your own LLM is technically less about “installation” and more about understanding the configuration hierarchy and protocol compatibility. The path in this guide reduces to:

    Install via package manager → verify environment variables and PATH → skip or avoid the region onboarding → obtain a model key with a compatible protocol → create switchable profiles with a configuration management tool → validate in the editor’s integrated terminal with cases from simple to advanced.

    With this methodology in hand, whether switching to models of different sizes or adapting to an enterprise’s private inference service, you can reuse the same troubleshooting and validation flow and avoid repeating the same mistakes.