Back to Blog

DeepSeek + Claude Code on Windows: Setup & Fixes

Tutorials and Guides3940
DeepSeek + Claude Code on Windows: Setup & Fixes

Abstract

This guide explains how to connect DeepSeek models to the official Claude Code CLI on Windows. It covers two integration approaches: direct access through DeepSeek’s Anthropic-compatible endpoint and indirect routing through the third-party ccswitch proxy.

The direct approach is generally easier to maintain because it removes the local proxy layer. The guide also explains why ccswitch may trigger ConnectionRefused errors, how Claude Code resolves overlapping configuration sources, and how to remove stale proxy settings.

All commands are written for Windows PowerShell. The article includes environment-variable configuration, settings.json cleanup, API connectivity tests, model mapping, and a structured troubleshooting checklist.

1. Integration Strategy

AI coding agents are increasingly used for repository analysis, code refactoring, unit-test generation, debugging, and multi-file development. As adoption grows, developers often want to use the Claude Code interface with models from other providers.

This guide focuses on Windows users who want to route Claude Code requests to DeepSeek V4 models, including:

There are two possible integration paths:

  1. Connect Claude Code directly to DeepSeek’s compatible API endpoint.
  2. Route requests through ccswitch or another local forwarding tool.

The first option is usually simpler. It removes the dependency on a local proxy process and reduces the number of components that can fail.

DeepSeek provides an Anthropic-compatible endpoint:

text
https://api.deepseek.com/anthropic

This endpoint is designed to accept requests using an Anthropic-style interface. Claude Code can therefore connect to it through environment variables, without requiring developers to rewrite request and response payloads.

The rest of this guide is divided into two parts. The first explains direct integration. The second focuses on diagnosing and removing ccswitch-related configuration conflicts.

2. Direct Integration with DeepSeek

2.1 Install the Required Software

Claude Code requires two main dependencies on Windows:

  1. Node.js 18 or a newer LTS release
  2. Git for Windows

Node.js provides the runtime for the Claude Code npm package. Git is required for repository operations and file-based development workflows.

After installing both dependencies, open PowerShell and run:

bash
npm install -g @anthropic-ai/claude-code

Verify the installation:

bash
claude --version

A valid version number confirms that the CLI is installed and available through the system PATH.

2.2 Configure the DeepSeek Endpoint

Claude Code reads Anthropic-compatible environment variables. These variables can override the default API endpoint, authentication token, and model selection.

For a temporary PowerShell session, use:

powershell
$env:ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
$env:ANTHROPIC_AUTH_TOKEN="REPLACE_WITH_YOUR_DEEPSEEK_API_KEY"
$env:ANTHROPIC_MODEL="deepseek-v4-pro[1m]"
$env:ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-v4-pro[1m]"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-v4-pro[1m]"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-v4-flash"
$env:CLAUDE_CODE_SUBAGENT_MODEL="deepseek-v4-flash"
$env:CLAUDE_CODE_EFFORT_LEVEL="max"

Each variable has a specific purpose:

These PowerShell variables apply only to the current terminal session. Closing the terminal removes them.

After configuration, open a local project directory and run:

bash
claude

Claude Code may display a workspace trust prompt during the first launch. Select the option that grants access only when you trust the current project directory.

Once the interactive interface opens, check the active model shown in the terminal. It should match:

text
deepseek-v4-pro[1m]

If another model or endpoint appears, a higher-priority configuration source may still be active.

3. Why ccswitch Can Cause ConnectionRefused

ccswitch acts as a local forwarding layer between Claude Code and an upstream model service. This approach can work, but it also introduces an additional process, local port, configuration file, and upstream route.

A failure in any of these components can interrupt the entire request path.

3.1 Local Proxy Settings Override the Direct Endpoint

ccswitch may write proxy values into the Claude Code user configuration file:

text
C:\Users\<CurrentUser>\.claude\settings.json

A typical proxy-managed configuration looks like this:

json
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "PROXY_MANAGED",
    "ANTHROPIC_BASE_URL": "http://127.0.0.1:15721"
  }
}

This configuration sends Claude Code requests to a local loopback address instead of DeepSeek.

The resulting path becomes:

text
Claude Code

127.0.0.1:15721

ccswitch

Upstream model endpoint

If ccswitch is not running, nothing listens on port 15721. Windows then rejects the connection immediately, producing a ConnectionRefused error.

The same problem can occur even after temporary environment variables are changed. Values stored in settings.json may continue to redirect traffic to the local proxy.

3.2 The Upstream Forwarding Chain May Also Fail

A running local proxy does not guarantee that requests will succeed.

The forwarding chain may still fail because of:

For example:

text
Claude Code

localhost:15721

ccswitch

api.anthropic.com

