Complete Windows configuration and reference guide for using Claude Code with OpenRouter, including the openrouter/free router.
This document covers:
- Claude Code installation on Windows
- OpenRouter API key configuration
- Anthropic-compatible OpenRouter endpoint configuration
openrouter/freemodel routing- Permanent PowerShell environment variables
- Session-level configuration
- Model configuration
- Connection verification
- Direct OpenRouter API testing
- Claude Code CLI commands
- Claude Code slash commands
- Gateway model discovery
- Debugging and common authentication errors
- Security recommendations
- Exact-model configuration
- A future universal gateway architecture
┌──────────────────────┐
│ Claude Code │
│ Windows CLI │
└──────────┬───────────┘
│
│ Anthropic-compatible API
▼
┌──────────────────────┐
│ OpenRouter │
│ API Endpoint │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ openrouter/free │
│ Free Model Router │
└──────────┬───────────┘
│
┌─────┼─────┐
▼ ▼ ▼
Free Free Free
Model Model Model
openrouter/freeis a routing identifier, not a single permanently fixed model. The selected upstream model can change based on OpenRouter's available free-model routing.
- Windows 10/11
- PowerShell
- Claude Code
- OpenRouter account
- OpenRouter API key
- Internet connection
Optional:
- Git
- An existing coding project
- A code editor
Open PowerShell and run:
irm https://claude.ai/install.ps1 | iexVerify the installation:
claude --versionStart Claude Code:
claudeCreate an API key in your OpenRouter account.
Use a new key for your own environment.
Never:
- Publish the API key
- Commit the API key to Git
- Put the key in a public repository
- Paste the key into screenshots or recordings
- Share the key with others
Use placeholders in documentation:
YOUR_OPENROUTER_API_KEY
The following configuration applies only to the current PowerShell session:
$env:OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY"
$env:ANTHROPIC_BASE_URL="https://openrouter.ai/api"
$env:ANTHROPIC_AUTH_TOKEN=$env:OPENROUTER_API_KEY
$env:ANTHROPIC_API_KEY=""Configure the model:
$env:ANTHROPIC_DEFAULT_SONNET_MODEL="openrouter/free"Optional model slots:
$env:ANTHROPIC_DEFAULT_OPUS_MODEL="openrouter/free"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL="openrouter/free"
$env:CLAUDE_CODE_SUBAGENT_MODEL="openrouter/free"Start Claude Code:
claudeTo persist the configuration for future PowerShell sessions, use Windows user-level environment variables.
setx OPENROUTER_API_KEY "YOUR_OPENROUTER_API_KEY"
setx ANTHROPIC_BASE_URL "https://openrouter.ai/api"
setx ANTHROPIC_AUTH_TOKEN "YOUR_OPENROUTER_API_KEY"
setx ANTHROPIC_DEFAULT_SONNET_MODEL "openrouter/free"
setx ANTHROPIC_DEFAULT_OPUS_MODEL "openrouter/free"
setx ANTHROPIC_DEFAULT_HAIKU_MODEL "openrouter/free"
setx CLAUDE_CODE_SUBAGENT_MODEL "openrouter/free"
setx CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY "1"setx changes future processes. It does not refresh the environment of the current PowerShell process.
Close PowerShell and open a new PowerShell window after running setx.
Verify:
$env:ANTHROPIC_BASE_URLExpected:
https://openrouter.ai/api
Check whether the API key exists without printing it:
if ($env:OPENROUTER_API_KEY) {
"OPENROUTER_API_KEY is configured"
} else {
"OPENROUTER_API_KEY is missing"
}Do not use:
$env:OPENROUTER_API_KEYin screenshots, screen recordings, logs, or public documentation.
If an old user-level ANTHROPIC_API_KEY is configured and you want to avoid credential conflicts:
[Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", $null, "User")Open a new PowerShell session afterward.
Check:
$env:ANTHROPIC_API_KEYA blank result is expected when the user-level variable has been removed and no higher-precedence source provides it.
Start Claude Code:
claudeInside Claude Code:
/status
Check that the active base URL points to:
https://openrouter.ai/api
You can also inspect the model selection:
/model
Inside Claude Code:
Hello
Then:
What model are you currently using?
Then, inside a project:
Explain this project's architecture without modifying any files.
A successful response confirms basic request routing.
A direct API test can help separate Claude Code configuration problems from OpenRouter API problems.
$body = @{
model = "openrouter/free"
max_tokens = 50
messages = @(
@{
role = "user"
content = "Say hello in one sentence."
}
)
} | ConvertTo-Json -Depth 10Invoke-RestMethod `
-Method Post `
-Uri "https://openrouter.ai/api/v1/messages" `
-Headers @{
"Authorization" = "Bearer $env:OPENROUTER_API_KEY"
"anthropic-version" = "2023-06-01"
"Content-Type" = "application/json"
} `
-Body $bodyKeep the API key in the environment rather than embedding it in the script.
Change to a project directory:
cd "C:\\Path\\To\\Your\\Project"Start Claude Code:
claudeA safe project-analysis request:
Analyze this project without modifying files.
Provide:
1. Framework
2. Runtime
3. Package manager
4. Main entry points
5. Important configuration files
6. Build command
7. Test command
A planning-first coding request:
Inspect this project and identify the cause of the current build issue.
Do not modify any files.
Explain:
1. Root cause
2. Affected files
3. Recommended fix
4. Verification steps
After reviewing the plan, a modification request can be made explicitly.
claudeclaude "fix this bug"claude -p "explain this code"claude -cclaude -rclaude --debugclaude --versionInside Claude Code:
/help
Show help.
/status
Show current status and configuration.
/model
Open model selection.
/clear
Clear the current conversation.
/login
Start authentication/login flow when applicable.
/logout
Sign out when applicable.
/exit
Exit Claude Code.
If the gateway supports Claude Code model discovery:
setx CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY "1"Open a new PowerShell session and start:
claudeThen:
/model
With a compatible gateway, discovered models can be shown in the model picker.
For troubleshooting discovery:
claude --debugSearch the debug output for:
[gatewayDiscovery]
Model discovery behavior depends on the gateway implementation and its compatibility with Claude Code.
openrouter/free
Use this when you want OpenRouter to select from eligible free models.
Use a specific OpenRouter model ID when deterministic model selection is required:
setx ANTHROPIC_DEFAULT_SONNET_MODEL "PROVIDER/MODEL-ID"Example format:
provider/model-name
Replace the example with the current model ID from OpenRouter.
- Predictable model selection
- Easier debugging
- Stable benchmarks
- Reproducible test results
- Automatic free-model routing
- Convenient experimentation
- No need to manually choose a single free model
Check that the key exists:
if ($env:OPENROUTER_API_KEY) {
"OpenRouter key is configured"
} else {
"OpenRouter key is missing"
}Check the base URL:
$env:ANTHROPIC_BASE_URLExpected:
https://openrouter.ai/api
Refresh the bearer credential:
$env:ANTHROPIC_AUTH_TOKEN=$env:OPENROUTER_API_KEYRestart Claude Code:
/exit
Then:
claudeSet:
$env:ANTHROPIC_BASE_URL="https://openrouter.ai/api"For permanent user configuration:
setx ANTHROPIC_BASE_URL "https://openrouter.ai/api"Restart PowerShell after using setx.
Check:
if ($env:OPENROUTER_API_KEY) {
"Configured"
} else {
"Missing"
}For a new PowerShell process, verify the permanent setting was loaded.
setx does not update the environment of the already-open PowerShell window.
Correct workflow:
1. Run setx
2. Close PowerShell
3. Open a new PowerShell
4. Verify $env:VARIABLE
Remove a conflicting user-level Anthropic API key:
[Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", $null, "User")Then start a new PowerShell session.
Do not place real API keys in:
- Git repositories
README.md- public Markdown files
- screenshots
- screen recordings
- public issue reports
- client-side application code
Example:
$env:OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY"If an API key has been exposed publicly, revoke or rotate it and replace it with a new key.
Avoid:
$env:OPENROUTER_API_KEYPrefer:
if ($env:OPENROUTER_API_KEY) {
"API key configured"
}Claude Code global configuration can also be maintained under the user's .claude directory.
Windows path:
%USERPROFILE%\.claude```
Example:
```powershell
New-Item -ItemType Directory -Force "$HOME\.claude"
Open the directory:
explorer "$HOME\.claude"Avoid putting reusable secrets into project-level configuration that can be committed to source control.
| Variable | Purpose | Example |
|---|---|---|
OPENROUTER_API_KEY |
OpenRouter credential | YOUR_OPENROUTER_API_KEY |
ANTHROPIC_BASE_URL |
Anthropic-compatible API base | https://openrouter.ai/api |
ANTHROPIC_AUTH_TOKEN |
Bearer authentication | YOUR_OPENROUTER_API_KEY |
ANTHROPIC_API_KEY |
Anthropic-style API-key credential | Leave unset when not needed |
ANTHROPIC_DEFAULT_SONNET_MODEL |
Default Sonnet slot | openrouter/free |
ANTHROPIC_DEFAULT_OPUS_MODEL |
Default Opus slot | openrouter/free |
ANTHROPIC_DEFAULT_HAIKU_MODEL |
Default Haiku slot | openrouter/free |
CLAUDE_CODE_SUBAGENT_MODEL |
Subagent model | openrouter/free |
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY |
Gateway model discovery | 1 |
For a simple Windows setup, the essential user-level variables are:
setx OPENROUTER_API_KEY "YOUR_OPENROUTER_API_KEY"
setx ANTHROPIC_BASE_URL "https://openrouter.ai/api"
setx ANTHROPIC_AUTH_TOKEN "YOUR_OPENROUTER_API_KEY"
setx ANTHROPIC_DEFAULT_SONNET_MODEL "openrouter/free"Then restart PowerShell:
claudeVerify:
/status
A more advanced architecture can place a local gateway between Claude Code and multiple providers:
Claude Code
│
▼
Anthropic-Compatible Endpoint
│
▼
┌─────────────────────┐
│ Universal LLM │
│ Gateway │
└─────────┬───────────┘
│
┌─────────────┼─────────────┐
▼ ▼ ▼
OpenRouter OpenAI Zen
│ │ │
└─────────────┼─────────────┘
▼
Provider Adapter
│
▼
LLM Model
Potential gateway responsibilities:
- Provider detection
- Provider registry
- Model discovery
- Protocol normalization
- Request translation
- Response normalization
- Streaming normalization
- Tool-call translation
- Reasoning normalization
- Retry handling
- Failover
- Health checks
- Rate-limit handling
- Logging and observability
- Secret management
[ ] Claude Code installed
[ ] `claude --version` works
[ ] OpenRouter API key created
[ ] API key stored securely
[ ] `ANTHROPIC_BASE_URL` points to OpenRouter
[ ] `ANTHROPIC_AUTH_TOKEN` is configured
[ ] Existing conflicting credential removed if necessary
[ ] `openrouter/free` configured
[ ] New PowerShell session opened after `setx`
[ ] `/status` checked
[ ] `/model` checked
[ ] Direct API request tested
[ ] Real project tested
[ ] API key not committed to Git
For a clean Windows setup:
irm https://claude.ai/install.ps1 | iexsetx OPENROUTER_API_KEY "YOUR_OPENROUTER_API_KEY"
setx ANTHROPIC_BASE_URL "https://openrouter.ai/api"
setx ANTHROPIC_AUTH_TOKEN "YOUR_OPENROUTER_API_KEY"
setx ANTHROPIC_DEFAULT_SONNET_MODEL "openrouter/free"Close PowerShell and open a new PowerShell window.
Verify:
$env:ANTHROPIC_BASE_URLThen:
claudeInside Claude Code:
/status
and:
/model
- Claude Code Quickstart: https://code.claude.com/docs/en/quickstart
- Claude Code Admin Setup: https://code.claude.com/docs/en/admin-setup
- Claude Code LLM Gateway: https://code.claude.com/docs/en/llm-gateway-connect
- OpenRouter Models: https://openrouter.ai/models
- OpenRouter Free Models Router: https://openrouter.ai/openrouter/free