Claude Code + OpenRouter: The Setup Guide That Actually Explains Things Anthropic's Claude Code terminal coding agent can be configured to route requests through OpenRouter, a model switchboard, by setting environment variables. The setup guide explains how to install Claude Code, obtain an OpenRouter API key, and configure shell files to enable the integration, with a note that OpenRouter's Anthropic-format endpoint ensures compatibility. 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. 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 https://openrouter.ai/models . 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. 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. 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: /zsh , like /bin/zsh , means you are using zsh. This is the default on modern Macs. /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: ~/.zshrc ~/.bashrc 1. Install Claude Code curl -fsSL https://claude.ai/install.sh | bash 2. Grab an OpenRouter API key at openrouter.ai https://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": "