
Claude Code (CC) is brilliant revolutionary tool, but it’s a walled garden - it is locked to Anthropic’s API. You are forced to use Anthropic’s models, at Anthropic’s prices, with Anthropic’s context limits.
What if you want to use the massive 1M token context of Gemini 2.5 Pro? What if you want to run simple background tasks on a free, local model using Ollama? What if you need the specific reasoning style of DeepSeek? You shouldn't have to choose between a great coding assistant and your preferred AI infrastructure.
Claude Code is designed to be the ultimate terminal-based agent, but its native configuration is hardwired for Anthropic’s API. However, like most professional CLI tools, it respects specific environment variables that allow you to configure its "brain" to any Anthropic's listed endpoints. We leverage this configuration option to jail-break from its vendor lock-in.
The key to unlocking Claude Code lies in 2 primary environment variables:
- ANTHROPIC_BASE_URL: This tells the CLI where to send requests. By default, it's `https://api.anthropic.com`.
- ANTHROPIC_AUTH_TOKEN: This is the "passport" sent in the header. Even if you aren't using Anthropic, the CLI will send this value to your custom URL. Assign your API_KEY, if any to this only.
- ANTHROPIC_API_KEY: This is legacy and is now deprecated by Anthropic. Simply keep it empty, if your version of Claude Code asks for it.
You can now leverage this many options for LLMs like below:
- Use locally hosted LLM in Ollama, LMStudio, etc.
- Use AI Gateway hosted locally using Claude Code Router, Bitfrost, LiteLLM, etc.
- Use AI Gateway web platforms like Groq, Open-Router, Helicone etc.
Critical Troubleshooting
If you change the base_url and get errors, it is likely because the CLI is sending Anthropic-specific headers (like anthropic-beta) that your target provider doesn't understand. To fix this, ensure your gateway/proxy is "stripping" or "translating" these headers. If you are using CCR, this is handled automatically. If you are building your own, you must ensure your server ignores or maps the x-api-key and anthropic-version headers correctly.
The garden is only as high as the walls you choose to respect. Happy coding!
Disclaimer
In my experience, I find that using non-Anthropic models resulting in degraded performance for varied reasons like a model not supporting tool-calling format that Claude Code requires, etc. I'm cracking my way onto this and a blog post on this should be out sooner or later. Until then, have fun leveraging your chosen model for big difference in pricing costs, at the very least.