So you have heard people rave about Claude Code. Maybe you have also heard people mention OpenRouter in the same breath, usually followed by some combination of environment variables and a screenshot of a terminal. If you are new to any of this, it can feel like everyone skipped a step and jumped straight to the jargon.
This guide is that missing step. We will go slow where it matters, explain the confusing bits, and by the end you will actually understand what is happening instead of just copy pasting commands and hoping.
The two things, quickly
Claude Code is Anthropic's terminal coding agent. It reads your files, edits code, runs commands. By default it talks straight to Anthropic's servers.
OpenRouter is a switchboard. It a switchboard for AI models. Instead of every app needing its own separate connection to every AI provider, OpenRouter sits in the middle and lets you route requests to different models through one account, one dashboard, and one place to watch your spending. (Even free and open source models!)
You can check out all the models provided by OpenRouter here.
Important honesty check: OpenRouter's own docs say this combo is only guaranteed to work well with Anthropic's own models. You're not really swapping Claude's brain out here, you're mostly rerouting the pipe it talks through.
Quick vocab check: "OpenAI compatible"
Claude Code sends requests in Anthropic's format. Some servers only understand OpenAI's format instead. Point Claude Code at one of those by mistake and you get garbled errors, like mailing a French letter to someone who only reads Spanish.
OpenRouter has an endpoint that speaks Anthropic's format natively, so no translation step, no separate proxy needed.
Wait, do I use zsh or bash? How would I even know
This question stops more beginners than anything else in this guide, and it is a fair one. Here is how to check in ten seconds.
Open your terminal and type this, then press enter:
echo $SHELL
You will get one of these back:
- Something ending in
/zsh, like/bin/zsh, means you are using zsh. This is the default on modern Macs. - Something ending in
/bash, like/bin/bash, means you are using bash. This is common on older Macs, many Linux setups, and Windows Subsystem for Linux (WSL).
That is it. Whichever one shows up tells you which file to edit later:
- zsh users edit
~/.zshrc - bash users edit
~/.bashrc
Setup
1. Install Claude Code
curl -fsSL https://claude.ai/install.sh | bash
2. Grab an OpenRouter API key at openrouter.ai, and load some credits.
3. Add these to your shell file (the one you found above), then restart your terminal:
export OPENROUTER_API_KEY="your-openrouter-api-key"
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
export ANTHROPIC_API_KEY=""
The last line is deliberate, not a typo. An old value there can cause confusing auth errors. Also, put these lines near the end of the file, otherwise if OPENROUTER_API_KEY gets redefined later, the token silently goes empty.
Prefer keeping it per-project? Use a settings file instead:
{
"env": {
"ANTHROPIC_BASE_URL": "https://openrouter.ai/api",
"ANTHROPIC_AUTH_TOKEN": "<your-openrouter-api-key>",
"ANTHROPIC_API_KEY": ""
}
}
4. Clear any old login
/logout
Then fully restart Claude Code.
5. Launch it
cd /path/to/your/project
claude
6. Confirm it worked
/status
Should show ANTHROPIC_AUTH_TOKEN and the OpenRouter base URL. Check the activity dashboard too, it's oddly satisfying watching requests show up.
You're ready to roll. Claude Code with a lineup of models waiting for their turn!
Bottom line
Install Claude Code, get an OpenRouter key, set four env vars in the right file, /logout, relaunch, /status to confirm. Ten minutes, done. Stick to Claude models first, then go exploring once you know what "working" looks like.
Top comments (5)
This is quite an easy setup. Nice work.
For a tip just add the env in the .zshrc file and do source .zshrc, you won’t need to restart the terminal.
Secondly, Have you noticed any differences in tool calling or reliability when using OpenRouter instead of Anthropic directly with the same Claude model?
Thank you!
Yes editing that also works, was aiming to keep this one out for beginners.
There’s no significant difference in tool calling as such. However, OpenRouter may route requests through multiple providers for the same model, which can be configured in your account settings. I’ve noticed that this can sometimes increase cost and latency, though there is hardly any noticeable difference in performance.
The shell detection bit is the right kind of boring. Most setup guides fail at the boundary between copy-paste and the user's actual machine. I’d maybe add one explicit “echo the variable back” check after the config step, since a bad env write can look like an API/provider problem later.
Great tip!
That'll for sure keep things in check.
I'll keep a note of this for the upcoming blogs.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.