How to Use Claude Code for Free: Complete Setup Guide (No Proxies)

How to Use Claude Code for Free: The Ultimate Step-by-Step Guide

 Claude Code is arguably the best-in-class AI coding agent on the planet right now; it can edit files, control your terminal, use MCP tools, and navigate through your entire project folder. But running it with Anthropic's top-tier models is incredibly expensive.

What if you could use the power of the Claude Code agent while saving a fortune in tokens?

In this guide, you will learn how to officially run Claude Code for free. There are no proxies needed or shady services; it all runs on your machine. I will explain the inner workings of this setup, limitations you will face, and the steps you need to run a free Claude Code agent today.

The Secret: The Car vs. The Engine

To understand this setup, you have to separate the agent and the model.

Think of Claude Code as a car; it provides the chassis, the steering, and the dashboard. It knows how to navigate through your codebase and use commands. The amazing engineering that is the Claude Code CLI is, in fact, free to install and use.


The thing that costs money is the engine, the LLM that processes your tokens (Claude 3.5 Sonnet or Opus). Anthropic allows you to change the engine; by using an API gateway known as OpenRouter you can point Claude Code to a free but powerful open-source model and replace the expensive proprietary Anthropic engine.

Free Models vs. Paid Models: The Honest Truth

Before diving into the setup, let's set realistic expectations. You will see claims online that free models are "exactly the same" as Claude Opus or Sonnet. While they look similar on benchmarks, real-world coding is different.

Here is the honest breakdown of what free models can and cannot do:

Where Free Models Shine (70-90% of daily tasks):

  • Writing scripts and single files

  • Generating boilerplate code and prototypes

  • Learning, experimenting, and scratch work

  • Explaining complex codebases

Where You Still Need Paid Models:

  • Massive refactors spanning 20+ files

  • Long, complex tool-call chains

  • Deep debugging sessions where time is money

  • Shipping production code under a tight deadline

The best workflow: Use free models for your day-to-day prototyping and learning, and switch to your paid API plan when you need heavy-lifting production power.

Step-by-Step: Setting Up Claude Code for Free

While the setup might seem daunting at first, it is actually quite straightforward. In this tutorial, we are using the Antigravity IDE because its built-in AI agent can automate the configuration, but you can also use VS Code or any standard terminal.

Step 1: Install Claude Code

First, open your terminal (in Antigravity, Cursor, or VS Code) and run the official installation command for your operating system. Once installed, restart your terminal and type claude to verify the installation. You will be prompted to log in—you can skip the standard Anthropic billing login for now.

Step 2: Get an OpenRouter API Key

We are going to use OpenRouter, a well-established and legitimate universal adapter for AI models. They host models from companies like DeepSeek, Meta (Llama), Google (Gemma), and Nvidia—many of which have zero input and output token costs.

  1. Create a free account at OpenRouter.

  2. Navigate to the Models section and filter by "Free" to see the available options (e.g., Google Gemma).

  3. Go to your API settings and generate a new API key. Keep this key handy.

Step 3: Configure Claude Code to use OpenRouter

Now we need to tell Claude Code to use OpenRouter instead of Anthropic's default servers.

If you are using Antigravity IDE, you can simply paste your OpenRouter API key and prompt the built-in Gemini agent:

"I want to use Claude Code with OpenRouter. Configure it to use the following free model: [Insert Model Name, e.g., Google Gemma] using this API key: [Your Key]."

The agent will automatically configure the environment for you.

