Back to Blog

Claude Code + DeepSeek on Rocky Linux Setup

Tutorials and Guides8118
Claude Code + DeepSeek on Rocky Linux Setup

Abstract

This hands-on guide covers end-to-end installation, local routing configuration, validation, and troubleshooting for pairing Claude Code with DeepSeek API on Rocky Linux 8 / 9 (and compatible RHEL distributions). The core routing utility ccswitch creates a local proxy gateway on port 15721 to translate Claude Code’s native Anthropic protocol requests for DeepSeek’s OpenAI-compatible endpoint. Every shell command, configuration snippet, and failure resolution workflow has been verified on live Rocky Linux 9 environments. Teams managing multi-model local and cloud API traffic can streamline unified endpoint management via an API gateway platform like 4sapi.

1. Architecture Overview & Core Component Breakdown

1.1 End-to-End Request Flow

The local routing layer built with ccswitch acts as a translation bridge between Claude Code’s Anthropic-native request format and DeepSeek’s API service. The full request pipeline follows this fixed sequence:

Claude Code CLI → Local ccswitch Proxy (127.0.0.1:15721) → DeepSeek Remote API Endpoint

All traffic is routed through the local port 15721; the proxy handles protocol conversion, credential injection, and error forwarding to eliminate native compatibility gaps between the two tools.

1.2 Core Component Roles

ComponentCore Function
Claude CodeTerminal-native AI coding assistant, natively built for Anthropic API protocol
ccswitchLocal routing & model provider management tool, hosts the port 15721 proxy service
DeepSeek APIRemote backend reasoning service exposing Anthropic-compatible endpoint for third-party integration

2. Prerequisite Environment Checks

2.1 System Hard Requirements

2.2 Mandatory Account & Credentials

  1. Active registered DeepSeek platform account
  2. Valid DeepSeek API Key, formatted with the standard sk- prefix

2.3 Base Software Dependencies

Node.js runtime is required for Claude Code installation via npm. Run this dnf command to install the dependency stack:

bash
sudo dnf install -y nodejs

Verify successful installation with two validation commands:

bash
node --version
npm --version

A valid deployment will return v16 or newer major Node.js release versions.

3. Step-by-Step Installation Workflow

3.1 Install Claude Code (Two Valid Methods)

Method 1: Recommended Global NPM Install
bash
sudo npm install -g @anthropic-ai/claude-code@2.1.179
Method 2: Official Remote Shell Install Script
bash
curl -fsSL https://claude.ai/install.sh | bash
Post-Install Validation

Run the version check command to confirm deployment success:

bash
claude --version

A correct install outputs version 2.1.179.

3.2 Deploy ccswitch Local Proxy Binary

Download the Linux x86_64 AppImage release directly from the official GitHub repository, apply executable permissions, and launch the binary:

bash
# Pull latest release binary
wget https://github.com/ccswitch/ccswitch/releases/latest/download/ccswitch-linux-x64.AppImage
# Grant execution permission
chmod +x ccswitch-linux-x64.AppImage
# Launch local routing service
./ccswitch-linux-x64.AppImage

3.3 Persist DeepSeek API Key as System Environment Variable

Inject the API key into the user’s bash runtime configuration file for permanent persistence across terminal sessions:

bash
# Append key to bashrc
echo 'export ANTHROPIC_API_KEY="YOUR_DeepSeek_API_Key"' >> ~/.bashrc
# Reload environment config without reboot
source ~/.bashrc
# Validate variable load
echo $ANTHROPIC_API_KEY | head -c 10

The truncated output confirms the credential variable loads correctly on shell startup.

4. Critical Core Routing & Client Configuration

4.1 Start & Configure ccswitch Local Proxy Service

  1. Open the ccswitch graphical interface
  2. Navigate to the dedicated Route configuration tab
  3. Toggle the master routing enable switch to active
  4. Confirm status displays Running with bound port 15721
  5. Input DeepSeek remote API parameters into the routing panel:
    • Base URL: https://api.deepseek.com/anthropic
    • API Key: Your issued DeepSeek API credential string

4.2 Create Claude Code Provider Settings File

Create or edit the hidden user configuration file ~/.claude/settings.json to point Claude Code to the local proxy gateway. Reference this standardized JSON template:

json
{
  "model_providers": {
    "deepseek": {
      "name": "DeepSeek",
      "base_url": "http://127.0.0.1:15721/v1",
      "env_key": "ANTHROPIC_API_KEY",
      "requires_openai_auth": false
    }
  }
}

Key configuration rules:

4.3 Inject Mandatory Global Environment Variables

Append three required routing variables to ~/.bashrc to force Claude Code to use the local proxy instead of Anthropic’s official cloud endpoints:

bash
cat >> ~/.bashrc << 'EOF'
export ANTHROPIC_AUTH_TOKEN="PROXY_MANAGED"
export ANTHROPIC_BASE_URL="http://127.0.0.1:15721/v1"
export ANTHROPIC_API_KEY="YOUR_DeepSeek_API_Key"
EOF
# Reload shell configuration
source ~/.bashrc

Critical note: The fixed value PROXY_MANAGED for ANTHROPIC_AUTH_TOKEN is mandatory. This flag disables native Anthropic account login and routes all traffic through the local translation proxy.