The local connection may succeed, but the upstream request can still fail. Troubleshooting then becomes more difficult because developers must inspect both the local proxy and the remote API connection.

Direct integration removes this extra layer:

text
Claude Code

api.deepseek.com/anthropic

4. Removing ccswitch Configuration

The following procedure removes stale local proxy settings and replaces them with a direct DeepSeek configuration.

Step 1: Back Up the Existing Configuration

Before rewriting settings.json, create a backup:

powershell
$settingsPath = "$env:USERPROFILE\.claude\settings.json"

if (Test-Path $settingsPath) {
    Copy-Item $settingsPath "$settingsPath.backup" -Force
}

This allows the previous configuration to be restored if needed.

Step 2: Rewrite settings.json

Create a clean configuration that points directly to DeepSeek:

powershell
$cleanConfig = @'
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "REPLACE_WITH_YOUR_DEEPSEEK_API_KEY",
    "ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic"
  }
}
'@

$cleanConfig | Set-Content `
    "$env:USERPROFILE\.claude\settings.json" `
    -Encoding UTF8

This removes the 127.0.0.1:15721 proxy target.

Avoid committing this file to a public repository because it contains an API credential. For better secret management, keep the token only in an environment variable and omit it from settings.json.

A safer minimal file is:

json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic"
  }
}

Step 3: Create Persistent User Variables

Temporary $env: assignments disappear when PowerShell closes. To preserve the configuration across terminal sessions, create user-level environment variables:

powershell
[Environment]::SetEnvironmentVariable(
    "ANTHROPIC_BASE_URL",
    "https://api.deepseek.com/anthropic",
    "User"
)

[Environment]::SetEnvironmentVariable(
    "ANTHROPIC_AUTH_TOKEN",
    "REPLACE_WITH_YOUR_DEEPSEEK_API_KEY",
    "User"
)

[Environment]::SetEnvironmentVariable(
    "ANTHROPIC_MODEL",
    "deepseek-v4-pro[1m]",
    "User"
)

[Environment]::SetEnvironmentVariable(
    "ANTHROPIC_DEFAULT_OPUS_MODEL",
    "deepseek-v4-pro[1m]",
    "User"
)

[Environment]::SetEnvironmentVariable(
    "ANTHROPIC_DEFAULT_SONNET_MODEL",
    "deepseek-v4-pro[1m]",
    "User"
)

[Environment]::SetEnvironmentVariable(
    "ANTHROPIC_DEFAULT_HAIKU_MODEL",
    "deepseek-v4-flash",
    "User"
)

[Environment]::SetEnvironmentVariable(
    "CLAUDE_CODE_SUBAGENT_MODEL",
    "deepseek-v4-flash",
    "User"
)

[Environment]::SetEnvironmentVariable(
    "CLAUDE_CODE_EFFORT_LEVEL",
    "max",
    "User"
)

The "User" scope applies the variables only to the current Windows account. It does not modify machine-wide settings.

Open a new PowerShell window after running these commands. Existing processes do not automatically reload updated user variables.

Step 4: Remove Conflicting Variables

Previous proxy tools may leave HTTP_PROXY, HTTPS_PROXY, or older Anthropic credentials in the user environment.

Remove them with:

powershell
[Environment]::SetEnvironmentVariable(
    "HTTPS_PROXY",
    $null,
    "User"
)

[Environment]::SetEnvironmentVariable(
    "HTTP_PROXY",
    $null,
    "User"
)

[Environment]::SetEnvironmentVariable(
    "ANTHROPIC_API_KEY",
    $null,
    "User"
)

Only remove proxy variables when they are not required by the rest of your development environment. Some corporate networks depend on them.

You can inspect the current PowerShell session with:

powershell
Get-ChildItem Env: |
    Where-Object {
        $_.Name -match "ANTHROPIC|CLAUDE|HTTP_PROXY|HTTPS_PROXY"
    }

Step 5: Stop Residual Processes

Terminate any existing Claude Code process:

powershell
Get-Process claude -ErrorAction SilentlyContinue |
    Stop-Process -Force

Check whether ccswitch is still running:

powershell
Get-Process ccswitch -ErrorAction SilentlyContinue

Stop it when you no longer intend to use the proxy:

powershell
Get-Process ccswitch -ErrorAction SilentlyContinue |
    Stop-Process -Force

Open a new PowerShell window and launch Claude Code again:

bash
claude

Confirm that the terminal now shows the intended DeepSeek model.

5. Validate the Configuration

Configuration should be tested at two levels:

  1. Verify that Claude Code is reading the intended settings.
  2. Verify that the remote endpoint accepts authenticated requests.

5.1 Inspect settings.json

Run:

