Using Claude Code in Restricted Networks: A Practical Setup Guide
This guide explains how to set up and run a terminal-based AI coding tool in network environments where the default installation and subscription flows are unreliable. It covers installing the Node.js runtime, switching npm to a reachable mirror, installing the tool globally, connecting a pay-as-you-go LLM endpoint through environment variables, and managing multiple provider profiles with a GUI switcher. It also includes a troubleshooting checklist and cost-control recommendations for engineering teams.
1. Why Installation and Access Often Break Down
Most developers hit two practical barriers the first time they try a terminal-based AI coding tool.
The first is acquisition. The recommended installation flow usually pulls a script from an overseas host and runs it directly. Those domains are often unreachable or unstable from certain networks, so the command hangs after you press Enter and eventually fails with a timeout. The problem is not your command; the network path itself is unavailable.
The second is usage. Once installed, the tool asks you to sign in and bind a subscription on first launch. The lowest tier’s monthly fee, plus an overseas payment method, is an extra burden for most individual developers and small teams.
This article addresses both points: switch the installation path to a mirror that is directly reachable, point the backend model at a directly reachable, pay-as-you-go general-purpose LLM service, and use a GUI configuration tool to manage multiple providers in one place. Note that both paths run the same tool program. The only difference is where the inference service behind it lives. The experience is similar; the cost structure is not.
2. Overall Approach and Prerequisites
The setup has four layers, each depending on the one below it:
- Runtime layer: an LTS release of Node.js, which provides the environment for running npm commands;
- Tool layer: the AI coding tool installed via npm from a reachable mirror;
- Model layer: an API key from a general-purpose LLM platform, billed by usage;
- Management layer: a configuration switcher that maintains multiple provider profiles for one-click switching.
About the runtime: you do not need to understand JavaScript engines or the event loop. Treat it simply as “the base software required to run npm commands.” The hard requirement is a major version of 18 or higher. Choosing a release marked LTS is recommended, since it is more stable in production.
3. Step 1: Install the Runtime
Official mirror sites distribute Node.js installers that download quickly and offer a Chinese-language interface, so they can be used first; the official download page also works, just with inconsistent speed.
- Windows: download the .msi installer, double-click it, and follow the wizard;
- macOS: download the .pkg installer, double-click it, and follow the wizard;
- If an older version is already present, uninstall it before installing the new one to avoid multiple versions competing and commands resolving to the wrong binary.
After installation, open a terminal and verify with two commands:
node -vnpm -v
If node -v reports a major version below 18, a leftover older version exists on the system. Check the order of paths in your PATH environment variable.
4. Step 2: Switch the Mirror and Install the Tool
The default npm registry is hosted overseas, so installs often stall midway. Switch to a reachable mirror first:
npm config set registry https://registry.npmmirror.comnpm config get registry
Then run the global install and add the executable directory to PATH:
npm install -g @anthropic-ai/claude-code
Verify the installation:
claude --version
If the command is not found, the global bin directory is usually missing from PATH. On Windows it is typically the npm global path under the user directory; on macOS and Linux it is often /usr/local/bin or a user-level npm prefix directory. Add it and reopen the terminal. If permissions are insufficient, avoid reaching for sudo. A safer approach is to configure a dedicated global install prefix for the current user.
5. Step 3: Obtain a Model Service Key
Open the platform’s developer console, register, complete identity verification, and create an API key. Billing is per call, top-ups go through mainstream local payment channels, and no overseas credit card is required.
Three rules for key management:
- Inject keys only through environment variables or a local config file; never commit them to project code or a repository;
- Use separate keys per environment so each can be revoked independently;
- Set account balance alerts and call quotas to prevent abnormal consumption.
An illustrative environment variable setup:
export ANTHROPIC_BASE_URL="https://your-endpoint.example/v1"export ANTHROPIC_AUTH_TOKEN="sk-your-key"
Endpoint paths and key field names differ slightly between providers. Follow the integration instructions in the provider’s console rather than guessing.
6. Step 4: Switch Between Profiles with a GUI
Editing environment variables by hand is error-prone and hard to trace. A desktop configuration switcher stores “endpoint URL + key + model parameters” as separate profiles and switches between them from a tray menu. Adding a provider usually takes about thirty seconds.
A suggested profile structure:
{"provider": "domestic-llm","baseUrl": "https://your-endpoint.example/v1","apiKeyRef": "env:LLM_API_KEY","model": "general-chat-model","timeout": 120000}
Note that apiKeyRef is a reference, not a plaintext secret; the key itself stays in the system keychain or an environment variable. After switching, open a new terminal and validate connectivity with one minimal-cost chat request before starting real development work.
7. Troubleshooting Checklist
- Command hangs after Enter: the network path is unreachable. Switch the mirror first, then check proxy settings;
- Install succeeds but the command is not found: PATH does not include the global bin directory;
- Auth failure from the API: wrong key field name or endpoint path;
- Model not found in the response: the model identifier must match the console listing exactly;
- Response interrupted or timing out: increase the timeout and check local network and firewall settings.
8. Cost and Engineering Recommendations
Usage-based billing means cost scales linearly with call volume. At the engineering stage, do three things: cap the context length per request on the tool side; capture repetitive tasks as in-project rule files and command templates; and track call volume and failure rates through a monitoring and alerting service. If a team needs stronger isolation and auditability, deploy the inference service inside a container platform and pair it with logging and object storage to retain call records, forming an accountable loop.
At this point you have bypassed both barriers: the runtime comes from a reachable mirror, the tool installs from a reachable registry, the model is supplied by a platform on a pay-as-you-go basis, and multiple profiles are managed by a GUI tool. The whole flow is reproducible, rollback-friendly, and easy to extend when swapping in a new model service later.
