Claude Code is Anthropic’s terminal-based AI coding assistant. It edits files, runs commands, plans projects, and debugs errors — entirely from your command line. It also requires a paid plan. Anthropic’s own documentation confirms that the free tier does not include Claude Code access — you need at least a $20/month Pro subscription to run it.
Here is what most tutorials skip: the Claude Code CLI is free to install. The subscription pays for the AI model it connects to, not the tool itself. By redirecting Claude Code to a different AI backend, you can run it without a subscription in 2026.
This guide covers 3 verified free methods — what each costs, what you trade off, and how to set it up in under 15 minutes.
How the Redirect Works
Claude Code sends every request to an AI model via API. By default, that is Anthropic’s API — the part that costs money. Three environment variables change that:
ANTHROPIC_API_KEY— authenticationANTHROPIC_BASE_URL— where to send requestsANTHROPIC_MODEL— which model to use
Set all three to point at a different provider, and Claude Code connects there instead. Anthropic officially supports this pattern — their Claude Code setup documentation lists Amazon Bedrock, Google Vertex AI, and Microsoft Foundry as supported integrations. Developers have extended the same approach to Ollama and OpenRouter.
At a Glance
| Method | Cost | Daily Limit | Hardware |
|---|---|---|---|
| Ollama (local) | Free forever | None | 16GB+ RAM |
| OpenRouter free tier | Free | ~50 requests/day | None |
| Google AI Studio | Free tier | Reduced post Dec 2025 | None |
Method 1: Ollama — Run Claude Code Free on Your Own Machine
Ollama runs open-source AI models locally. Claude Code connects to it instead of Anthropic’s servers — no API key, no monthly bill, no request limits, no data leaving your machine.
Hardware requirement: 16GB RAM minimum for a usable experience. 32GB+ unlocks larger models that handle multi-file tasks more reliably.
Setup
Step 1: Download and install Ollama (macOS, Windows, Linux).
Step 2: Pull a model. Open your terminal:
ollama pull llama3.3
Choose a model with a large context window — this lets it hold bigger codebases in working memory.
Step 3: Install Claude Code (requires Node.js 18+):
npm install -g @anthropic-ai/claude-code
Step 4: Add to your shell config (.zshrc on Mac/Linux, $PROFILE on Windows):
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_BASE_URL=http://localhost:11434
export ANTHROPIC_MODEL=llama3.3
Restart your terminal. Run claude from any project folder. If it can’t connect, run ollama serve first to start the local server.
Trade-off: Local models are less capable than Claude Sonnet on complex multi-file reasoning. For focused tasks — fixing a bug, writing a function, generating tests — the gap is workable. For large architectural refactors, paid models are noticeably stronger.
Method 2: OpenRouter Free Tier — Cloud Models, No Hardware Required
OpenRouter is an API gateway that routes requests to dozens of AI models. Their free tier gives approximately 50 requests/day through rotating free models — including DeepSeek R1, Qwen, and Llama variants. No credit card required.
This is the easiest setup of the three.
Setup
Step 1: Create a free account at openrouter.ai. Go to the API Keys section and generate a key (starts with sk-or-v1-).
Step 2: Install Claude Code if not already installed:
npm install -g @anthropic-ai/claude-code
Step 3: Add to your shell config:
export ANTHROPIC_BASE_URL=https://openrouter.ai/api
export ANTHROPIC_AUTH_TOKEN=sk-or-v1-your-key-here
export ANTHROPIC_API_KEY=
export ANTHROPIC_MODEL=meta-llama/llama-4-maverick:free
⚠️ Use
https://openrouter.ai/api— not/api/v1. Claude Code appends/v1/messagesautomatically. Using the wrong base URL is the most common setup mistake. LeaveANTHROPIC_API_KEYblank — an Anthropic key is not needed here and may cause routing conflicts.
Any model ID ending in :free on OpenRouter costs nothing. Browse current free models at openrouter.ai/models — the selection rotates over time.
Trade-off: 50 requests/day sounds like a lot. Claude Code makes multiple model calls per task, so you can exhaust the limit mid-session during complex work. Adding $10 in credits raises the limit to approximately 1,000 requests/day. If you are building n8n automation workflows that include a coding agent, this method integrates cleanly through standard API routing.
Method 3: Google AI Studio — Claude Code Free with Gemini
Google AI Studio provides free API access to Gemini models, including Gemini 2.5 Flash. You use the same three-variable redirect to connect Claude Code to a Gemini API key instead of an Anthropic subscription.
Note: Google reduced Gemini’s free tier limits by 50–80% in December 2025. Free access still works but handles less volume than it used to.
Setup
Step 1: Go to aistudio.google.com, sign in with a Google account, and generate a free API key.
Step 2: Add to your shell config:
export ANTHROPIC_API_KEY=your-gemini-api-key
export ANTHROPIC_BASE_URL=[Gemini endpoint — verify below]
export ANTHROPIC_MODEL=gemini-2.5-flash
⚠️ I am not certain of the exact base URL as of June 2026. Google’s API endpoints have changed before. Verify the current value in the Google AI Studio documentation before completing this step. The three-variable redirect pattern is confirmed to work — the specific endpoint URL is what needs checking.
Trade-off: Gemini’s API is not a 1:1 match with Anthropic’s format. Most coding tasks work normally. Some Claude Code features — particularly extended thinking — may behave differently or not at all.
Which Method Fits Your Situation?
Use Ollama if you want unlimited, private, offline access and have 16GB+ RAM. Zero cost forever, no rate limits.
Use OpenRouter if you want a cloud setup with no hardware overhead. Easiest configuration, practical for moderate daily use.
Use Google AI Studio if you want Gemini 2.5 Flash specifically. Confirm the current API endpoint from Google’s documentation before setup.
For most developers trying Claude Code for the first time, OpenRouter is the fastest path: one free account, one API key, three environment variables, working setup in your terminal today.
When you are ready to connect a free Claude Code setup to a larger automation pipeline, BULDRR AI’s free workflows library includes n8n templates built for AI coding agents.
Quick Recap
- The Claude Code CLI is free. The $20/month subscription covers the AI model connection, not the tool.
- Three environment variables redirect Claude Code to any compatible backend.
- Ollama: free forever, offline, needs 16GB+ RAM, no limits.
- OpenRouter: ~50 free requests/day via cloud, easiest setup, no hardware.
- Google AI Studio: Gemini free tier, reduced limits since December 2025, verify endpoint URL.
What Should You Do Next?
Start with OpenRouter. Go to openrouter.ai, create a free account, and generate an API key. Add the three environment variables to your shell config, restart your terminal, and run claude in any project folder. Under 10 minutes, no subscription, no credit card.
FAQ
Q: Will I get access to the real Claude model using these free methods? A: No. These methods replace Claude with Llama, DeepSeek, or Gemini. You get the Claude Code CLI interface, but a different AI processes requests. To use actual Claude Sonnet or Opus, you need Anthropic API credits or a paid subscription.
Q: Is redirecting Claude Code to a third-party backend against Anthropic’s terms? A: Anthropic officially documents third-party integrations in their Claude Code setup guide. Pointing the tool at Ollama or OpenRouter uses the same mechanism as Bedrock or Vertex AI — you are not accessing Anthropic’s API without paying. Verify current terms if compliance matters for your use case.
Q: Do all 3 methods work on Windows? A: Yes. Ollama has a Windows installer. For OpenRouter and Google AI Studio, set the environment variables in your PowerShell profile ($PROFILE) instead of .zshrc. The npm install and claude commands work on Windows without changes.
Q: How many free requests does OpenRouter give per day? A: Approximately 50 requests/day on free model variants. Claude Code can make multiple calls per task, so complex sessions can hit the limit. Adding $10 in credits raises this to approximately 1,000 requests/day.
Q: Will code quality match the paid Claude subscription? A: For focused single-function tasks, the gap is smaller than expected. For large multi-file refactors and complex reasoning, paid Claude models are noticeably stronger. Free methods are best for learning, experimentation, and moderate daily coding.
Q: Can I use these methods inside VS Code’s integrated terminal? A: Yes. Environment variables set in your shell config are picked up automatically by VS Code’s integrated terminal. Run claude from VS Code’s terminal the same way you would from a standalone terminal window.
