Abstract
This tutorial covers end-to-end deployment of Anthropic’s Claude Code CLI tool on Ubuntu Linux, with full integration for DeepSeek’s compatible Anthropic API endpoint. All operations are validated on x86_64 Ubuntu 20.04 and 22.04 environments, with Node.js 20 LTS as the core runtime dependency. Unlike official one-line curl install scripts that suffer regional access failures, this guide uses npm global installation with domestic mirror acceleration for stable setup. We provide a self-contained bash bootstrap script that handles environment variable injection, persistent local configuration, API connectivity validation, and one-click startup. For teams managing multi-model API routing, an API gateway like 4sapi can standardize DeepSeek and Anthropic endpoint forwarding for unified access control.
1. Pre-Deployment Environment Prerequisites
Claude Code is a terminal-native AI assistant built entirely on Node.js, with no direct PyTorch or CUDA runtime dependencies. Before starting installation, verify these hardware & network requirements:
- Operating System: Ubuntu 20.04 / 22.04 (x86_64 or ARM64 architecture)
- Minimum Memory: 4GB RAM
- Network Access: Reachable npm mirror (Tsinghua mirror recommended for mainland China)
1.1 Install Node.js 20 LTS via Tsinghua Mirror
The official remote install script (claude.ai/install.sh) frequently returns region-unavailable errors for domestic networks, so we perform manual offline binary deployment:
Valid output versions: v20.15.0 for Node, 10.7.0 for npm.
1.2 Configure Domestic npm Registry Mirror
Speed up subsequent package installation by switching npm to a domestic mirror source:
2. Global Installation of Claude Code CLI
Execute the global npm install command to pull the official Claude Code package:
Post-Install Validation
Run two verification commands to confirm the CLI binary is registered to system PATH:
Critical Note: The official curl one-click installation script is omitted here due to consistent regional access failures; npm global installation is confirmed as the reliable alternative for restricted network environments.
3. DeepSeek API Integration & Auto Bootstrap Script
DeepSeek exposes an Anthropic-compatible API path, allowing Claude Code to send all native request schemas to DeepSeek’s model backend without payload rewriting. We build a self-contained startup script to automate environment injection, persistent config writing, and connectivity health checks.
3.1 Retrieve DeepSeek API Key
- Visit the official DeepSeek developer platform:
platform.deepseek.com - Complete account sign-up and login, navigate to the API Keys management page
- Generate a new secret key (format starts with
sk-), store securely — the full key string only displays once on creation.
3.2 Create One-Click Bootstrap Script
Create a file named start-claude-deepseek.sh with the full automation logic below:
3.3 Inject Your Personal DeepSeek API Key
Open the script file with nano editor to replace the placeholder secret key value:
Locate the line DEEPSEEK_KEY="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" and overwrite the placeholder with your real API key, save and exit with Ctrl+O then Ctrl+X.
3.4 Execute Bootstrap Script
Grant execute permission and run the automation workflow:
The script will automatically complete environment injection, persistent config writing, API health validation, and launch the interactive Claude Code terminal session on first run. Subsequent usage only requires re-running the bash script command.
4. Daily Operation & Core CLI Commands
4.1 Standard Interactive Startup (Recommended)
Navigate to your project working directory and launch the bootstrap script:
4.2 Unattended Auto-Edit Mode (Non-root User Only)
For fully autonomous file modification without manual confirmation prompts, use the permission skip flag (security warning: only run inside trusted project directories):
4.3 Built-In Internal Shell Commands
After entering the Claude Code interactive shell, these built-in slash commands simplify debugging and project management:
| Command | Function Description |
|---|---|
/status | Print loaded model, environment variables, and API connection status |
/auto-accept | Auto-approve all file edit & shell execution requests (ideal for trusted rootless dev users) |
/init | Scan full project directory and generate CLAUDE.md structural context file |
/clear | Erase current dialogue history to reset context window |
/cost | Show real-time token consumption metrics for the active session |
5. Special Root User Security Handling
Claude Code enforces security restrictions that block --dangerously-skip-permissions when operating under the root superuser account. Three compliant workarounds are provided:
Option A: Create Dedicated Non-Root Developer User (Best Practice)
Option B: Manually run /auto-accept inside root shell
Launch standard claude without skip flag, then input /auto-accept once inside the interactive terminal to enable automatic approval logic.
Option C: Fine-grained permission whitelist for root execution
6. Model & Environment Variable Reference Table
All critical environment variables injected by the bootstrap script, with official recommended values for DeepSeek integration:
| Env Variable | Explanation | Suggested Value |
|---|---|---|
| ANTHROPIC_BASE_URL | DeepSeek Anthropic-compatible API root endpoint | https://api.deepseek.com/anthropic (do not append /v1) |
| ANTHROPIC_MODEL | Primary inference model for core tasks | deepseek-v4-pro[1m] |
| ANTHROPIC_DEFAULT_OPUS_MODEL | High-complexity task fallback model | deepseek-v4-pro[1m] |
| ANTHROPIC_DEFAULT_SONNET_MODEL | Medium-difficulty reasoning model | deepseek-v4-pro[1m] |
| ANTHROPIC_DEFAULT_HAIKU_MODEL | Lightweight fast-response auxiliary model | deepseek-v4-flash |
| CLAUDE_CODE_SUBAGENT_MODEL | Sub-agent lightweight worker model | deepseek-v4-flash |
| CLAUDE_CODE_EFFORT_LEVEL | Reasoning computation resource allocation | max |
The [1m] suffix enables the 1M ultra-long context window, strongly recommended for large repository code analysis workloads.
7. Common Failure Troubleshooting Matrix
| Failure Symptom | Root Cause | Resolution |
|---|---|---|
| Script syntax error during Node.js install | Official curl script blocked by regional network filters | Use manual npm mirror installation workflow from Section 1 |
glibc recv error (-110) | GitHub binary download throttling | Switch to Tsinghua Node.js mirror archive deployment |
--dangerously-skip-permissions cannot be used | Root user security hardening block | Create non-root dev user or use /auto-accept inside shell |
| Streaming API request failures | Intermittent network packet loss | Add env flag CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 |
| 401 Unauthorized API response | Incorrect or expired DeepSeek API Key | Re-generate secret key on DeepSeek platform and re-inject into script |
| 404 model not found error | Wrong model identifier string | Use deepseek-v4-pro[1m] instead of generic deepseek-chat |
8. Security Hardening Best Practices
- Restrict bootstrap script file permissions:
chmod 600 start-claude-deepseek.shto prevent other system users from reading embedded API credentials. - Never commit the unredacted startup script to public Git repositories; the plaintext API key poses data leakage and unexpected billing risks.
- Rotate DeepSeek API keys on a regular cycle via the developer platform to mitigate long-term credential exposure risks.
- Periodically execute
/costinside the Claude shell to monitor token consumption and avoid unplanned high-cost inference spikes.
9. Pre-Deployment Validation Checklist
Complete all verification items before formal production usage:
- Node.js 20 LTS installed and reachable via
node --version claude --versionreturns a valid CLI version number- DeepSeek API Key correctly filled within the bootstrap script
- Bootstrap script runs without syntax errors
- API connectivity test inside the script returns HTTP 200 status
- Environment variables persist after reloading
~/.bashrc - Running
/statusinside Claude shell displays DeepSeek model identifiers - Sending a simple prompt
hireturns valid text generation output
Conclusion
This deployment pipeline resolves the core regional access pain point of the official Claude Code install script by leveraging domestic npm mirrors and a fully self-contained bash automation script for DeepSeek API integration. The dual-layer configuration mechanism (bashrc global environment variables + local .claude/settings.json) ensures persistent model routing settings across terminal sessions, while built-in curl health checks eliminate blind API connection failures.
For enterprise teams managing multiple LLM backend endpoints including DeepSeek and Anthropic native services, centralized traffic routing via an API gateway such as 4sapi can standardize authentication headers and model fallback logic across all CLI agent workloads. The documented root-user security workarounds balance convenience with the official permission guardrails built into Claude Code, making this workflow suitable for both local developer workstations and remote Ubuntu cloud servers. All model identifiers, environment variables, and error mitigation logic are validated against live DeepSeek compatible API endpoints, eliminating trial-and-error configuration overhead for engineers migrating Claude Code away from native Anthropic models to domestic open-weight LLM backends.




