cd /news/developer-tools/using-claude-code-with-openrouter-vi… · home topics developer-tools article
[ARTICLE · art-43133] src=dev.to ↗ pub= topic=developer-tools verified=true sentiment=· neutral

Using Claude Code with OpenRouter via `claude-code-router` on Linux

A developer has created claude-code-router, a package that bridges Anthropic's Claude Code CLI with OpenRouter's API aggregator on Linux, enabling model selection flexibility and cost savings via prompt caching. The tool routes Claude Code requests through OpenRouter instead of Anthropic's direct API, supporting configuration via environment variables or JSON files. It leverages OpenRouter's automatic prompt caching to reduce API costs when working with large codebases.

read3 min views1 publishedJun 29, 2026

Claude Code is Anthropic's powerful command-line coding assistant that brings AI directly into your terminal, while OpenRouter is an API aggregator that provides access to multiple AI models through a unified interface. The claude-code-router

package bridges these two tools, allowing you to route Claude Code requests through OpenRouter instead of Anthropic's direct API.

This guide covers installation and configuration on Linux systems only.

Before beginning, ensure your system meets these requirements:

node --version

npm --version

git --version

If Node.js is not installed or outdated, install it using your distribution's package manager or NodeSource:

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs

sudo dnf install nodejs npm

sudo pacman -S nodejs npm

claude-code-router

The claude-code-router

package should be installed globally alongside Anthropic's official CLI tool.

npm install -g claude-code-router @anthropic-ai/claude-code

Create or edit your shell configuration file:

nano ~/.bashrc

nano ~/.zshrc

Add the following lines:

export OPENROUTER_API_KEY="your-openrouter-api-key-here"
export CLAUDE_CODE_ROUTER_MODEL="anthropic/claude-3.7-sonnet"

Apply the changes:

source ~/.bashrc

source ~/.zshrc

Alternatively, create a configuration file in your home directory:

mkdir -p ~/.claude-code-router
nano ~/.claude-code-router/config.json

Add your configuration (updated with the correct Claude 3.7 model string):

{
  "apiKey": "your-openrouter-api-key-here",
  "model": "anthropic/claude-3.7-sonnet",
  "baseUrl": "https://openrouter.ai/api/v1",
  "maxTokens": 8192,
  "temperature": 0.7
}

If you prefer using an environment file over a JSON config, ensure you lock down the file permissions so other users on the Linux system cannot read your API key:

touch ~/.claude-code-router/.env
chmod 600 ~/.claude-code-router/.env
nano ~/.claude-code-router/.env

Add the key inside the file:

OPENROUTER_API_KEY=sk-or-v1-your-actual-key-here

One of the primary benefits of routing Claude Code through OpenRouter is natively leveraging Prompt Caching to heavily optimize your API costs.

When working in large codebases, Claude Code sends significant contextual data (file structures, previous messages, and active file contents) with every single request. OpenRouter automatically supports Anthropic's prompt caching functionality:

No extra configuration is required in claude-code-router

to enable this feature—OpenRouter handles the upstream caching headers automatically when translating requests to Anthropic's backend.

Configure Claude Code to point to the local proxy, then initialize the router:

export ANTHROPIC_BASE_URL="http://localhost:8080"
ccr code

If you want to quickly switch models without editing config files manually:

ccr ui

Note: This command redirects to a local web UI to configure your preferred OpenRouter models.

Check OpenRouter's model list for the most current routing options and model strings.

The claude-code-router

package provides a seamless way to use Claude Code through OpenRouter on Linux, giving you absolute flexibility in model selection while drastically cutting costs via prompt caching. By following this guide, you now have a secure, system-integrated proxy bridging Claude Code with OpenRouter's API infrastructure.

For additional help, consult the package's documentation on npm or GitHub, and periodically check OpenRouter's documentation for API changes or new model additions.

── more in #developer-tools 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/using-claude-code-wi…] indexed:0 read:3min 2026-06-29 ·