How to Use Claude Code with Agent Router | Vishal Kushwaha
How to Use Claude Code with Agent Router
Introduction
Claude Code is Anthropic''s powerful AI coding assistant that helps developers write, debug, and understand code faster. Normally, you access Claude through Anthropic''s official subscription or Claude.ai platform.
Agent Router is a third-party API gateway that acts as an intermediary between your tools and AI models. It allows developers to route requests to various AI providers, including Claude, through a unified API interface.
In this guide, you''ll learn how to configure Claude Code to work with Agent Router, enabling you to:
- Access Claude models through an alternative API gateway
- Manage API credentials securely
- Understand the request flow from your IDE to Anthropic''s servers
- Troubleshoot configuration issues
- Follow security best practices
Prerequisites
Before starting, make sure you have:
✓ Claude Code installed on your system (Windows, macOS, or Linux)
✓ An active Agent Router account (free account available)
✓ A valid Agent Router API key generated and stored securely
✓ Terminal or command-line access on your machine
✓ Basic understanding of environment variables and how to set them
Step 1: Install Claude Code
Windows
1. Download the Claude Code installer from the official Anthropic website
2. Run the installer (.exe file)
3. Follow the installation wizard
4. Choose your installation directory (default: C:\Program Files\Claude Code)
5. Complete the setup
Verify installation by opening PowerShell and running:
```powershell
claude --version
```
macOS
Using Homebrew (recommended):
```bash
brew install anthropic/claude/claude-code
```
Or download directly from the Anthropic website and drag the application to your Applications folder.
Verify installation:
```bash
claude --version
```
Linux
Download the appropriate package for your distribution, or use your package manager:
```bash
For Ubuntu/Debian-based systems
sudo apt-get install claude-code
For Fedora/RHEL-based systems
sudo dnf install claude-code
```
Verify installation:
```bash
claude --version
```
Step 2: Create an Agent Router Account
Step-by-step signup process:
1. Visit Agent Router''s official website: https://agentrouter.org/
⚠️ Important Note: The website is currently in Chinese language. To view in English:
- Chrome: The browser will offer to translate. Click "Translate"
- Firefox: Right-click → "Translate Page to English"
- Any browser: Copy the URL to Google Translate at https://translate.google.com/
2. On the login page, you''ll see three authentication options:
Recommended: Continue with GitHub
- Click "Continue with GitHub" (easiest option)
- Authorize Agent Router to access your GitHub account
- You''ll be redirected to complete the setup
Alternative: Sign in with Email
- Click "Sign in with Email or Username"
- Enter your email address
3. Create a strong password (if using email option)
- Recommended: 12+ characters, mix of uppercase, lowercase, numbers, symbols
4. Verify your email address (if using email option)
- Check your inbox for verification link
- Click the link to confirm your email
5. Complete any additional verification steps
- May include phone verification or CAPTCHA
6. Log in to your Agent Router dashboard
- You should see a welcome screen with your account balance and credit information
7. Check your available credits
- You''ll see "Current balance" showing your available credits
- "Consumption" shows your usage so far
Important Note:
> Agent Router is a third-party service operated independently from Anthropic. Before using it with production workloads, review:
> - Pricing model and current rates
> - Privacy policy and data handling
> - Terms of service
> - Current model availability and limits
> - Any usage restrictions or fair-use policies
The interface and features may change, so always refer to Agent Router''s current documentation for the latest information.
Step 3: Generate an API Key
Once logged into Agent Router:
1. Navigate to API Token section in your dashboard (left sidebar)
- Usually found in Settings or Account menu
2. Click "Create New API Key" or "Generate Token"
3. Give your key a descriptive name (e.g., "Claude Code - VS Code" or "Development Machine")
- This helps you remember what each key is for
- Example names:
- "Claude Code - Development"
- "VS Code Integration"
- "Local Machine Setup"
4. Set appropriate permissions if available
- Select "Read" and "Write" or "Full Access" as needed
- More restrictive is better for security
5. Click "Generate" or "Create"
6. ⚠️ Copy the entire API key immediately — you won''t see it again
- Copy to clipboard
- Don''t close this window until you''ve saved it
7. Store it securely in a password manager or .env file (never in version control)
- Password managers: 1Password, LastPass, Bitwarden
- Keep it safe like your bank password
Example API Key format:
```
YOUR_AGENT_ROUTER_API_KEY
```
⚠️ Security Warning: Never use a real API key in public repositories, screenshots, or documentation.
Step 4: Configure Claude Code
Now you''ll set up Claude Code to use Agent Router''s endpoints instead of the default configuration.
Using Environment Variables
Create or edit your .env file in your project directory or system-wide:
Linux / macOS:
```bash
export ANTHROPIC_AUTH_TOKEN="YOUR_AGENT_ROUTER_API_KEY"
export ANTHROPIC_BASE_URL="YOUR_AGENT_ROUTER_BASE_URL"
export ANTHROPIC_MODEL="claude-3-5-sonnet"
```
Windows PowerShell:
```powershell
$env:ANTHROPIC_AUTH_TOKEN = "YOUR_AGENT_ROUTER_API_KEY"
$env:ANTHROPIC_BASE_URL = "YOUR_AGENT_ROUTER_BASE_URL"
$env:ANTHROPIC_MODEL = "claude-3-5-sonnet"
Verify
Get-Item env:ANTHROPIC_AUTH_TOKEN
```
What Each Variable Means
| Variable | Purpose |
|----------|----------|
| ANTHROPIC_AUTH_TOKEN | Your Agent Router API key |
| ANTHROPIC_BASE_URL | Agent Router API endpoint |
| ANTHROPIC_MODEL | Claude model identifier |
Step 5: Start Claude Code
```bash
claude
```
Claude Code should start with your Agent Router configuration loaded.
Security Best Practices
✓ Do:
- Store API keys in environment variables
- Use .env files (add to .gitignore)
- Rotate keys regularly if exposed
- Use different keys for different projects
- Keep keys secret like passwords
✗ Don''t:
- Paste API keys into GitHub
- Include keys in frontend code
- Share screenshots with visible keys
- Commit .env files to version control
- Use the same key for all projects
Setup .gitignore
```
.env
.env.local
.env.*.local
.env.development
.env.production
```
Conclusion
Configuring Claude Code with Agent Router gives you flexibility in accessing Claude models with proper security and credit tracking.
Remember:
- Agent Router is third-party—review their documentation and terms
- Protect your API credentials
- Monitor usage and costs
- Test thoroughly before production use