5. Multi-Stage Validation & Functional Testing

5.1 Health Check for Local ccswitch Proxy

Send a basic GET request to the proxy health endpoint to confirm the service is live and responsive:

bash
curl -v http://127.0.0.1:15721/health

A healthy service returns a 200 OK HTTP status code.

5.2 Verify Full Environment Variable Injection

List all prefixed Anthropic environment variables loaded into the active shell session:

bash
env | grep ANTHROPIC

The output must display all three configured variables: ANTHROPIC_AUTH_TOKEN, ANTHROPIC_BASE_URL, ANTHROPIC_API_KEY.

5.3 End-to-End API Request Test

Execute a raw POST request through the local proxy to validate full request forwarding to DeepSeek’s backend:

bash
curl -X POST http://127.0.0.1:15721/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
  "model": "deepseek-chat",
  "max_tokens": 20,
  "messages": [{"role": "user", "content": "Hello"}]
}'

A successful test returns a valid chat completion payload generated by DeepSeek’s model.

5.4 Launch Claude Code CLI & Confirm Integration

Start the Claude Code terminal client with the simple launch command:

bash
claude
Successful Integration Signals
  1. The CLI header displays the active deepseek model provider
  2. Interface text confirms Using deepseek (from .claude/settings.json)
  3. Basic chat prompts return coherent responses generated by DeepSeek’s remote model

6. Common Failure Modes & Step-by-Step Troubleshooting

Issue 1: Connection Refused Error

Root Cause: ccswitch proxy service is not running, or the base URL port address is misconfigured. Resolution Steps:

  1. Check active port listeners to confirm the proxy process binds 15721:
bash
netstat -tulpn | grep 15721
  1. Double-check the base_url value inside ~/.claude/settings.json is set to http://127.0.0.1:15721/v1

Issue 2: Not logged in · Please run /login Prompt

Root Cause: The mandatory ANTHROPIC_AUTH_TOKEN="PROXY_MANAGED" environment variable is missing or unset. Resolution: Re-inject the fixed proxy auth token variable and reload bashrc:

bash
export ANTHROPIC_AUTH_TOKEN="PROXY_MANAGED"
source ~/.bashrc

Issue 3: Model Not Found Error

Root Cause: The model name defined in settings.json does not match the official model identifiers exposed by DeepSeek’s API. Resolution: Pull the full list of supported model IDs from the local proxy endpoint:

bash
curl http://127.0.0.1:15721/v1/models \
-H "x-api-key: $ANTHROPIC_API_KEY"

Replace the model field value in the configuration file with one of the returned valid identifiers such as deepseek-chat.

Issue 4: Configuration File Fails to Load

Root Cause: Malformed JSON syntax inside settings.json, or an incorrect file path reference. Resolution: Validate JSON syntax with Python’s built-in json parser to locate formatting errors:

bash
python3 -c "import json; json.load(open('/root/.claude/settings.json'))"

Launch Claude Code with an explicit config path flag to test file loading:

bash
claude --config ~/.claude/settings.json

7. Production Optimization & Best Practices

7.1 Create Persistent Shell Alias

Simplify Claude Code launch by defining a permanent bash alias that auto-loads all required proxy environment variables:

bash
alias claude-deepseek='ANTHROPIC_AUTH_TOKEN="PROXY_MANAGED" ANTHROPIC_BASE_URL="http://127.0.0.1:15721/v1" ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" claude'

7.2 Full Standardized settings.json Template

This complete template includes multiple selectable DeepSeek model variants for flexible workload switching:

json
{
  "model_providers": {
    "deepseek": {
      "name": "DeepSeek",
      "base_url": "http://127.0.0.1:15721/v1",
      "env_key": "ANTHROPIC_API_KEY",
      "requires_openai_auth": false,
      "models": [
        {"id": "deepseek-chat", "name": "DeepSeek V3 Chat"},
        {"id": "deepseek-reasoner", "name": "DeepSeek Reasoner"}
      ]
    }
  }
}

7.3 Long-Term Performance Maintenance

  1. Explicitly specify target models at launch with claude --model deepseek-chat to skip manual provider selection
  2. Schedule regular updates for both Claude Code and ccswitch binaries to pull protocol compatibility patches
  3. Restart the ccswitch proxy service after every system reboot to preserve local routing availability

8. Core Deployment Summary

Four non-negotiable rules for stable production operation:

  1. The ccswitch local proxy must continuously run and bind port 127.0.0.1:15721
  2. Three environment variables are mandatory: ANTHROPIC_AUTH_TOKEN, ANTHROPIC_BASE_URL, ANTHROPIC_API_KEY
  3. The base_url entry in settings.json must always point to the local proxy gateway address
  4. All model name values must exactly match the identifiers returned by the proxy’s /v1/models endpoint

9. Reference Documentation

All commands and configuration workflows featured in this guide have been fully validated on a live Rocky Linux 9 production environment. For teams running multiple local and cloud LLM endpoints, centralized API management tools such as 4sapi can standardize credential handling and routing logic across all model providers.

Tags:Claude CodeDeepSeek APIRocky LinuxccswitchLLM Deployment

Recommended reading

Explore more frontier insights and industry know-how.