Quickly install Claude Code via NPM or scripts, configure third-party models like DeepSeek and Zhipu GLM to reduce usage costs, and use the Claude Code Router (CCR) to build an intelligent routing system. The article details key technical points such as multi-provider management, dynamic routing strategies, request transformation, and cost optimization, and provides complete configuration examples and architectural designs.
I. Introduction to Claude Code
Claude Code is an intelligent terminal coding agent tool launched by Anthropic that "lives in your terminal." It can understand project structures, edit code, execute commands, manage Git, and perform other development tasks. Although IDE integration is supported, its core design philosophy is command-line driven.
Simply put, running the claude command in any terminal environment allows an AI assistant to help you write code, fix bugs, generate documentation, and even manage version control.
II. Installation and Configuration
2.1 Installation Methods
Method 1: NPM Installation (Recommended for Node.js Users)
bash
npm install -g @anthropic-ai/claude-code
Method 2: Native Installation Scripts
macOS / Linux / WSL
bash
curl -fsSL https://claude.ai/install.sh | bash
Windows PowerShell
powershell
irm https://claude.ai/install.ps1 | iex
Windows CMD
cmd
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
Verify Installation
bash
claude --version
# Or run directly
claude
Seeing version information or entering the interactive prompt indicates a successful installation.
2.2 Login and Authorization
The first time you run claude, you will be prompted to log in, which supports two methods:
Personal Users: Interactive login using a Claude.ai account.
Enterprise/API Users: Authorization using an Anthropic API Key.
Credentials are usually saved in ~/.config/claude or another local storage location specified by the CLI. You can re-login or switch accounts later using the /login command.
Contents
2.3 Basic Usage Examples
Enter your project directory and start:
bash
cd /path/to/your/project
claude
In interactive mode, describe your needs in natural language:
> create utilities/logger.py with rotating file handler
> write unit tests for date parsing edge cases
> explain this function foo in module bar
> refactor module baz to async/await
Claude Code automatically reads the project context, understands the code structure, and executes the corresponding operations.
III. Why Integrate Third-Party Models?
While Claude Code is powerful, directly using official models presents the following challenges:
3.1 Real-World Issues
High Cost: Official models are billed per token, leading to significant expenses for long-term or high-volume usage.
Quota Limitations: Daily or weekly call limits can be inconvenient for heavy users who frequently adjust their strategies.
Lack of Flexibility: Inability to directly use third-party or self-hosted models like DeepSeek, OpenRouter, or local LLMs.
3.2 Solutions
By inserting a routing/proxy layer into the call chain, you can achieve:
Routing to different models based on task type or cost strategy.
Reducing overall usage costs.
Improving service availability.
Gaining greater flexibility in model selection.
IV. Quick Integration: Compatible Model Direct Connection
4.1 DeepSeek Integration
DeepSeek provides an interface compatible with the Claude API, allowing for a "painless replacement" via environment variables:
You can add these commands to ~/.bashrc, ~/.zshrc, or system environment variables. Fish users can add the following configuration to ~/.config/fish/config.fish.
fish
set -gx ANTHROPIC_BASE_URL https://api.deepseek.com/anthropic
set -gx ANTHROPIC_AUTH_TOKEN
set -gx API_TIMEOUT_MS 600000
set -gx ANTHROPIC_MODEL deepseek-chat
set -gx ANTHROPIC_SMALL_FAST_MODEL deepseek-chat
set -gx CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC 1
After configuration, running claude will automatically redirect all model calls to DeepSeek.
{"env":{"ANTHROPIC_AUTH_TOKEN":"your_zhipu_api_key","ANTHROPIC_BASE_URL":"https://open.bigmodel.cn/api/anthropic",// Mainland China region// "ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic", // International version"API_TIMEOUT_MS":"3000000","ANTHROPIC_DEFAULT_HAIKU_MODEL":"glm-4.5-air","ANTHROPIC_DEFAULT_SONNET_MODEL":"glm-4.6","ANTHROPIC_DEFAULT_OPUS_MODEL":"glm-4.6"}}
Environment Variable Method
The JSON method may fail, and you can also use environment variable configuration (refer to deepseek):