Skip to content

Repository files navigation

Claude Code with Deepseek v3.1

Do you want to run Claude Code at a fraction of the price and nearly the same quality? Time to use Claude Code with Deepseek v3.1 using a devcontainer.

Bonus: use a ssh reverse tunnel to tunnel through your firewall.

Resources

Deepseek supports Antroptic API format.

Create Deepseek API Key

Go to API Keys and create a API Key.

Create a .env file

# Standard Anthropic setting
ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
# IMPORTANT: No quotes around the token!
ANTHROPIC_AUTH_TOKEN=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ANTHROPIC_MODEL="deepseek-chat"
ANTHROPIC_SMALL_FAST_MODEL="deepseek-chat"

# Further finetuning Anthropic
API_TIMEOUT_MS=600000
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1

# Optional: Set HTTPS proxy for Claude Code network traffic
HTTPS_PROXY=https://localhost:8080

# Alternatively, set HTTP proxy if HTTPS proxy is not available
HTTP_PROXY=http://localhost:8080

# Optional: Bypass proxy for certain hosts or IPs (space or comma separated)
NO_PROXY="example.com,test.example.com"

Install directly in existing project

curl -s https://raw.githubusercontent.com/spacemonkeyrocks/test-claude-code-devcontainer-deepseek-v3.1/main/install.sh | bash

Use with the Anthropic Python SDK

Lets setup with uv to test the Anthropic format lets using the Anthropic Python SDK. Also usefull for testing if the API Key is working.

# Initialize uv
uv init

# Create venv
uv venv .venv

# Activate venv
source .venv/bin/activate

# Add dependencies from requirements.txt
uv add -r requirements.txt

# Install dependencies
uv sync

# Run the script inside the venv
uv run python3 test-deepseek.py

Use DeepSeek in Claude Code

Now we know the API Key is working with the Anthropic Python SDK it is time to test Deepseek v3.1 with Claude Code.

Step 1: Load .env file

Add the following to ./.devcontainer/devcontainer.json:

{
    ...
    "runArgs": ["--env-file", ".env"],
    ...
}

Step 2: Whitelist api.deepseek.com

Update the following section in ./.devcontain/init-firewall.sh and whitelist both openrouter.ai and api.deepseek.com:

...
# Resolve and add other allowed domains
for domain in \
    "openrouter.ai" \
    "api.deepseek.com" \
    "registry.npmjs.org" \
    "api.anthropic.com" \
    "sentry.io" \
    "statsig.anthropic.com" \
    "statsig.com" \
    "marketplace.visualstudio.com" \
    "vscode.blob.core.windows.net" \
    "update.code.visualstudio.com"; do
    echo "Resolving $domain..."
...

Step 3: Rebuild the container

Rebuild the container (Shift+Ctrl+P and select Dev Container: Rebuild Container).

Step 4: Test it

Ones that has completed, start a terminal (Ctrl+Shift+`)

Execute the following as a bash command (!):

curl ${ANTHROPIC_BASE_URL}/v1/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${ANTHROPIC_AUTH_TOKEN}" \
  -d '{
    "model": "deepseek-chat",
    "messages": [
      {
        "role": "user",
        "content": "Hello!"
      }
    ],
    "max_tokens": 1024,
    "temperature": 0.7,
    "stream": false
  }'

Execute the following as a bash command (!):

curl -X POST ${ANTHROPIC_BASE_URL}/v1/messages \
-H "Authorization: Bearer ${ANTHROPIC_AUTH_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
  "model": "deepseek-chat",
  "max_tokens": 1000,
  "system": "You are a helpful assistant.",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Hi, how are you?"
        }
      ]
    }
  ]
}'

If that worked then you are ready to start coding with Claude Code and Deepseek v3.1! Happy coding!

Bonus: Use Claude Code with ssh reverse tunnel

For those wanting to access Claude, Deepseek, etc. from behind a corporate firewall that blocks them, here is a tip to tunnel out. Use at your own risk!

Step 1: Install Socat

On most Linux distributions (Ubuntu/Debian), install socat using:

# Update and install
sudo apt update
sudo apt install socat

# Verify installation
socat -V

Step 2: Create SSH Reverse Tunnel

On your local machine (the one behind NAT/firewall), create a reverse tunnel to a remote server that will act as your proxy server.

ssh -R 9000:localhost:22 user@remote-server
  • This opens port 9000 on remote-server forwarding connections to your local SSH port 22.
  • Keep this session running.

Step 3: Use Socat on Remote Server

On the remote server, use socat to listen on a local port (e.g., 8080) and forward connections to the SSH reverse tunnel port 9000.

socat TCP-LISTEN:8080,reuseaddr,fork TCP:localhost:9000
  • This opens port 8080 on the remote server as a normal TCP proxy.
  • Any client connecting to remote-server:8080 will be forwarded to your local SSH service through the reverse tunnel.

Step 4: Use the Proxy

Now you can configure clients to use remote-server:8080 as a proxy.

# Set HTTPS proxy for Claude Code network traffic
export HTTPS_PROXY=https://localhost:8080

# Alternatively, set HTTP proxy if HTTPS proxy is not available
export HTTP_PROXY=http://localhost:8080

# Optional: Bypass proxy for certain hosts or IPs (space or comma separated)
export NO_PROXY="example.com,test.example.com"

Data goes through the socat forwarder → SSH reverse tunnel → your local machine.

Optional: Run Socat in Background

To keep socat running detached.

nohup socat TCP-LISTEN:8080,reuseaddr,fork TCP:localhost:9000 &

About

Do you want to run Claude Code at a fraction of the price and nearly the same quality? Time to use Claude Code with Deepseek v3.1 using a devcontainer.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages