Claude Code Setup
Route Claude Code through lina-router to get automatic token savings, free model fallback, and multi-account rotation — without changing how you code.
Before you start
- lina-router installed and running (Quick Start)
- At least one provider connected in the dashboard
- Claude Code installed (
npm install -g @anthropic-ai/claude-code)
Method 1 — Environment Variable (Recommended)
Set two environment variables before launching Claude Code. This works in any shell and is the simplest approach.
macOS / Linux
export ANTHROPIC_BASE_URL=http://localhost:20128/v1
export ANTHROPIC_API_KEY=<your-lina-router-api-key>
claudeWindows (PowerShell)
$env:ANTHROPIC_BASE_URL = "http://localhost:20128/v1"
$env:ANTHROPIC_API_KEY = "<your-lina-router-api-key>"
claudeMethod 2 — Persistent Shell Config
Add the variables to your shell profile so they're always set when you open a terminal.
# Add to ~/.zshrc, ~/.bashrc, or ~/.profile
export ANTHROPIC_BASE_URL=http://localhost:20128/v1
export ANTHROPIC_API_KEY=<your-lina-router-api-key>
# Then reload:
source ~/.zshrcRTK Token Saver with Claude Code
Claude Code is one of the biggest beneficiaries of RTK because it generates large tool_result messages — the output of shell commands like git diff, grep, find, and file reads.
Without vs with RTK
Without RTK
tool_result: 4,200 tokens
(full git diff output
with context lines)
With RTK
tool_result: 2,580 tokens
(compressed, model
still understands it)
~38% saved per request, automatically
RTK is enabled by default. No extra config needed. See the RTK deep-dive →
Choosing a Model
When using lina-router, specify a model in the kr/ namespace for Kiro models, or use any provider's model format:
# Kiro AI (free)
ANTHROPIC_MODEL=kr/claude-sonnet-4.5
# Or pass --model flag to claude
claude --model kr/claude-sonnet-4.5Troubleshooting
Claude Code says 'connection refused'
lina-router is not running. Start it with: lina-router (in a separate terminal). It must stay running while you use Claude Code.
API key is invalid
Copy the key from the lina-router dashboard (Providers → your provider → API Key tab). Don't use your actual Anthropic API key here.
Responses are slower than usual
Free providers (Kiro, OpenCode) may be slower than paid APIs. If speed matters, connect a cheap API provider in Tier 2.
Claude Code is still hitting the real Anthropic API
Make sure ANTHROPIC_BASE_URL is set in the same shell session where you run claude. Check with: echo $ANTHROPIC_BASE_URL