Claude Code on Windows: A Complete Guide to Using Third-Party APIs Without Login
Core Question of This Article: How can I bypass the official OAuth login process in Claude Code on a Windows system and connect directly via a third-party API proxy?
Claude Code, the CLI programming assistant developed by Anthropic, typically guides users through an OAuth-based browser login by default. However, under the hood, the tool is strictly API-driven. For developers who prefer using OpenRouter, OneAPI, LiteLLM, or their own self-hosted proxies, this official login can be bypassed entirely through environment variables. This guide provides a comprehensive, step-by-step walkthrough for configuring Claude Code on Windows, resolving terminal-specific errors, and automating your workflow.
The Mechanism of Decoupling: How Environment Variables Override Login
Core Question of This Section: How does Claude Code detect and prioritize third-party API configurations over official login states?
Claude Code is designed to prioritize system environment variables during its initialization phase. If the tool detects valid API parameters—specifically a base URL and an authentication token—it assumes an API-first configuration and skips the browser-based OAuth sequence. This decoupling allows you to use the tool in environments where browser access is restricted or where you wish to consolidate costs through a third-party provider.
Essential Configuration Parameters
To redirect Claude Code’s traffic, you must define the following variables within your Windows environment:
| Variable Name | Functional Description | Example Value |
|---|---|---|
ANTHROPIC_BASE_URL |
The entry point of your proxy API | https://api.yourproxy.com/v1 |
ANTHROPIC_AUTH_TOKEN |
Your third-party API Key/Secret | sk-xxxx... |
ANTHROPIC_MODEL |
The specific model ID required by the proxy | anthropic/claude-3-5-sonnet |
ANTHROPIC_API_KEY |
Used to clear official keys (Optional) | "" (Empty string) |
Author’s Reflection & Insight:
In my experience, the biggest hurdle for Windows developers isn’t the API itself, but the “stickiness” of the tool’s default state. Many users try to edit configuration files first, but environment variables are actually the “cleanest” way to handle this. They act as a high-priority override that doesn’t require you to dig into hidden application folders, making it easier to switch between different providers like OpenRouter or a local LLM instance.
Three Deployment Methods for Windows Users
Core Question of This Section: What are the best ways to persist these API settings across different Windows terminal environments?
Depending on whether you need a quick test or a permanent development setup, you can choose from three distinct methods to apply these settings.
Method 1: Temporary Session via PowerShell (Best for Testing)
If you only need to use a third-party API for a single session, you can set the variables directly in your active PowerShell window. These settings will disappear once the window is closed.
Execution Steps:
-
Open PowerShell. -
Run the following commands (replace placeholders with your actual data):
$env:ANTHROPIC_BASE_URL = "https://your-proxy-provider.com/v1"
$env:ANTHROPIC_AUTH_TOKEN = "sk-your-third-party-key"
$env:ANTHROPIC_MODEL = "anthropic/claude-3-5-sonnet-20241022"
-
Launch the tool by typing claude.
Method 2: Permanent System Environment Variables (Recommended)
For a “set it and forget it” experience, adding these to the Windows System Properties is the most reliable path. This ensures that any terminal (CMD, PowerShell, or the VS Code integrated terminal) can access the API.
Detailed Step-by-Step:
-
Press Win + R, typesysdm.cpl, and hit Enter. -
Navigate to the Advanced tab and click Environment Variables. -
Under the User variables section, click New for each of the following:
-
Variable: ANTHROPIC_BASE_URL| Value:https://your-proxy.com/v1 -
Variable: ANTHROPIC_AUTH_TOKEN| Value:your-api-key -
Variable: ANTHROPIC_MODEL| Value:model-id-string
-
Crucial Step: You must restart any open terminals for these changes to take effect. Windows does not “hot-load” system variables into existing processes.
Method 3: Editing the Local Settings File
Claude Code stores internal configurations in a hidden folder within your user directory.
-
Path: C:\Users\<YourUsername>\.claude\settings.json -
Implementation: You can manually inject an envobject into the JSON structure. Note that if you have never run the tool successfully, this folder might not exist yet.
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.openrouter.ai/api/v1",
"ANTHROPIC_AUTH_TOKEN": "sk-or-xxxx...",
"ANTHROPIC_MODEL": "anthropic/claude-3-5-sonnet"
}
}
Advanced Troubleshooting: Resolving Connection and Format Errors
Core Question of This Section: How do I interpret and fix specific Windows-based errors like SSL failures or JSON parsing issues?
Testing your API connection with curl.exe is a standard diagnostic step, but the Windows implementation of curl and PowerShell’s handling of quotes often lead to “false negative” errors.
1. Diagnosing curl: (3) URL rejected
This error usually indicates that the URL string is malformed or the environment variable is empty.
-
Interpretation: If you see this, the terminal cannot find a “host part.” -
The Fix: Double-check your variable assignment. In PowerShell, use the $($env:VARIABLE)syntax to ensure the string is expanded correctly before being passed to the executable. Also, ensure there isn’t a double slash in the path (e.g.,v1//messages).
2. Solving curl: (56) schannel: server closed abruptly
This is an SSL/TLS handshake error specific to the Windows Secure Channel (SChannel) layer.
-
Interpretation: Your computer tried to establish a secure connection, but the server (or your local proxy/VPN) cut it off. -
The Fix: This often happens due to conflicts with global proxy software like Clash or V2Ray. Try adding the -kflag to yourcurlcommand to bypass SSL certificate verification, or check if your proxy is intercepting traffic to that specific domain.
3. Fixing the “Invalid Character ‘m'” JSON Error
This is perhaps the most common trap for Windows developers. When you see invalid character 'm' looking for beginning of object key string, it means your JSON payload is broken.
-
The Logic: PowerShell often strips the double quotes from your JSON string before sending it. Instead of receiving "model", the server receivesmodel, which isn’t valid JSON. -
The Correct Test Command:
You must use backslashes to escape the internal quotes so that the server receives a valid JSON object:
curl.exe -X POST "$($env:ANTHROPIC_BASE_URL)/messages" `
-H "Authorization: Bearer $($env:ANTHROPIC_AUTH_TOKEN)" `
-H "Content-Type: application/json" `
-H "anthropic-version: 2023-06-01" `
-d "{\"model\": \"claude-3-5-sonnet-20241022\", \"max_tokens\": 10, \"messages\": [{\"role\": \"user\", \"content\": \"hi\"}]}"
Protocol Compatibility: The “Tool Use” Requirement
Core Question of This Section: Can any third-party API work with Claude Code, or are there specific protocol requirements?
Claude Code is not a simple chatbot; it is a sophisticated Agentic CLI. This means it doesn’t just send text; it calls “tools” to list files, read code, and execute terminal commands.
-
The Anthropic Protocol: Claude Code uses the /messagesendpoint with a specific schema fortools. -
The OpenAI Compatibility Trap: If your third-party provider only supports the standard OpenAI /v1/chat/completionsformat without a translation layer for Anthropic’s tool-calling schema, Claude Code will fail. -
Recommendation: Ensure your provider (like OpenRouter or a specific OneAPI channel) explicitly supports the Claude 3.5 Sonnet Tool Use protocol. Without this, the tool will hang during the initial project indexing phase.
[A clean, high-resolution image of a Windows 11 desktop with a terminal window open, showing successful API responses and organized code blocks.]
Image Source: Pexels
Scenario-Based Insights: Lessons Learned from Windows Deployments
Reflection / Lessons Learned:
One of the most important lessons I’ve learned while configuring these tools on Windows is the “Clean Slate” principle. If you have previously attempted an official login and failed, Claude Code might have cached partial credentials that interfere with your environment variables. Always start by clearing the$HOME\.claudedirectory if things don’t seem to sync. It feels like a “hard reset” for your CLI environment and solves 90% of mysterious “still asking for login” bugs.
Practical Summary: Launch Checklist and One-Page Setup
For developers who want to get up and running immediately, use this checklist to ensure all technical requirements are met.
Operational Checklist
-
[ ] Verify API Endpoint: Ensure your URL ends in /v1and does not include/messages. -
[ ] Format API Key: Remove any leading or trailing spaces from your sk-...key. -
[ ] Select Model: Match the model ID to your provider’s specific requirements (e.g., anthropic/claude-3.5-sonnet). -
[ ] Clear Cache: Run rm -Recurse -Force "$HOME\.claude"if you have prior login attempts. -
[ ] Test Connectivity: Run the escaped curlcommand to verify the proxy is responding.
One-Page Launch Script (start-claude.ps1)
Copy this into a text file, save it as start-claude.ps1, and run it to automate your environment setup.
# --- Configuration Section ---
$env:ANTHROPIC_BASE_URL = "https://your-api-proxy.com/v1"
$env:ANTHROPIC_AUTH_TOKEN = "sk-your-third-party-key"
$env:ANTHROPIC_MODEL = "claude-3-5-sonnet-20241022"
# --- Initialization ---
Write-Host "Initializing Claude Code with Third-Party API..." -ForegroundColor Cyan
Write-Host "Target URL: $env:ANTHROPIC_BASE_URL" -ForegroundColor Gray
# --- Execute ---
claude
Searchable FAQ (Frequently Asked Questions)
Q: Why does Claude Code still open my browser even after I set the variables?
A: This usually means the variable names are misspelled or not properly exported to the global scope. Ensure you are using ANTHROPIC_BASE_URL (all caps) and that you have restarted your terminal after setting system-level variables.
Q: Can I use this with a local Ollama instance on Windows?
A: Yes, provided you use a model that supports tool calling (like Qwen2.5-Coder) and set your base URL to http://localhost:11434/v1. However, compatibility with the specific Anthropic tool schema may vary.
Q: My terminal says ‘claude’ is not a recognized command. What happened?
A: This is unrelated to the API. You need to install the Claude Code CLI via npm (npm install -g @anthropic-ai/claude-code) and ensure the npm global binaries folder is in your Windows PATH.
Q: Does using a third-party API limit the features of Claude Code?
A: Only if the proxy doesn’t support “Tool Use.” If the protocol translation is perfect, you will have full access to file editing, terminal execution, and project indexing features.
Q: How do I handle the ‘invalid character m’ error in a script?
A: Don’t worry about this error inside the claude tool itself. It only happens during manual curl tests because of how PowerShell parses quotes. Claude Code’s internal code handles JSON correctly.
Q: What should I do if my proxy requires a specific version header?
A: Claude Code sends the anthropic-version: 2023-06-01 header by default. Most proxies that support Claude will handle this automatically. If they don’t, you may need a more advanced proxy manager like LiteLLM to inject headers.

