Command-Line AI Coding Assistant Setup: Installation and Chinese LLM API Integration
This guide explains what terminal-based AI coding assistants can do, how to check your environment before installing Claude Code, how to install and verify it, and how to connect Chinese LLM APIs through Anthropic-compatible endpoints or a protocol conversion gateway. It also covers endpoint testing and common troubleshooting.
1. What a Terminal AI Coding Assistant Can Do
A terminal AI coding assistant runs directly in the command line. Its difference from an IDE plugin is scope. Plugins mostly complete code around the current file, while terminal tools can read the whole project, execute commands, run tests, and continue fixing based on failure output.
Common capabilities include:
- Codebase understanding: read the project structure and key files, and answer questions such as “where is a certain function called?”
- Code generation and modification: add features, modify existing code, or add unit tests based on natural language descriptions.
- Terminal execution: run shell commands, inspect output, and try again after a test failure.
- Git assistance: generate commit messages, organize branch content, and help prepare merge requests.
- Multimodal input: some tools can accept screenshots or architecture diagrams. Support depends on the specific tool and model; check the corresponding documentation before use.
These tools are suitable for prototyping, code review, small refactors, getting familiar with unfamiliar projects, and writing automation scripts. Changes involving core business or security logic still require human review.
2. Environment Checks Before Installation
Before installation, confirm the following items one by one.
- Operating system: macOS and Linux support is more mature. On Windows, use WSL2. The native environment requires more configuration steps and has a higher chance of errors.
- Node.js: Claude Code is distributed via Node.js. Use the minimum version currently stated in the official documentation; a common requirement is LTS 18 or above. Check with:
node -vnpm -v
- Git: run
git --versionto confirm it is installed. The tool relies on Git to determine repository status; some features are limited if Git is not installed. - Terminal: choose a terminal with true color support for clearer display.
- Permissions: before a global install, run
npm config get prefixand confirm that the output directory is writable by the current user. Do not install with sudo; otherwise, file permission issues will be harder to troubleshoot later.
If any check fails, fix it before installation. This can save most of the troubleshooting time later.
3. Installation and First Launch
Using Claude Code as an example, install it globally via npm:
npm install -g @anthropic-ai/claude-codeclaude --version
If the second command outputs a version number, the command is in PATH. If the command is not found, check whether the bin subdirectory under the directory returned by npm config get prefix has been added to PATH.
Enter the project directory and start it:
cd your-projectclaude
The first run will guide you through login or API key configuration. After entering the interactive interface, you can verify it with three typical tasks:
> Explain the overall architecture of this project> Find unused functions in src/utils> Write unit tests for the auth module and run them
If the tool can read project files, give answers consistent with the code, and execute commands, the basic environment is ready. This step does not yet involve Chinese LLM integration.
4. Connecting Chinese LLM APIs
This section is the key configuration part. Before connecting, clarify the interface protocol provided by the model service. If the protocol does not match, configuration will fail, and the error messages are often not intuitive.
4.1 Confirm Protocol Compatibility
Claude Code communicates with models through the Anthropic Messages API protocol. It reads environment variables including ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_API_KEY, and ANTHROPIC_MODEL. Only when the platform provides an endpoint compatible with this protocol can you directly fill the address and key into these variables.
Confirm the following two points in the platform documentation:
- Whether the platform provides an Anthropic Messages API-compatible address. The documentation usually explicitly states “Anthropic-compatible” or provides the corresponding base address.
- If the platform only provides an OpenAI-compatible API, you cannot directly fill the key into the
ANTHROPIC_*variables. Use the gateway solution described below.
For the specific access address and protocol support of Baidu AI Cloud Qianfan, refer to its official documentation. This article does not assume that the platform provides a fixed Anthropic-compatible address.
4.2 Two Integration Paths
Path 1: The platform provides an Anthropic-compatible endpoint. Replace the content in angle brackets with the real values from the documentation:
export ANTHROPIC_BASE_URL="<Anthropic-compatible address from the platform documentation>"export ANTHROPIC_AUTH_TOKEN="<API Key created in the platform console>"export ANTHROPIC_MODEL="<model ID from the platform model list>"
Confirm the three values separately:
- Address: fill in the base address given by the documentation. The client appends the API path itself; do not manually add the API path at the end of the address.
- Authentication:
ANTHROPIC_AUTH_TOKENis sent as a Bearer token. If the platform requires anx-api-keyrequest header, useANTHROPIC_API_KEYinstead. Choose one of the two according to the platform documentation. - Model name: it must exactly match the ID in the platform model list, including case and version suffix.
Path 2: The platform only provides an OpenAI-compatible API. In this case, deploy a protocol conversion gateway on your local machine or server, such as claude-code-router or LiteLLM. Claude Code connects to the gateway, and the gateway converts requests before sending them to the platform. OPENAI_API_KEY and ANTHROPIC_AUTH_TOKEN cannot be interchanged; the platform address and key should be configured on the gateway side. For gateway configuration, refer to the README of the corresponding project.
4.3 Verification
Test in the current terminal first, and write the configuration to ~/.bashrc or ~/.zshrc only after confirming it works. This avoids leaving incorrect configuration in startup files for a long time. After writing, run source ~/.zshrc or reopen the terminal.
Use curl to test the endpoint directly, which excludes the tool from the equation. The API path must match the platform documentation. If the base address in the documentation already includes /v1, remove /v1 from the command below.
curl -s "$ANTHROPIC_BASE_URL/v1/messages" \-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \-H "anthropic-version: 2023-06-01" \-H "content-type: application/json" \-d '{"model":"<model ID>","max_tokens":16,"messages":[{"role":"user","content":"ping"}]}'
Use the response to determine where the problem is:
- JSON containing a model reply: the endpoint, authentication, and model name are all correct. At this point, start
claudeand ask a simple question. - 401 or 403: the key is invalid or expired, or the authentication header format is incorrect.
- 404: the address or path is wrong, or the address is not an Anthropic-compatible endpoint.
- 400 with a message that the model does not exist:
ANTHROPIC_MODELdoes not match the platform model ID. - The response is not the expected JSON structure, or protocol fields are missing: the endpoint is very likely not compatible with the Anthropic protocol, and you should use Path 2.
5. Common Troubleshooting
- Command not found: check whether the
bindirectory under the output ofnpm config get prefixis in PATH. - Permission error during installation: fix the owner of the npm global directory. Do not use sudo.
- Network timeout: npm mirrors or proxies only affect downloads during installation. For model call timeouts, check proxy settings. You can use
echoto inspect the relevant HTTP proxy environment variables.
