How to Use Claude Code with Qwen models for Free (Linux)
Source: Dev.to
Prerequisites
-
Qwen CLI installed and authenticated
-
Node.js v18+ installed
-
Install the Qwen Code CLI:
npm install -g @qwen-code/qwen-code@latest -
Install Claude Code and the router:
npm install -g @anthropic-ai/claude-code @musistudio/claude-code-router
Configuration
-
Replace
LINUX_USERwith your Linux username. -
Open the Qwen OAuth credentials file:
cat /home/LINUX_USER/.qwen/oauth_creds.jsonIt should look similar to:
{ "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_tokenvalue. -
Create the Claude Code Router configuration:
cat > ~/.claude-code-router/config.json > ~/.zshrc source ~/.zshrc
Verify Installation
claude --version # Should show: Claude Code v2.x.x
ccr version # Should show the version number
echo $QWEN_ACCESS_TOKEN # Should display your token
Run the Router
Restart the router server:
ccr restart
Use Claude Code with Qwen Models
Start Claude Code:
ccr code
Test the setup:
> hi
Refreshing an Expired OAuth Token
If your token expires:
-
Delete the existing OAuth credentials file to force re‑authentication:
rm /home/LINUX_USER/.qwen/oauth_creds.json qwen # Run the Qwen CLI to log in again -
Copy the new
access_tokenfrom the regeneratedoauth_creds.json. -
Update the
api_keyin~/.claude-code-router/config.jsonwith the new token (e.g., usingnanoor your preferred editor). -
Restart the router:
ccr restart
Hopefully this helps you get Claude Code running for free on Linux! 💖