Installing and Using Agentic Coding Tools with Domestic Mirror Sources and Replaceable Model APIs

    This guide explains how to set up an agentic coding tool when official installation scripts and overseas subscriptions are unavailable. It covers preparing the Node.js runtime, installing the CLI through a mirror-based npm registry, obtaining a directly reachable, pay-as-you-go LLM API key, and switching providers with a graphical configuration tool. It also includes troubleshooting, cost and security practices, and the underlying request loop that makes model replacement possible.

    1. Background: Two Barriers Block Most Attempts

    Using an agentic coding tool in the terminal has become part of many developers’ daily workflow. In some network environments, however, installation and usage run into two typical obstacles.

    The first is that the installation source is unreachable. The officially recommended install script is usually hosted on an overseas domain, so running it tends to time out, break midway, or return a connection failure. The problem is not your machine; the script URL simply cannot be reached reliably from the current network.

    The second is the service and billing barrier. The tool itself can be installed, but to actually run it you need to link an overseas subscription and payment method. For developers who only want personal validation, learning, or a small-scale trial, this upfront cost is too high.

    This article addresses a clear goal: run an equivalent tool without relying on an overseas install script or an overseas subscription, and make the underlying model replaceable. The overall path has four steps.

    1. Prepare the runtime environment (Node.js 18 or later).
    2. Install the CLI through a domestic mirror source.
    3. Obtain a large-model API key from a provider that is directly reachable domestically and supports pay-as-you-go billing.
    4. Use a graphical configuration tool to switch providers and verify the setup.

    One point deserves emphasis: both routes ultimately run the same program. The only difference is “where the model request is sent.” The interactive experience is essentially the same, while the cost structure can differ by an order of magnitude.

    2. Step 1: Prepare the Node.js Runtime

    These tools are usually distributed as npm packages, so you need a Node.js runtime, version 18 or higher. You do not need to understand how the JavaScript engine works; just treat it as “the prerequisite software for running npm commands.”

    Download recommendations:

    • Prefer the LTS (Long-Term Support) version for better stability and compatibility.
    • When access to the official download page is slow, use a mirror site instead; these usually offer a Chinese-language interface and faster downloads.
    • On Windows, choose the .msi installer; on macOS, choose the .pkg installer. Double-click and complete the setup with the wizard’s default options.

    After installation, open a terminal and verify:

    1. node -v
    2. npm -v

    If both commands print a version number and the Node version is not lower than 18, the environment is ready.

    A common pitfall: after installation, the terminal reports “command not found.” This is usually caused by environment variables not being refreshed, so simply open a new terminal window. If it still fails, check whether “Add to PATH” was selected during installation.

    3. Step 2: Install the CLI Through a Domestic Mirror Source

    The default npm registry is overseas, and installing large packages often fails midway. Switching to a domestic mirror source is the key to a stable installation.

    1. # Check the current registry
    2. npm config get registry
    3. # Switch to a domestic mirror source
    4. npm config set registry https://registry.npmmirror.com
    5. # Install the CLI globally (package name per the official documentation)
    6. npm install -g @anthropic-ai/claude-code

    If the global install hits a permission error, do not immediately escalate with sudo. A safer approach is to configure a user-level global directory:

    1. mkdir -p ~/.npm-global
    2. npm config set prefix ~/.npm-global
    3. # Add ~/.npm-global/bin to PATH, then reinstall

    After installation, verify:

    1. claude --version

    A printed version number means the installation succeeded. At this point no model is available in the code yet; the next step solves “where the model comes from.”

    4. Step 3: Obtain a Directly Reachable Large-Model API Key

    The goal of this step is to replace the overseas subscription with a model service that is directly reachable domestically and supports pay-as-you-go billing. When choosing, focus on four points:

    • Network reachability: the domain and API are directly reachable domestically, with no extra proxy required.
    • Billing model: billed by token usage, top-ups supported through locally common payment methods, avoiding a minimum monthly fee.
    • API compatibility: whether it is compatible with the mainstream OpenAI-style protocol, which determines the switching cost for the tool.
    • Quota and rate limits: whether the free tier and per-minute request cap meet trial needs.

    The application flow is usually: register an account → complete identity verification → create an API key in the console → top up or claim the free quota.

    Key security is the priority, with three practical recommendations:

    1. Store keys only in local configuration or the system keychain; never write them into project code or commit them to version control.
    2. Create separate keys for different purposes, making individual revocation and usage attribution easier.
    3. Rotate keys periodically in the console, and revoke immediately if abnormal calls are detected.

    Adding rules such as .env and *.key to .gitignore is the lowest-cost way to prevent leaks.

    5. Step 4: Switch Configuration Graphically for Hot Model Switching

    CLI tools usually specify the model service URL and key through environment variables, and manual editing is error-prone. The value of a graphical configuration tool is that it abstracts “service URL + key + model name” into a savable configuration profile that can be switched with one click.

    The configuration logic can be abstracted as:

    1. {
    2. "providers": [
    3. {
    4. "name": "domestic-provider",
    5. "base_url": "https://api.example.com/v1",
    6. "api_key": "sk-***",
    7. "model": "deepseek-chat"
    8. }
    9. ],
    10. "active": "domestic-provider"
    11. }

    The corresponding environment-variable form (illustrative):

    1. export ANTHROPIC_BASE_URL="https://api.example.com"
    2. export ANTHROPIC_AUTH_TOKEN="sk-***"
    3. export ANTHROPIC_MODEL="deepseek-chat"

    When adding a new provider, you only need to add one provider record and switch active, usually done within 30 seconds. Compared with editing the config file by hand every time, the error rate drops significantly.

    To verify it works, issue a minimal request inside the tool:

    1. > Explain idempotency in one sentence

    A normal response means the “tool → gateway → model” chain is connected.

    6. How It Works: Why This Path Succeeds

    The core of these tools is a loop: read context → assemble the request → call the model API → parse the response (text or tool call) → execute the tool → feed the result back. What is actually tied to the vendor is just three configuration items: “which URL the request goes to, which key is used, and which model name is specified.”

    As long as the target service implements a compatible API protocol, the tool side needs no code changes to complete the swap. This is also the foundation that makes model gateways and aggregation proxies viable. Once you understand this, you are no longer locked to a single provider and can choose models flexibly by task type (long context, code completion, complex reasoning).

    7. Troubleshooting Common Issues

    • Install script times out: do not retry the official script; go straight to the mirror source plus npm path.
    • npm install fails midway with ETIMEDOUT: switch the mirror source and retry; if necessary, clear the cache with npm cache clean --force.
    • Request returns 401: the key is wrong or not in effect; check for stray spaces and whether the wrong environment variable name was used.
    • Request returns 404: the service URL is missing or has an extra /v1; align the path with the provider’s documentation.
    • Response content is truncated: lower the expected output length per call, or switch to a model with a larger context window.
    • Response is noticeably slower: first check the local network, then look at the provider’s rate-limit status.

    8. Cost and Security Practice Checklist

    • Under pay-as-you-go billing, set a monthly budget alert for daily use to avoid runaway calls.
    • Split long tasks into smaller runs to reduce token consumption from repeatedly sending redundant context.
    • Do not upload sensitive code to untrusted services; for enterprise scenarios, prefer private deployment or dedicated instances.
    • When a team shares access, distribute keys through a unified gateway so members never touch the real key.
    • Keep a rollback-able configuration backup so you can recover quickly if a switch fails.

    9. Summary

    The difficulty of using agentic coding tools in a domestic environment is essentially two blocked links—the distribution chain and the billing chain—rather than a lack of technical capability. Using a mirror source solves distribution, a compatible-API domestic model service solves billing, and a graphical configuration tool pushes switching cost to the minimum, yielding a stable, controllable, and extensible workflow. The same approach applies to onboarding any new model service later, giving it long-term reuse value.