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:
deepseek-v4-pro[1m]for long-context and complex coding tasksdeepseek-v4-flashfor lightweight or background subagent tasks
There are two possible integration paths:
- Connect Claude Code directly to DeepSeek’s compatible API endpoint.
- 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:
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:
- Node.js 18 or a newer LTS release
- 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:
Verify the installation:
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:
Each variable has a specific purpose:
ANTHROPIC_BASE_URLreplaces the default Anthropic API address.ANTHROPIC_AUTH_TOKENprovides the DeepSeek API credential.ANTHROPIC_MODELdefines the primary model used by Claude Code.ANTHROPIC_DEFAULT_OPUS_MODELmaps the Opus tier to the DeepSeek Pro model.ANTHROPIC_DEFAULT_SONNET_MODELmaps the Sonnet tier to the same Pro model.ANTHROPIC_DEFAULT_HAIKU_MODELmaps lightweight requests to the Flash model.CLAUDE_CODE_SUBAGENT_MODELassigns the Flash model to subagent tasks.CLAUDE_CODE_EFFORT_LEVELrequests the highest available reasoning effort.
These PowerShell variables apply only to the current terminal session. Closing the terminal removes them.
After configuration, open a local project directory and run:
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:
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:
A typical proxy-managed configuration looks like this:
This configuration sends Claude Code requests to a local loopback address instead of DeepSeek.
The resulting path becomes:
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:
- An unreachable upstream endpoint
- Incorrect proxy configuration
- Invalid authentication credentials
- A placeholder token such as
PROXY_MANAGED - Unsupported model identifiers
- Residual HTTP or HTTPS proxy variables
- Custom model suffixes being modified or removed
For example:
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:
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:
This allows the previous configuration to be restored if needed.
Step 2: Rewrite settings.json
Create a clean configuration that points directly to DeepSeek:
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:
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:
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:
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:
Step 5: Stop Residual Processes
Terminate any existing Claude Code process:
Check whether ccswitch is still running:
Stop it when you no longer intend to use the proxy:
Open a new PowerShell window and launch Claude Code again:
Confirm that the terminal now shows the intended DeepSeek model.
5. Validate the Configuration
Configuration should be tested at two levels:
- Verify that Claude Code is reading the intended settings.
- Verify that the remote endpoint accepts authenticated requests.
5.1 Inspect settings.json
Run:
The file should not contain:
It should point to:
5.2 Inspect Persistent Environment Variables
Read the user-level values directly:
To avoid exposing the complete token, check only whether it exists:
5.3 Send a Test API Request
Use a small request to test authentication and connectivity:
A successful response confirms that:
- DNS resolution works.
- The endpoint is reachable.
- TLS negotiation succeeds.
- The token is accepted.
- The request format is valid.
A failed response should be interpreted according to its type:
ConnectionRefused: usually points to a local address or closed port.401 Unauthorized: usually indicates an invalid or missing token.404 Not Found: often indicates an incorrect endpoint path.400 Bad Request: usually indicates an unsupported model or invalid payload.- Timeout errors: commonly point to DNS, proxy, firewall, or network-routing problems.
6. Troubleshooting Checklist
Use the following order to isolate failures efficiently:
| Step | Check | PowerShell command |
|---|---|---|
| 1 | Inspect Claude Code configuration | Get-Content "$env:USERPROFILE\.claude\settings.json" |
| 2 | Search for the old local proxy address | Select-String -Path "$env:USERPROFILE\.claude\settings.json" -Pattern "127.0.0.1" |
| 3 | Check whether ccswitch is running | Get-Process ccswitch -ErrorAction SilentlyContinue |
| 4 | Check for lingering Claude processes | Get-Process claude -ErrorAction SilentlyContinue |
| 5 | Inspect proxy variables | Get-ChildItem Env:HTTP_PROXY,Env:HTTPS_PROXY -ErrorAction SilentlyContinue |
| 6 | Verify the configured base URL | [Environment]::GetEnvironmentVariable("ANTHROPIC_BASE_URL","User") |
| 7 | Confirm that the token exists | [Environment]::GetEnvironmentVariable("ANTHROPIC_AUTH_TOKEN","User") |
| 8 | Test the API independently | Run the Invoke-WebRequest example above |
| 9 | Open a new terminal | Restart PowerShell to reload persistent variables |
| 10 | Relaunch Claude Code | Run 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
| Dimension | Direct DeepSeek Integration | ccswitch Proxy Routing |
|---|---|---|
| Request path | Claude Code connects directly to DeepSeek | Requests pass through a local proxy |
| Local dependency | No background forwarding process | ccswitch must remain available |
| Configuration ownership | Endpoint and token remain under developer control | Proxy may rewrite local configuration |
| Failure points | Primarily the remote API connection | Local port, proxy process, credentials, and upstream endpoint |
| Model mapping | Pro and Flash mappings can be configured directly | Custom mappings may depend on proxy behavior |
| Long-context model names | Passed directly to the compatible endpoint | Custom suffixes may be modified by the proxy |
| Maintenance | Lower operational overhead | Additional service monitoring is required |
| Troubleshooting | Easier to isolate | Requires 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:
- A compatible API base URL
- A valid authentication token
- 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.




