Using AI Coding Tools with Domestic LLMs in Restricted Network Environments

    This article explains why AI coding assistants often fail during installation and authentication in restricted network environments, and how to fix both issues. You will learn how to obtain the client through accessible package mirrors, decouple the client from the model service with a three-layer architecture, point the tool to a locally reachable LLM endpoint using configuration files and environment variables, manage multiple configurations with a local switcher, and follow a verification checklist to troubleshoot network, configuration, authentication, and model errors. The article also covers practical engineering recommendations for team adoption and cost control.

    1. Define the Problem: The Bottleneck Is the Chain, Not the Operation

    Many developers hit the same frustration the first time they try to use an AI coding assistant in a terminal: the first installation command from the documentation is copied, pasted, and executed, then the terminal hangs for a long time and finally ends with a timeout or connection failure. This is not a permissions issue, and it is not a shell configuration issue. The domain hosting the installation script is unreachable in the current network environment, so the request is interrupted either at DNS resolution or during the TLS handshake.

    A second barrier appears after a successful installation. These tools generally follow a “free client, paid model service” business model: the command-line program runs locally, but the actual inference capability comes from a remote model service. As a result, the first launch requires account authentication, and that authentication is often tied to an overseas subscription and an overseas payment method. For developers without an overseas credit card, the flow stops at the login page.

    Abstracting these two points yields a general conclusion: the barriers to using AI coding tools are essentially two simultaneously restricted chains — the software distribution chain and the model service chain. As long as each chain is replaced with a channel that is reachable in the local network environment, the capabilities of the tool itself are not reduced.

    2. Overall Architecture: Decoupling the Client, the Switching Layer, and the Model Service

    The recommended practice is to split the system into three layers that communicate through standard protocols:

    • Client layer: the AI coding assistant in the terminal, responsible for reading the codebase, performing file reads and writes, executing commands, and rendering the interactive interface.
    • Configuration switching layer: a local configuration management entry point that maintains multiple sets of service endpoints and keys, and writes the selected configuration into the configuration file or environment variables expected by the client.
    • Model service layer: any inference service compatible with mainstream open API specifications. It can be a general-purpose LLM service from a domestic cloud provider, or a self-hosted inference service.

    The value of this decoupling is that client upgrades, model changes, and key rotation do not interfere with one another. To switch models, you only change the configuration without reinstalling the client; to switch accounts, you only replace the key without touching the code.

    3. Clearing the First Barrier: Obtaining the Installation Package from an Accessible Source

    The direct cause of the installation failure is that the script is hosted on an unreachable domain. There are three workable approaches, listed in order of recommendation:

    1. Install through a package manager. Most AI coding tools offer an npm-based distribution method. Replacing the default official registry with a domestic mirror registry allows the package to be pulled normally:
    1. npm config set registry https://registry.npmmirror.com
    2. npm install -g @anthropic-ai/claude-code
    1. Download the package manually and verify it locally. Obtain the archive for the target platform from a reachable mirror site, verify the hash, extract it into the user directory, and create a symbolic link in a directory on PATH. This approach offers the most control, but you must confirm that the version and the source of the checksum are trustworthy.

    2. Set a proxy for the installation script. If a usable outbound proxy is already available in the environment, the HTTPS_PROXY and HTTP_PROXY environment variables can route the script through the proxy. Note that the proxy applies only to the current shell session; it becomes persistent only after being written into the shell configuration file.

    After installation, run the version query command to confirm the executable is in place. If the command is reported as not found, the global installation directory is usually missing from PATH, and that directory needs to be appended to the environment variable.

    4. Clearing the Second Barrier: Pointing the Model Service Endpoint to a Locally Reachable Service

    The client’s authentication and request address can usually be overridden through a configuration file. Common fields include the service base URL and the API key. The overall flow is as follows:

    Step one: activate a service on any domestic cloud platform that provides general-purpose LLM inference, and create an access key. The key is displayed in full only once, at creation time, so store it immediately in a key management tool or a local environment variable, and never write it into a code repository.

    Step two: prepare a configuration directory. Most tools read a hidden configuration directory under the user’s home directory by default, so you can first copy the default configuration as a template:

    1. mkdir -p ~/.config/claude
    2. cp ~/.claude/settings.json ~/.config/claude/settings.json.bak

    Step three: write the service endpoint and model name into the configuration, and keep an environment variable placeholder:

    1. {
    2. "env": {
    3. "ANTHROPIC_BASE_URL": "https://your-endpoint.example.com/v1",
    4. "ANTHROPIC_AUTH_TOKEN": "${MY_MODEL_KEY}",
    5. "ANTHROPIC_MODEL": "deepseek-chat",
    6. "ANTHROPIC_SMALL_FAST_MODEL": "deepseek-chat"
    7. }
    8. }

    Step four: put the key into an environment variable and launch:

    1. export MY_MODEL_KEY="sk-your-key"
    2. claude

    Two easily overlooked details matter here. First, the main model and the lightweight model should preferably point to the same service; otherwise, when the tool performs small tasks such as context compression or generating conversation titles, it will request the unreachable default endpoint, which shows up as “the conversation works, but occasional errors appear.” Second, some tools perform endpoint connectivity pre-checks. If the service does not implement the path they probe, you can disable non-essential checks in the configuration, or route traffic through a compatible gateway.

    5. Managing Multiple Configurations with a Switcher

    When you compare results and costs across several services, editing configuration files by hand quickly becomes unmanageable. A more reliable approach is to introduce a local configuration switching entry point that stores the “currently active configuration” separately from the “candidate configuration set”:

    1. ~/.cc-switch/
    2. ├── config.json # Candidate configuration set (endpoints, models, key references)
    3. └── active.json # Pointer to the currently active configuration

    The switching action does only one thing: render the candidate configuration into the configuration file expected by the client. An illustrative implementation:

    1. import json, pathlib, os
    2. root = pathlib.Path.home() / ".cc-switch"
    3. candidates = json.loads((root / "config.json").read_text())
    4. active = json.loads((root / "active.json").read_text())
    5. target = candidates[active["name"]]
    6. settings = {"env": {
    7. "ANTHROPIC_BASE_URL": target["base_url"],
    8. "ANTHROPIC_AUTH_TOKEN": os.environ[target["key_env"]],
    9. "ANTHROPIC_MODEL": target["model"],
    10. }}
    11. pathlib.Path.home().joinpath(".claude/settings.json").write_text(
    12. json.dumps(settings, indent=2))
    13. print("Switched to:", active["name"])

    Keys always remain in environment variables or the system keychain, and the configuration file stores only the variable name. This way, even if the configuration directory is accidentally committed, no credentials are leaked.

    6. Verification and Troubleshooting Checklist

    Running the following checks in order covers more than ninety percent of failure scenarios:

    • Network layer: curl -I https://registry.npmmirror.com returns a response, confirming the mirror registry is reachable.
    • Client layer: the version query command outputs a version number normally.
    • Configuration layer: confirm the configuration file path matches the path the tool actually reads, paying attention to letter case and trailing commas in JSON.
    • Authentication layer: verify the key with a minimal request. A 401 response means the key or the format of the authentication header is wrong.
    • Model layer: the model name must exactly match the identifier supported by the chosen service; a 404 is most often caused by this.
    • Long-running task layer: if streaming output is interrupted, first investigate proxy timeouts and buffer settings.

    7. Engineering Recommendations

    In team scenarios, keep configuration templates in internal documentation rather than in the repository, and distribute keys centrally through a key management service. Add monitoring and alerting for reachability, and collect endpoint success rates and time-to-first-token in a unified logging service. For cost-sensitive projects, the switching layer can route tasks to models of different sizes by task type: assign bulk refactoring and comment generation to a more economical general-purpose model service, and reserve architecture design and defect localization for a more capable model. This keeps the toolchain stable while keeping compute spending under control.