Prerequisites
- Qwen CLI installed and authenticated
- Node.js v18+ installed
Step 1: Install Claude, Claude Code Router and Qwen Code
npm install -g @qwen-code/qwen-code@latest
npm install -g @anthropic-ai/claude-code @musistudio/claude-code-router
Step 2: Extract Your Access Token
Replace LINUX_USER with your Linux username.
Open /home/LINUX_USER/.qwen/oauth_creds.json
It should look something like this:
{
"access_token": "YOUR_QWEN_ACCESS_TOKEN_HERE",
"token_type": "Bearer",
"refresh_token": "YOUR_QWEN_REFRESH_TOKEN_HERE",
"resource_url": "portal.qwen.ai",
"expiry_date": 1764876220290
}
Copy the access_token value.
Step 3: Create router config
cat > ~/.claude-code-router/config.json << 'EOF'
{
"LOG": true,
"LOG_LEVEL": "info",
"HOST": "127.0.0.1",
"PORT": 3456,
"API_TIMEOUT_MS": 600000,
"Providers": [
{
"name": "qwen",
"api_base_url": "https://portal.qwen.ai/v1/chat/completions",
"api_key": "$QWEN_ACCESS_TOKEN",
"models": [
"qwen3-coder-plus",
"qwen3-coder-plus",
"qwen3-coder-plus"
]
}
],
"Router": {
"default": "qwen,qwen3-coder-plus",
"background": "qwen,qwen3-coder-plus",
"think": "qwen,qwen3-coder-plus",
"longContext": "qwen,qwen3-coder-plus",
"longContextThreshold": 60000,
"webSearch": "qwen,qwen3-coder-plus"
}
}
EOF
Verify file was created
cat ~/.claude-code-router/config.json
Step 4: Set your Access Token
echo 'export QWEN_ACCESS_TOKEN="YOUR_QWEN_ACCESS_TOKEN_HERE"' >> ~/.zshrc
source ~/.zshrc
Step 5: Verify Setup
claude --version # Should show: Claude Code v2.x.x
ccr version # Should show version number
echo $QWEN_ACCESS_TOKEN # Should show your token
Step 6: Start Using
Restart the router server:
ccr restart
Run Claude Code with Qwen models:
ccr code
Test with:
> hi
Token Refresh (When you get 401 errors)
Your OAuth token expires. Refresh it by:
- Re-authenticating your QWEN CODE CLI: If already logged in and the access_token matches in both
config.jsonandoauth_creds.json, delete theoauth_creds.jsonfile and runqwento initiate re-authentication. - Update the api_key in your config.json with the new access_token:
nano ~/.claude-code-router/config.json - Restart:
ccr restart
Hopefully this will help you learn Claude Code for Free 💖
Top comments (0)