Beyond Anthropic: Using Claude Code with Any Model via Claude Code Router and OpenRouter

6 minute read

Claude Code Router

Ever hit that dreaded “Claude usage limit reached” message at 2 AM while debugging a critical issue? Or wished you could use Claude Code with GPT models for specific tasks? After experiencing these pain points firsthand, I discovered a game-changing setup: Claude Code Router paired with OpenRouter.

This isn’t just about having backup models—it’s about intelligently routing requests to the right model at the right time, whether that’s a free Qwen model for simple tasks, a local Ollama instance for privacy-sensitive work, or GPT when you need specific capabilities.

The Problem: Claude Code’s Single-Provider Limitation

Usage Limit Reached

While Claude Code is incredibly powerful, being locked to Anthropic’s models creates real friction:

  • Usage limits that reset at inconvenient times (6pm Madrid time for me)
  • No access to specialized models that might excel at specific tasks
  • Cost accumulation when you could use free alternatives for simpler queries
  • Privacy concerns for sensitive code that should stay local

Claude Code Router solves these issues elegantly by intercepting requests and routing them to any compatible model provider.

What is Claude Code Router?

Claude Code Router acts as an intelligent proxy between Claude Code and various LLM providers. Think of it as a smart switchboard operator that:

  • Intercepts Claude Code’s API requests
  • Routes them to different models based on your rules
  • Transforms requests/responses for API compatibility
  • Manages multiple providers transparently

The beauty? Claude Code doesn’t even know it’s happening. From its perspective, it’s still talking to Claude—but behind the scenes, you might be using a completely different model.

CLI Interface

OpenRouter: The Universal LLM Gateway

OpenRouter takes this flexibility even further. With access to 400+ models from 60+ providers through a single API, it’s like having a universal remote for AI models:

Free Models Worth Exploring

Free Models on OpenRouter

These models cost literally nothing and handle routine tasks surprisingly well:

  • Qwen3 Coder: Optimized for coding tasks, 262K context window
  • DeepSeek R1: Strong reasoning capabilities, especially for debugging
  • OpenAI gpt-oss-20b: Open-weight model with solid general performance

Premium Models When You Need Them

GPT Models on OpenRouter

Sometimes you need the heavy hitters. OpenRouter provides access to:

  • GPT models: Note that GPT-5 requires BYOK (Bring Your Own Key), while GPT-4o-mini is available with OpenRouter’s standard API
  • Google’s Gemini series
  • Anthropic’s Claude models (with potentially better availability)

Important: Always verify that your chosen model supports the features you need—see the Model Tool Support Considerations section below for details on tool/function calling limitations.

Self-Hosted with Ollama

Ollama Configuration

For maximum privacy and control, run models locally:

  • Complete privacy: Code never leaves your machine
  • No usage limits: Run as much as your hardware allows
  • Offline capability: Work without internet connectivity

Setting Everything Up

Step 1: Install Claude Code Router

npm install -g @musistudio/claude-code-router

Step 2: Get Your OpenRouter API Key

  1. Head to openrouter.ai
  2. Sign up (GitHub/Google auth available)
  3. Add some credits ($10 goes a long way with free models)
  4. Generate your API key

Step 3: Configure the Router

Create .claude-code-router/config.json:

{
  "LOG": true,
  "API_TIMEOUT_MS": 600000,
  "Providers": [
    {
      "name": "openrouter",
      "api_base_url": "https://openrouter.ai/api/v1/chat/completions",
      "api_key": "${OPENROUTER_API_KEY}",
      "models": ["qwen/qwen3-coder:free", "openai/gpt-oss-20b:free"]
    },
    {
      "name": "ollama",
      "api_base_url": "http://localhost:11434/v1/chat/completions",
      "api_key": "ollama",
      "models": ["qwen3:4b", "deepseek-coder:6.7b"]
    }
  ]
}

Notice the ${OPENROUTER_API_KEY} syntax—the router reads from environment variables for security.

Step 4: Launch and Use

Start the router:

ccr start

This launches the router on port 3456 by default. Claude Code will now route through it automatically when configured with the local endpoint.

Use Claude Code as normal:

ccr code "explain this function"

Step 5: Configure Claude Code to Use the Router

