Claude Code with Chinese LLM APIs: Complete Terminal Setup Guide
This guide explains how to install Claude Code, configure it to use Chinese LLM providers that offer Anthropic-compatible endpoints, and validate the setup with real tasks. It covers Node.js and Git prerequisites, environment variables and settings files, first-task verification, troubleshooting, permission rules, and token-based cost control.
Claude Code with Chinese LLM APIs: Complete Terminal Setup Guide
1. Choose the Tool and Model
A terminal coding assistant can read and write project files, execute commands, and run tests. This article uses Claude Code as an example. By default, Claude Code connects to Anthropic’s services. Developers can change the request URL to a Chinese LLM service that supports the Anthropic-compatible API format, such as DeepSeek, Zhipu GLM, or Moonshot Kimi.
When choosing a provider, compare four dimensions:
- Whether it meets your organization’s compliance requirements
- Pricing
- Model performance on coding tasks
- Whether the provider offers an Anthropic-compatible endpoint
Endpoint addresses and model names may change as providers update their services. The examples in this article follow the current versions in each provider’s official documentation.
2. Install Node.js and Git
Claude Code requires Node.js 18.0 or later. Windows users also need Git for Windows because the assistant relies on Git Bash to execute commands on Windows.
Windows (PowerShell):
winget install OpenJS.NodeJS.LTSwinget install Git.Git
macOS (with Homebrew installed):
brew install node git
Linux: The Node.js version in system repositories may be too old. Install nvm first, then run nvm install --lts. Refer to the nvm official repository for installation instructions.
After installation, reopen the terminal and check the versions:
node -v # Should show v18.x or laternpm -vgit --version
If node -v shows a version lower than 18, upgrade Node.js before continuing.
3. Install Claude Code
npm install -g @anthropic-ai/claude-codeclaude --version
If installation reports an EACCES permission error, do not add sudo directly. The recommended approach is to manage Node.js with nvm so that the global installation directory is owned by the current user.
On Windows, if startup reports that Git Bash cannot be found, set CLAUDE_CODE_GIT_BASH_PATH in the system environment variables. Point it to bash.exe, for example C:\Program Files\Git\bin\bash.exe.
4. Connect to Chinese LLM Providers
4.1 Variable Reference
| Variable | Purpose | Example | Notes |
|---|---|---|---|
ANTHROPIC_BASE_URL |
Service address to which requests are sent | https://api.deepseek.com/anthropic |
Fill in according to provider documentation; do not append API paths arbitrarily. |
ANTHROPIC_AUTH_TOKEN |
Authentication key | Your API key | Store only in local configuration; do not commit it to a code repository. |
ANTHROPIC_MODEL |
Default model to use | The model name in the provider documentation, such as deepseek-chat |
A misspelled model name returns an error. |
API_TIMEOUT_MS |
Timeout for a single request, in milliseconds | 600000 |
Increase as needed for large projects. |
If both ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN are set in the system, they may conflict. After configuration, keep only one.
4.2 Write the Configuration File
The configuration file paths are:
- macOS and Linux:
~/.claude/settings.json - Windows:
%USERPROFILE%\.claude\settings.json
If the file does not exist, create it manually. Example content:
{"env": {"ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic","ANTHROPIC_AUTH_TOKEN": "<your API key>","ANTHROPIC_MODEL": "<model name from provider documentation>","API_TIMEOUT_MS": "600000"}}
Replace the three angle-bracket placeholders with real values. If you want the configuration to apply only to the current terminal session, you can also set it with export ANTHROPIC_BASE_URL=..., but this setting expires after the terminal is closed.
5. Run the First Task
Go to the root directory of a test project. Do not start the assistant in your home directory or a system directory. Then run claude and send a read-only instruction:
Read the src directory, list the entry files, and explain the project structure. Do not modify any files.
There are three success criteria:
- The assistant returns a directory analysis.
- A permission prompt appears when files are read.
- No 401, 404, or timeout errors appear in the terminal.
After confirming that the read-only task works, send a small modification task, such as adding unit tests for a function and running the tests. This verifies that both file writing and command execution work correctly.
6. Troubleshooting Checklist
| Symptom | Possible Cause | Troubleshooting |
|---|---|---|
claude: command not found |
npm global directory is not in PATH | Run npm config get prefix, add the bin directory under the output path to PATH, then reopen the terminal. |
EACCES during installation |
sudo was used, or the global directory is not writable |
Use nvm to manage Node.js and avoid sudo. |
401 or authentication_error |
Invalid or expired key, or insufficient balance | Check the key and balance in the provider console, and check for stale environment variables. |
404 or model not found |
Wrong model name, or incorrect endpoint path | Check the model name against provider documentation, and confirm that BASE_URL does not include extra paths. |
Request timeout or ECONNRESET |
Network or proxy issue | Check system proxy settings, increase API_TIMEOUT_MS, and confirm that the endpoint is reachable. |
| Empty or malformed response | The selected model lacks required capabilities such as tool calling | Check provider documentation and switch to a model that supports the required capabilities. |
| Windows cannot find Git Bash | Git is not installed, or the installation path is not the default | Set CLAUDE_CODE_GIT_BASH_PATH to point to bash.exe. |
| Configuration changes do not take effect | An old session or shell variable overrides the configuration | Exit and reopen the terminal; check the variable with echo $ANTHROPIC_BASE_URL (Windows: echo %ANTHROPIC_BASE_URL%). |
7. Permission and Cost Control
The assistant can execute commands, so set boundaries first. In .claude/settings.json at the project root, you can configure permission rules. The syntax depends on the version you use; refer to the official documentation for that version. The following is an example:
{"permissions": {"deny": ["Read(./.env)", "Read(./.env.*)", "Read(./secrets/**)"],"ask": ["Bash(rm:*)", "Bash(git push:*)"],"allow": ["Bash(npm test)", "Bash(pytest:*)"]}}
This configuration means:
- Reading environment variable files and the secrets directory is denied.
- Deleting files and pushing code require confirmation.
- Test commands can run directly.
Also confirm that .env and secret files are listed in .gitignore. During initial use, keep the confirmation prompt for each command and review commands one by one before allowing them.
For cost, models are billed by token. The cost of a single task can be estimated roughly as:
Cost per task ≈ input tokens × input price + output tokens × output price
Input tokens include file content read by the assistant and conversation history, so costs can grow quickly in large projects. Limit tasks to a single module and use /clear to clear the context after a task is complete. Pricing and billing rules vary by provider; refer to the official price list and set daily or monthly usage limits in the console.
Following these steps, developers can complete tool installation, model connection, permission setup, and first-task validation in a local terminal, then gradually expand usage as project needs require.
