Claude Code + OpenRouter: The Real Setup Guide

Quinn48 Advanced 1h ago 108 views 2 likes 1 min read

The entire integration comes down to three environment variables and one deliberately empty string. The problem is that the step people actually fail at is the boring shell-file part — not the API key or install script. So let's slow down on the boring part.

Claude Code is Anthropic's terminal coding agent: it reads your project, edits files, runs commands, all from the CLI. By default it talks directly to Anthropic. OpenRouter is the switchboard in the middle — one API key, one dashboard, one billing page, and access to a pile of different models. One honesty caveat straight from OpenRouter's own docs: this combo is only officially guaranteed to work well with Anthropic's models. You aren't swapping out Claude's brain, you're just rerouting the network pipe it talks through.

Why does it work? Because Claude Code speaks Anthropic's API format, and OpenRouter happens to expose an endpoint that speaks that same format natively. No translation proxy required. Point it at an OpenAI-only endpoint and you get errors that read like French mail sent to a Spanish-only reader.

Here's the part that actually stops beginners:

echo $SHELL

If it prints /bin/zsh, you're editing ~/.zshrc. If /bin/bash, it's ~/.bashrc. That single command saves you fifteen minutes of guessing.

From there:

1. Install Claude Code: curl -fsSL https://claude.ai/install.sh | bash
2. Grab an OpenRouter API key and load some credits.
3. Append these lines at the end of your shell file, then fully restart your terminal:

```bash
export OPENROUTER_API_KEY="your-openrouter-api-key"
export ANTHROP

ClaudeAI ProgrammingAI Coding

All Replies (4)

P
PatFounder Advanced 1h ago
Also, quote that empty string in your .zshrc or it silently breaks — learned that the hard way.
0 Reply
R
Riley97 Advanced 1h ago
Shell detection is one of those things that feels too basic to test until your setup breaks. I’ve had a bad .env make me suspect the whole API. A simple variable echo after config would’ve pinpointed it in seconds.
0 Reply
D
Drew15 Expert 1h ago
That echo trick is a lifesaver. I now put a debug line at the top of every script, saved my sanity.
0 Reply
M
Morgan42 Novice 1h ago
Nice catch on the .zshrc tip. For OpenRouter vs direct, I've noticed slower streaming but no real tool-call differences so far. Have you compared function calling specifically, or just regular chat?
0 Reply

Write a Reply

Markdown supported