{"slug": "claude-code-openrouter-the-setup-guide-that-actually-explains-things", "title": "Claude Code + OpenRouter: The Setup Guide That Actually Explains Things", "summary": "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.", "body_md": "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.\n\nThis 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.\n\n** 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.\n\n** 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!)\n\nYou can check out all the models provided by OpenRouter [here](https://openrouter.ai/models).\n\nImportant 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.\n\nClaude 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.\n\nOpenRouter has an endpoint that speaks Anthropic's format natively, so no translation step, no separate proxy needed.\n\nThis question stops more beginners than anything else in this guide, and it is a fair one. Here is how to check in ten seconds.\n\nOpen your terminal and type this, then press enter:\n\n```\necho $SHELL\n```\n\nYou will get one of these back:\n\n`/zsh`\n\n, like `/bin/zsh`\n\n, means you are using zsh. This is the default on modern Macs.`/bash`\n\n, like `/bin/bash`\n\n, 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:\n\n`~/.zshrc`\n\n`~/.bashrc`\n\n**1. Install Claude Code**\n\n```\ncurl -fsSL https://claude.ai/install.sh | bash\n```\n\n**2. Grab an OpenRouter API key** at [openrouter.ai](https://openrouter.ai/), and load some credits.\n\n**3. Add these to your shell file** (the one you found above), then restart your terminal:\n\n```\nexport OPENROUTER_API_KEY=\"your-openrouter-api-key\"\nexport ANTHROPIC_BASE_URL=\"https://openrouter.ai/api\"\nexport ANTHROPIC_AUTH_TOKEN=\"$OPENROUTER_API_KEY\"\nexport ANTHROPIC_API_KEY=\"\"\n```\n\nThe 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`\n\ngets redefined later, the token silently goes empty.\n\nPrefer keeping it per-project? Use a settings file instead:\n\n```\n{\n  \"env\": {\n    \"ANTHROPIC_BASE_URL\": \"https://openrouter.ai/api\",\n    \"ANTHROPIC_AUTH_TOKEN\": \"<your-openrouter-api-key>\",\n    \"ANTHROPIC_API_KEY\": \"\"\n  }\n}\n```\n\n**4. Clear any old login**\n\n```\n/logout\n```\n\nThen fully restart Claude Code.\n\n**5. Launch it**\n\n```\ncd /path/to/your/project\nclaude\n```\n\n**6. Confirm it worked**\n\n```\n/status\n```\n\nShould show `ANTHROPIC_AUTH_TOKEN`\n\nand the OpenRouter base URL. Check the [activity dashboard](https://openrouter.ai/activity) too, it's oddly satisfying watching requests show up.\n\nYou're ready to roll. Claude Code with a lineup of models waiting for their turn!\n\nInstall Claude Code, get an OpenRouter key, set four env vars in the right file, `/logout`\n\n, relaunch, `/status`\n\nto confirm. Ten minutes, done. Stick to Claude models first, then go exploring once you know what \"working\" looks like.", "url": "https://wpnews.pro/news/claude-code-openrouter-the-setup-guide-that-actually-explains-things", "canonical_source": "https://dev.to/shreshthgoyal/claude-code-openrouter-the-setup-guide-that-actually-explains-things-1d6o", "published_at": "2026-07-31 15:27:57+00:00", "updated_at": "2026-07-31 15:35:45.779433+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools", "large-language-models"], "entities": ["Anthropic", "Claude Code", "OpenRouter"], "alternates": {"html": "https://wpnews.pro/news/claude-code-openrouter-the-setup-guide-that-actually-explains-things", "markdown": "https://wpnews.pro/news/claude-code-openrouter-the-setup-guide-that-actually-explains-things.md", "text": "https://wpnews.pro/news/claude-code-openrouter-the-setup-guide-that-actually-explains-things.txt", "jsonld": "https://wpnews.pro/news/claude-code-openrouter-the-setup-guide-that-actually-explains-things.jsonld"}}