(For manual setups in standard terminals, this process involves pointing the ANTHROPIC_BASE_URL to [https://openrouter.ai/api](https://openrouter.ai/api) and passing your OpenRouter key as the auth token.)

Step 4: The "Smart Fix" for Timeout Errors

Once configured, you might start chatting with your free model and suddenly hit this error:

hook timed out after 30 seconds, output discarded...

Why does this happen? Free models are incredibly popular. When a specific model experiences heavy global traffic, it rate-limits your requests, causing Claude Code to time out.

The Permanent Solution: Instead of manually swapping models every time there is traffic, you can use OpenRouter's Free Models Router. Prompt your IDE agent with:

"Update my configuration to use the OpenRouter auto free model router. It should automatically pick the best available free model and switch if one is rate-limited."

This setting acts as a load balancer. Whenever your primary free model is bogged down by traffic, OpenRouter instantly routes your request to the next available free model, ensuring uninterrupted coding.

Advanced Configuration: The .claude/settings.json Method

If you don't want to rely on an IDE agent to configure your terminal, you can set this up manually. Claude Code looks for environment variables to determine where to send its API requests.

To configure OpenRouter globally, you need to edit Claude Code's settings file.

For Mac/Linux: ~/.claude/settings.json For Windows: C:\Users\YourName\.claude\settings.json

Add the following JSON configuration to the file: {

  "env": {

    "ANTHROPIC_BASE_URL": "https://openrouter.ai/api",

    "ANTHROPIC_AUTH_TOKEN": "your-openrouter-api-key-here",

    "ANTHROPIC_API_KEY": "", 

    "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"

  }

}

⚠️ CRITICAL TIP: Notice that "ANTHROPIC_API_KEY" is left intentionally blank (""). OpenRouter authenticates via a Bearer token (which goes in ANTHROPIC_AUTH_TOKEN). If you leave an old Anthropic API key in the ANTHROPIC_API_KEY field, Claude Code will get confused, prioritize the Anthropic key, and throw authentication errors.

The Best Free Models for Coding in 2026

Not all free models are created equal. If you are using OpenRouter, here are the top-tier free models you should be targeting for software development:

  1. Llama 3.3 70B Instruct (Free): Currently one of the strongest open-weights models for writing new code and generating boilerplates.

  2. Qwen 2.5 Coder: Specifically trained on massive coding datasets. It consistently outperforms general-purpose models on code completion.

  3. DeepSeek R1 (Free tiers): Best for debugging. R1's "chain-of-thought" reasoning makes it excellent for figuring out why a specific function is failing.

Frequently Asked Questions (FAQ)

Is it legal and safe to route Claude Code through OpenRouter?

Yes. OpenRouter is a legitimate, well-established API gateway used by thousands of developers. However, keep privacy in mind. While Anthropic explicitly does not train on API data, you should check OpenRouter’s privacy settings. Ensure you opt-out of prompt logging in your OpenRouter dashboard if you are working on proprietary code.

Why is Claude Code suddenly ignoring my settings?

If Claude Code is ignoring your .claude/settings.json file, you likely have environment variables exported directly in your shell profile (like .zshrc or .bashrc). Shell environment variables take precedence over the JSON settings file. Check your terminal profile and remove any conflicting ANTHROPIC_ variables.

What are the limits on OpenRouter’s free models?

While the tokens are free, the server compute is not infinite. Free models on OpenRouter typically have rate limits of around 20 to 50 requests per minute, and roughly 200 requests per day per model.

How do I bypass the rate limits?

If you hit a rate limit (usually resulting in a hook timed out or 429 Too Many Requests error), the easiest workaround is to simply rotate your model. Since you are using a unified API gateway, switching from Gemma to Llama 3 takes three seconds and immediately resets your quota. Alternatively, use the OpenRouter Auto-Router (openrouter/auto) to handle this seamlessly.

Troubleshooting Common Errors

  • "Authentication failed" (401 Error): You either pasted the wrong OpenRouter API key, or you forgot to clear out your ANTHROPIC_API_KEY variable. Run /logout in Claude Code to clear cached Anthropic credentials, ensure the Anthropic key is blank, and restart your terminal.

  • "Model not found": You typed the model name incorrectly. OpenRouter requires specific model IDs (e.g., meta-llama/llama-3.3-70b-instruct:free). Check the exact ID string on OpenRouter's website.

  • Connection Refused / Timeout: The free model you selected is currently experiencing massive global traffic. Switch to a different free model or configure the Auto-Router.

  • Context Length Errors: Free models usually have smaller context windows than Claude 3.5 Sonnet or Opus. If you get this error, you are asking the agent to read too many files at once. Break your task down or start a fresh session using the /clear command.

Comments