powershell
Get-Content "$env:USERPROFILE\.claude\settings.json"

The file should not contain:

text
http://127.0.0.1:15721

It should point to:

text
https://api.deepseek.com/anthropic

5.2 Inspect Persistent Environment Variables

Read the user-level values directly:

powershell
[Environment]::GetEnvironmentVariable(
    "ANTHROPIC_BASE_URL",
    "User"
)

[Environment]::GetEnvironmentVariable(
    "ANTHROPIC_MODEL",
    "User"
)

To avoid exposing the complete token, check only whether it exists:

powershell
$token = [Environment]::GetEnvironmentVariable(
    "ANTHROPIC_AUTH_TOKEN",
    "User"
)

if ([string]::IsNullOrWhiteSpace($token)) {
    Write-Host "Token is missing"
} else {
    Write-Host "Token is configured"
}

5.3 Send a Test API Request

Use a small request to test authentication and connectivity:

powershell
$token = [Environment]::GetEnvironmentVariable(
    "ANTHROPIC_AUTH_TOKEN",
    "User"
)

$headers = @{
    "Authorization" = "Bearer $token"
    "Content-Type"  = "application/json"
}

$testPayload = @'
{
  "model": "deepseek-v4-pro",
  "max_tokens": 10,
  "messages": [
    {
      "role": "user",
      "content": "hi"
    }
  ]
}
'@

Invoke-WebRequest `
    -Uri "https://api.deepseek.com/anthropic/v1/messages" `
    -Method POST `
    -Headers $headers `
    -Body $testPayload

A successful response confirms that:

A failed response should be interpreted according to its type:

6. Troubleshooting Checklist

Use the following order to isolate failures efficiently:

StepCheckPowerShell command
1Inspect Claude Code configurationGet-Content "$env:USERPROFILE\.claude\settings.json"
2Search for the old local proxy addressSelect-String -Path "$env:USERPROFILE\.claude\settings.json" -Pattern "127.0.0.1"
3Check whether ccswitch is runningGet-Process ccswitch -ErrorAction SilentlyContinue
4Check for lingering Claude processesGet-Process claude -ErrorAction SilentlyContinue
5Inspect proxy variablesGet-ChildItem Env:HTTP_PROXY,Env:HTTPS_PROXY -ErrorAction SilentlyContinue
6Verify the configured base URL[Environment]::GetEnvironmentVariable("ANTHROPIC_BASE_URL","User")
7Confirm that the token exists[Environment]::GetEnvironmentVariable("ANTHROPIC_AUTH_TOKEN","User")
8Test the API independentlyRun the Invoke-WebRequest example above
9Open a new terminalRestart PowerShell to reload persistent variables
10Relaunch Claude CodeRun claude and inspect the active model

Do not print a real API token in screenshots, logs, forum posts, or issue reports.

7. Direct Integration vs. ccswitch

DimensionDirect DeepSeek Integrationccswitch Proxy Routing
Request pathClaude Code connects directly to DeepSeekRequests pass through a local proxy
Local dependencyNo background forwarding processccswitch must remain available
Configuration ownershipEndpoint and token remain under developer controlProxy may rewrite local configuration
Failure pointsPrimarily the remote API connectionLocal port, proxy process, credentials, and upstream endpoint
Model mappingPro and Flash mappings can be configured directlyCustom mappings may depend on proxy behavior
Long-context model namesPassed directly to the compatible endpointCustom suffixes may be modified by the proxy
MaintenanceLower operational overheadAdditional service monitoring is required
TroubleshootingEasier to isolateRequires inspection of both local and upstream layers

The direct approach is usually more suitable when the model provider already offers a compatible API endpoint. A proxy is more useful when protocol conversion, organization-wide routing, or centrally managed credentials are genuinely required.

Conclusion

Connecting DeepSeek to Claude Code on Windows mainly requires three elements:

  1. A compatible API base URL
  2. A valid authentication token
  3. Correct model-mapping variables

The most common ConnectionRefused issue is not caused by the remote model. It occurs when Claude Code is still configured to send traffic to a local ccswitch address such as 127.0.0.1:15721, while the proxy process is no longer listening.

The permanent fix is to remove stale localhost settings, clean conflicting proxy variables, create persistent DeepSeek environment variables, and restart the affected processes. Independent API testing should then be used to separate Claude Code configuration problems from endpoint or credential failures.

For teams that operate several LLM backends, a managed aggregation layer such as 4sapi can centralize endpoints, authentication, usage records, and model switching. For an individual DeepSeek-to-Claude Code setup, however, direct configuration remains the simpler architecture.

Tags:DeepSeekClaude CodeWindowsPowerShellccswitchAPI Integration

Recommended reading

Explore more frontier insights and industry know-how.