To make Claude Code route through your local router, you need to configure it to use the router’s endpoint. Open the web UI for visual configuration:

ccr ui

This opens the router’s web interface at http://localhost:3456 where you can:

  • Configure routing rules for different scenarios (Default, Background, Think, Long Context)
  • Assign specific models to each routing category
  • Monitor request logs to see which models are being used
  • Test different configurations before applying them

The web UI provides an intuitive way to set up intelligent routing without editing configuration files manually. You can assign cost-effective models for simple tasks and premium models for complex operations requiring tool support.

The Power of Intelligent Routing

Router UI Configuration

The real magic happens when you configure routing rules. The UI lets you assign different models to different scenarios:

  • Default: Your go-to model for general queries
  • Background: Efficient model for background processing
  • Think: Reasoning-optimized model for complex problems
  • Long Context: Model with large context windows for big codebases
  • Web Search: Model optimized for research tasks

This means a simple “format this JSON” request might go to a free Qwen model, while “architect a microservices solution” triggers GPT or Claude.

Model Tool Support Considerations

Model Endpoint Limitations

When setting up routing rules, it’s crucial to understand that Claude Code relies heavily on tools/function calling for many operations like file editing, git commands, and system interactions. Not all models support these capabilities:

  • Tool-capable models: Claude models, GPT-4o series, some Gemini models
  • Text-only models: Many free models (Qwen, DeepSeek, etc.) that can handle explanations and code generation but not tool execution
  • Best practice: Route tool-requiring tasks to confirmed tool-capable models, and use text-only models for explanations, code review, and documentation

As shown in the error logs above, you’ll encounter “No endpoints found that support” errors when trying to use advanced features with models that don’t support them. Always verify model capabilities before routing critical tasks.

Real-World Workflow

Here’s how I use this setup daily:

  1. Morning standup prep: Free Qwen models summarize yesterday’s commits
  2. Feature development: Claude (through normal subscription) for complex implementations
  3. Quick fixes: Local Ollama for private customer code
  4. After hours debugging: OpenRouter credits when I hit Claude limits
  5. Documentation writing: GPT models that excel at technical writing

The /model command lets me switch on the fly:

/model ollama,qwen3:4b       # Switch to local Ollama
/model openrouter,gpt-4o     # Use GPT through OpenRouter

Cost Optimization Tips

After a month of usage, here’s what I’ve learned:

  1. Start with free models: You’d be surprised how capable they are for routine tasks
  2. Use context thresholds: Route only complex queries to premium models
  3. Monitor the logs: The router logs help identify which queries actually need premium models
  4. Leverage Ollama: For repetitive local tasks, self-hosted is unbeatable

My typical monthly breakdown:

  • 70% free models (basic queries, formatting, simple debugging, code explanations)
  • 20% Ollama (private code, offline work, documentation generation)
  • 10% premium tool-capable models (complex architecture requiring file edits, git operations, system interactions)

Troubleshooting Common Issues

The router logs to ~/.claude-code-router.log by default, which helps diagnose issues:

  • Connection refused: Check if the router is running (ccr status)
  • Model not found: Verify the model name matches OpenRouter’s format
  • Timeout errors: Increase API_TIMEOUT_MS for slower models
  • API key issues: Ensure environment variables are set correctly

Beyond Basic Routing

Claude Code Router supports advanced features I’m still exploring:

  • Custom transformers: Modify requests/responses programmatically
  • JavaScript routing scripts: Complex logic for model selection
  • GitHub Actions integration: CI/CD with model routing
  • Multiple provider fallbacks: Automatic failover when providers are down

The Bottom Line

This setup transformed my Claude Code experience from frustrating (hitting limits) to liberating (infinite flexibility). Whether you’re looking to reduce costs, bypass limitations, or simply experiment with different models, Claude Code Router + OpenRouter provides the perfect solution.

Start simple—configure one free model as a fallback for when you hit limits. Once you experience the flexibility, you’ll naturally expand your routing rules to optimize for different scenarios.

The future of AI-assisted development isn’t about picking the “best” model—it’s about having the right model for each specific task. This setup gets you there today.


Have you tried routing Claude Code through alternative models? What’s your experience with free models for development tasks? Share your setups in the comments below.

Leave a Comment