AI Coding Assistant Alternatives for Mainland China: Windows 11 Setup Guide with Chinese LLM APIs

    This guide explains how developers in mainland China can keep using command-line AI coding assistants when overseas services are slow or unavailable. It covers how to choose a replacement model with a compatible API, how to configure Windows 11 with PowerShell environment variables, how to verify that the model has switched, and how to troubleshoot common errors.

    1. Background: Why an Alternative Is Needed

    Developers in mainland China have recently found that several widely used AI coding tools hosted outside China are unstable or unavailable. For developers who rely on AI pair programming, this affects code generation, refactoring, debugging, and documentation.

    The causes generally fall into two categories:

    • Restricted network paths: Endpoints outside China often have high latency, heavy packet loss, or fail to connect at all.
    • Account and payment barriers: Registration, subscription, and payment flows are often difficult for users in mainland China, so the service is effectively unavailable.

    Most mainstream command-line AI coding assistants follow open protocol designs, and their request formats closely match the conversation protocols of mainstream LLM APIs. This means you can keep the tool and your existing workflow, and replace only the underlying model with a large language model service that is stably accessible from China. This approach of keeping the tool and swapping the model is currently the smoothest migration path.

    2. Choosing a Replacement Model

    When evaluating replacement models, consider the following dimensions:

    1. Protocol compatibility: Prefer model services that offer an Anthropic-compatible or OpenAI-compatible API. This avoids changes to the tool’s adaptation code. Major Chinese cloud providers and model vendors commonly offer such compatibility layers. Pointing the tool to a compatible endpoint with environment variables is enough to switch.
    2. Coding capability: Programming tasks require strong code understanding, long context handling, and function calling. Use a flagship model for complex tasks, and a lightweight model for simple completion tasks to reduce cost.
    3. Cost and quotas: Chinese model services are usually billed per token. Some vendors offer free quotas or monthly plans, so individual developers can test on a small scale before scaling up.
    4. Stability: Choose services that provide official endpoints and hold the required regulatory filings in China. This avoids the security risks of relay proxies.

    A typical layered configuration maps the main model and the lightweight model to the tool’s advanced and fast tiers, balancing quality and cost.

    3. Environment Setup (Windows 11)

    1. Allow Script Execution

    Windows blocks local PowerShell scripts by default. Before the first setup, allow script execution for the current user. Open PowerShell as a standard user or as an administrator, and run:

    1. Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force

    This command affects only the current user, so the change is controlled. You only need to run it once.

    2. Install the Command-Line Assistant

    Install the command-line AI coding assistant globally with npm. The steps below use the general npm package workflow:

    1. npm install -g @anthropic-ai/claude-code

    After installation, run claude --version in a terminal to verify. If you see a “command not found” error, the npm global install directory is not in the system PATH. Apply the path fix in the next step.

    3. Fix the Global Command Path (One-Time)

    On Windows, npm global packages are installed by default into an npm subfolder of the user directory. In some environments, this folder is not added to PATH automatically. Run the following command to add it permanently:

    1. [Environment]::SetEnvironmentVariable(
    2. "Path",
    3. $env:Path + ";$env:APPDATA\npm",
    4. [System.EnvironmentVariableTarget]::User
    5. )

    Note: After changing environment variables, close and reopen all terminal windows for the new PATH to take effect. The integrated terminal in VS Code also requires restarting the entire editor.

    4. Permanently Configure a Chinese LLM Service

    1. Edit the PowerShell Profile

    To load the environment variables automatically each time a terminal opens, write them to the PowerShell profile file:

    1. if (!(Test-Path $PROFILE)) {
    2. New-Item -Type File -Path $PROFILE -Force
    3. }
    4. notepad $PROFILE

    2. Add the Environment Variables

    In the Notepad window, paste the entire block below and replace each placeholder with the API key and model names from your model service platform:

    1. # ========== AI coding assistant + Chinese LLM ==========
    2. $env:ANTHROPIC_BASE_URL = "<compatible endpoint URL>"
    3. $env:ANTHROPIC_AUTH_TOKEN = "<your_API_key>"
    4. $env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "<lightweight model name>"
    5. $env:ANTHROPIC_DEFAULT_SONNET_MODEL = "<flagship model name>"
    6. $env:ANTHROPIC_DEFAULT_OPUS_MODEL = "<flagship model name>"
    7. # ============================================

    The three variable groups do the following:

    • BASE_URL: The protocol-compatible endpoint from the model provider. The tool sends requests to this address instead of the original overseas service.
    • AUTH_TOKEN: The authentication credential. Replace the placeholder with your own key, and never commit it to a code repository.
    • DEFAULT_*_MODEL: Map the tool’s three internal model tiers (fast, standard, and advanced) to the actual Chinese models, so requests are routed by tier.

    Save and close Notepad, then restart the terminal. The configuration takes effect permanently.

    5. Verify and Launch

    In any PowerShell, CMD, or VS Code terminal, run:

    1. claude

    Once the interactive session starts, check whether the model has switched by running:

    1. /model

    Or ask directly:

    1. What model are you?

    If the response names the Chinese model provider and model, the configuration is working, and you can start using the tool.

    6. Troubleshooting Checklist

    Symptom What to check
    claude command not recognized Apply the global path fix above, then restart the terminal
    Environment variables must be set again every time a terminal opens Confirm the configuration is saved in $PROFILE and restart the terminal
    Authentication fails Check that AUTH_TOKEN contains your own key and no extra spaces
    Request timeout Confirm BASE_URL is the official endpoint from the provider, and check whether a local proxy app interferes with direct connections
    Model name error Confirm the model identifier exactly matches the name in the service platform’s documentation

    7. Further Recommendations

    • API key security: Do not write API keys into project code or commit them to Git. Besides the profile file, you can store keys in system-level user environment variables or a secrets management tool.
    • Standardized team setup: Teams can write a shared initialization script, such as a PowerShell installation script or configuration template. New members can then set up their environment in one step, which reduces coordination overhead.
    • Mixed model usage: Use the flagship model for complex refactoring, and the lightweight model for everyday questions and simple completions. This can noticeably reduce token usage.
    • Track tool updates: Mainstream coding assistant tools change quickly. After upgrading the tool, verify that the environment variable mappings still work.

    8. Summary

    Limited access to