If you want to use Claude Code without paying for a Claude subscription or Anthropic API credits, there is a practical alternative: connect Claude Code to OpenRouter and use one of OpenRouter’s free AI models.

In this guide, I’ll show you exactly how to install Claude Code, create an OpenRouter API key, connect Claude Code to OpenRouter, configure a free model, verify the connection, and troubleshoot the most common problems.

Important: This setup does not give you free access to Anthropic’s Claude models. Instead, Claude Code acts as the coding-agent interface while OpenRouter provides the underlying model. OpenRouter has free models, but their availability, limits, and compatibility can change.

Table of Contents

What You’ll Learn

By the end of this tutorial, you’ll know how to:

  • Install Claude Code on Windows, macOS, or Linux
  • Create a free OpenRouter account
  • Generate an OpenRouter API key
  • Connect Claude Code to OpenRouter
  • Use OpenRouter’s free model router
  • Configure Claude Code environment variables
  • Check whether the connection is working
  • Change models
  • Avoid accidentally using paid models
  • Fix common authentication and model errors

What Is Claude Code?

Claude Code is Anthropic’s command-line coding agent. It can work directly inside your project directory, inspect files, edit code, run commands, and help with software-development tasks.

Unlike a normal chatbot, Claude Code is designed to work with an actual codebase.

For example, instead of copying a JavaScript file into a chat window and asking for help, you can open your project folder and ask Claude Code to:

Find the authentication bug and fix it. Run the tests afterward.

Claude Code can then inspect the project and work with the files and terminal.

The official Claude Code documentation is available here:

Claude Code Official Documentation

Can You Really Use Claude Code for Free?

Yes, with an important distinction.

Claude Code itself is the coding-agent interface. The model that processes your requests is provided through a backend.

Normally, Claude Code can connect to Anthropic. With this setup, we change the backend URL so Claude Code communicates with OpenRouter instead.

The architecture looks like this:

Claude Code
     ↓
OpenRouter API
     ↓
OpenRouter Free Model
     ↓
Response
     ↓
Claude Code

OpenRouter currently provides a collection of free models and also offers a openrouter/free router that automatically selects an available free model.

However, there is an important limitation.

OpenRouter’s official Claude Code integration states that Claude Code is optimized for Anthropic models and that compatibility is only guaranteed with Anthropic’s first-party provider. Therefore, free non-Anthropic models should be treated as an experimental or budget-friendly option rather than a perfect replacement for Claude’s own models.

Requirements

Before starting, you’ll need:

  1. A computer running Windows, macOS, or Linux
  2. Internet access
  3. A terminal or command prompt
  4. Claude Code installed
  5. A free OpenRouter account
  6. An OpenRouter API key

You do not need an Anthropic Pro subscription for the OpenRouter approach.


Step 1: Install Claude Code

First, install Claude Code on your computer.

Anthropic currently recommends its native installer.

macOS, Linux, or WSL

Open your terminal and run:

curl -fsSL https://claude.ai/install.sh | bash

Windows PowerShell

Open PowerShell and run:

irm https://claude.ai/install.ps1 | iex

Windows Command Prompt

If you’re using CMD instead of PowerShell:

curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd

These are the current installation commands documented by Anthropic.

You can also install Claude Code using Homebrew:

brew install --cask claude-code

Or, where appropriate, npm:

npm install -g @anthropic-ai/claude-code

The official installation documentation should be checked if these commands change in the future.

Claude Code Installation Guide

Verify the Installation

After installation, run:

claude --version

You should see the installed Claude Code version.

You can also run:

claude doctor

This can help diagnose installation problems.


Step 2: Create an OpenRouter Account

Now we need an OpenRouter account.

OpenRouter provides a unified API for accessing many different AI models through a single interface.

OpenRouter Official Website

Create an account and sign in.

OpenRouter provides free models that can be used without purchasing credits, although free models have usage restrictions.

According to OpenRouter’s current pricing information, the free plan includes free models and currently has a limit of 50 requests per day. OpenRouter also states that purchasing at least $10 in credits can increase the free-model limit to 1,000 requests per day.

So if your goal is zero-cost usage, don’t assume that every model on OpenRouter is free.

You must specifically select a model marked as free or use the free-model router.


Step 3: Create an OpenRouter API Key

After creating your OpenRouter account, you need an API key.

Go to the OpenRouter API key section:

OpenRouter API Keys

Create a new key.

Give it a recognizable name such as:

Claude Code Free

OpenRouter will generate an API key that looks similar to:

sk-or-v1-xxxxxxxxxxxxxxxxxxxxxxxx

Important: Protect Your API Key

Your API key is effectively a password for API access.

Never:

  • Publish it on GitHub
  • Put it in a blog post
  • Share it in screenshots
  • Paste it into public Discord or Telegram channels
  • Commit it to a Git repository

If a key is exposed, revoke it and create a new one.

OpenRouter’s documentation also recommends treating API keys as sensitive credentials.


Step 4: Find a Free OpenRouter Model

Before configuring Claude Code, let’s check the free models currently available.

OpenRouter Free Models

OpenRouter’s free-model catalog changes over time, so I recommend checking the current list rather than hard-coding a particular model into your setup.

You can also use OpenRouter’s special free router:

openrouter/free

The openrouter/free router automatically selects an available free model based on the request and the capabilities required.

This is useful because individual free models can disappear, become unavailable, or change their limits.


Step 5: Configure Claude Code to Use OpenRouter

This is the most important part of the setup.

Claude Code uses environment variables to determine where API requests should be sent.

Instead of sending requests directly to Anthropic, we’ll point Claude Code toward:

https://openrouter.ai/api

OpenRouter provides an Anthropic-compatible API interface for Claude Code.

macOS and Linux

If you’re using Bash:

nano ~/.bashrc

If you’re using Zsh, which is common on modern macOS:

nano ~/.zshrc

Add:

export OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY"
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_API_KEY="$OPENROUTER_API_KEY"
export ANTHROPIC_AUTH_TOKEN=""
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1

Replace:

YOUR_OPENROUTER_API_KEY

with your real OpenRouter API key.

For example:

export OPENROUTER_API_KEY="sk-or-v1-xxxxxxxxxxxxxxxx"

Do not copy that example key. It is only a placeholder.

Save the file and restart your terminal.

OpenRouter’s current documentation specifically recommends using the OpenRouter API URL and configuring the authentication variables so Claude Code does not fall back to Anthropic authentication.


Step 6: Configure OpenRouter on Windows

If you’re using Windows PowerShell, you can set environment variables like this:

$env:OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY"
$env:ANTHROPIC_BASE_URL="https://openrouter.ai/api"
$env:ANTHROPIC_API_KEY="$env:OPENROUTER_API_KEY"
$env:ANTHROPIC_AUTH_TOKEN=""
$env:CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY="1"

Replace:

YOUR_OPENROUTER_API_KEY

with your actual API key.

Making the Variables Permanent on Windows

The commands above apply to the current PowerShell session.

For persistent configuration, you can use Windows environment variables or configure them through your system settings.

For example:

[Environment]::SetEnvironmentVariable("OPENROUTER_API_KEY", "YOUR_OPENROUTER_API_KEY", "User")
[Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "https://openrouter.ai/api", "User")
[Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", "YOUR_OPENROUTER_API_KEY", "User")
[Environment]::SetEnvironmentVariable("ANTHROPIC_AUTH_TOKEN", "", "User")
[Environment]::SetEnvironmentVariable("CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY", "1", "User")

Close and reopen PowerShell afterward.


Step 7: Log Out of Your Previous Anthropic Session

If you’ve already used Claude Code with an Anthropic account, you may have an existing login session cached.

That can cause authentication conflicts.

Start Claude Code:

claude

Then run:

/logout

Exit Claude Code and start it again:

claude

OpenRouter specifically recommends clearing a cached Anthropic login when switching Claude Code to OpenRouter.

If you’ve never logged into Claude Code before, you can skip this step.


Step 8: Start Claude Code

Navigate to your project directory.

For example:

cd my-project

Then run:

claude

Claude Code should start.

You can now interact with your project through the terminal.

For example, try:

Explain the structure of this project.

Or:

Find the main entry point of this application.

Or:

Find any obvious bugs in this project and explain them before making changes.

Step 9: Verify That Claude Code Is Using OpenRouter

Inside Claude Code, run:

/status

You should see information indicating that Claude Code is using the OpenRouter base URL.

A typical configuration will show something similar to:

Auth token: ANTHROPIC_API_KEY
Anthropic base URL: https://openrouter.ai/api

The exact output can vary between Claude Code versions.

OpenRouter also provides an Activity Dashboard where you can see API requests and usage.

OpenRouter Activity Dashboard


Step 10: Select a Free Model

This is where the setup becomes interesting.

You can use OpenRouter’s free model router:

openrouter/free

The router automatically selects from available free models.

OpenRouter documents this as the simplest way to access its free model pool.

If your Claude Code version exposes the gateway model picker, you can use:

/model

and look for the available models.

You can also enable model discovery with:

export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1

Then restart Claude Code.

OpenRouter notes that the gateway model picker is opt-in and that the displayed list is curated rather than the entire OpenRouter catalog.


Step 11: Configure a Specific Model

If you don’t want automatic model selection, you can configure individual Claude Code model roles.

Claude Code supports different model variables for different types of work.

For example:

export ANTHROPIC_DEFAULT_OPUS_MODEL="MODEL_ID"
export ANTHROPIC_DEFAULT_SONNET_MODEL="MODEL_ID"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="MODEL_ID"
export CLAUDE_CODE_SUBAGENT_MODEL="MODEL_ID"

Replace MODEL_ID with the model you want to use.

However, there is an important warning here:

Don’t assume that every OpenRouter model will work correctly with every Claude Code feature.

Claude Code is built around Anthropic’s API semantics, and OpenRouter says the native integration is only guaranteed with Anthropic’s first-party provider. Non-Anthropic models may not support every tool, agent, reasoning, or coding workflow exactly as Claude Code expects.

For that reason, the free-model approach is best considered a way to experiment with the Claude Code workflow rather than a guaranteed one-to-one replacement for Claude.


Step 12: Test Claude Code With a Small Project

Don’t start by giving a free model a massive production codebase.

Create a small test project first.

For example:

mkdir claude-code-test
cd claude-code-test

Create a simple file:

touch index.html

Then start Claude Code:

claude

Try this prompt:

Create a simple responsive landing page for a coffee shop.

Use HTML and CSS only.

Create a clean layout with:
- A navigation bar
- Hero section
- About section
- Three featured products
- Contact section
- Mobile responsive design

Before changing files, explain what you plan to create.

This gives you a simple way to verify whether your selected free model handles file editing and coding tasks correctly.


Step 13: Give Claude Code Permission Carefully

Claude Code can interact with your filesystem and run commands.

That means you should not blindly approve every command it proposes.

For example, commands such as:

npm install

may be reasonable in a JavaScript project.

But commands that delete files, modify system configuration, or execute downloaded scripts deserve more scrutiny.

A good workflow is:

Ask Claude to explain
        ↓
Review the proposed change
        ↓
Approve it
        ↓
Run tests
        ↓
Review the result

This is especially important when experimenting with unfamiliar models.


Step 14: Check Your OpenRouter Usage

OpenRouter provides an Activity Dashboard where you can monitor requests and model usage.

This is useful even when you’re trying to stay completely free.

Why?

Because you want to make sure your requests are actually being sent to a free model.

Don’t assume that because you created a free OpenRouter account, every model is free.

OpenRouter has both free and paid models.

OpenRouter Pricing

The current OpenRouter pricing page lists free models separately from its pay-as-you-go models.


OpenRouter Free Model Limits

There is an important limitation that many tutorials leave out.

OpenRouter’s free models aren’t unlimited.

According to its current documentation, free users are limited to 50 free-model requests per day. OpenRouter says the limit can increase to 1,000 requests per day after purchasing at least $10 in credits.

That means:

SetupCostFree-model limit
OpenRouter free account$0Currently 50 requests/day
OpenRouter account with qualifying credit purchasePaid credits requiredCurrently up to 1,000 free-model requests/day
Paid OpenRouter modelUsage-basedDepends on model/provider

These limits can change, so check OpenRouter’s current pricing and FAQ before publishing or relying on these numbers.

OpenRouter FAQ and Pricing Details


Is Claude Code Completely Free With This Method?

The answer needs some clarification.

The Claude Code software

You can install the Claude Code CLI without buying an Anthropic subscription specifically for this OpenRouter setup.

OpenRouter

OpenRouter has free models that can be used without purchasing credits, subject to its current limits.

Anthropic Claude models

Anthropic’s Claude models are not automatically free just because you’re using OpenRouter.

If you select a paid Claude model through OpenRouter, you’ll incur usage costs.

Therefore, the accurate statement is:

You can use the Claude Code CLI with OpenRouter’s free models at no cost, within OpenRouter’s free-tier limits.

Don’t advertise this as “free Claude Opus” or “free Claude Sonnet” unless Anthropic or OpenRouter explicitly offers that particular model for free.


Claude Code + OpenRouter vs Normal Claude Code

Here’s the basic difference:

FeatureNormal Claude CodeClaude Code + OpenRouter Free Models
Claude Code CLIYesYes
Anthropic account/subscriptionNormally required for Anthropic-hosted accessNot required for OpenRouter routing
OpenRouter accountNoYes
API keyAnthropic/OpenRouter depending on setupOpenRouter
Free modelsNoYes
Claude modelsYesAvailable through OpenRouter, but generally paid
CostDepends on Anthropic plan/API$0 when using free models within limits
Model selectionAnthropic modelsOpenRouter catalog/free router
CompatibilityBestCan vary with non-Anthropic models
Daily free limitDepends on Anthropic planOpenRouter free-model limits apply

Common Problems and How to Fix Them

Problem 1: “Authentication failed”

First check your environment variables.

macOS/Linux:

echo $OPENROUTER_API_KEY
echo $ANTHROPIC_BASE_URL

You should see your OpenRouter key and:

https://openrouter.ai/api

On Windows PowerShell:

echo $env:OPENROUTER_API_KEY
echo $env:ANTHROPIC_BASE_URL

Also make sure you didn’t accidentally leave an old Anthropic API key configured.

OpenRouter specifically recommends ensuring the Anthropic authentication variables don’t conflict with your OpenRouter credentials.


Problem 2: Claude Code keeps asking me to log in

If you previously used Claude Code with Anthropic, run:

/logout

Then close Claude Code and restart it:

claude

A cached Anthropic session can conflict with your OpenRouter configuration.


Problem 3: “Model not found”

A model may have been removed, renamed, become temporarily unavailable, or may not be compatible with Claude Code.

First check the current OpenRouter model catalog:

OpenRouter Models

If you’re trying to use a free model, check the current free-model list:

OpenRouter Free Models

You can also try the:

openrouter/free

router instead of hard-coding a specific model.


Problem 4: The Model Works in OpenRouter but Not in Claude Code

This is an important distinction.

A model can work perfectly through OpenRouter’s normal API and still not behave correctly inside Claude Code.

Why?

Claude Code is an agentic coding environment. It doesn’t simply send ordinary text prompts. It can use tools, structured messages, file operations, reasoning features, and other API capabilities.

OpenRouter’s official documentation warns that Claude Code is optimized for Anthropic models and that non-Anthropic models may not work correctly with all features.

If you need maximum compatibility, use an Anthropic model through OpenRouter instead of a random free model.

If your priority is zero cost, experiment with the current free models and expect occasional compatibility issues.


Problem 5: I Accidentally Used a Paid Model

This is one of the biggest mistakes to avoid.

Before starting a serious session, check:

  1. Which model is selected
  2. Whether the model is marked free
  3. Your OpenRouter Activity page
  4. Your OpenRouter credit balance

You can browse the current free models here:

OpenRouter Free Models Collection

And monitor usage here:

OpenRouter Activity Dashboard


Problem 6: Free Models Are Slow

Free models can become slower during periods of heavy demand.

OpenRouter notes that free models can have lower rate limits and availability than paid models.

If you’re working on an important project, you may eventually want to switch to a paid model.

The advantage of OpenRouter is that you don’t have to completely change your workflow. You can keep Claude Code and change the backend model.


How to Get Better Results From Free Models

Free models can be surprisingly useful, but you should adjust your expectations.

Instead of giving one huge instruction such as:

Build my entire SaaS application.

break the work into smaller tasks.

For example:

Analyze this project structure and tell me how authentication currently works.

Then:

Find the authentication bug. Don't modify anything yet. Explain the problem.

Then:

Fix the bug and run the existing tests.

Then:

Review your changes and look for regressions.

This workflow makes it easier to catch mistakes and reduces unnecessary model usage.


Useful Claude Code Commands

Here are several commands worth knowing.

Start Claude Code

claude

Check installation

claude --version

Diagnose installation

claude doctor

Check current configuration

Inside Claude Code:

/status

Show available help

/help

Log out

/logout

Change model

Inside Claude Code:

/model

Claude Code’s available commands can change between releases, so use:

/help

to see the commands supported by your installed version.


Example: Using Claude Code With a WordPress Project

If you’re a WordPress developer, you can use Claude Code from your WordPress project directory.

For example:

cd /path/to/wordpress
claude

Then ask:

Analyze the WordPress plugin structure in this project.

Do not modify anything yet.

Identify:
1. Main plugin file
2. Admin functionality
3. Frontend functionality
4. Database operations
5. REST API endpoints
6. Potential security issues
7. Potential performance issues

Give me a summary first.

Once you’ve reviewed the results, you can ask Claude Code to work on a specific problem.

For example:

Review the plugin's AJAX handlers.

Look for missing capability checks, nonce validation, unsafe SQL queries, and unsanitized input.

Do not change the code yet. Show me the problems first.

This is a much safer workflow than immediately telling an AI agent to modify an entire production plugin.


Security Tips

Using an AI coding agent requires some basic security precautions.

1. Never expose your API key

Never put this:

OPENROUTER_API_KEY="sk-or-v1-..."

inside a public Git repository.

2. Don’t commit local configuration files containing secrets

If you create project-specific configuration, make sure secrets are excluded from Git.

3. Review destructive commands

Be especially careful with commands such as:

rm -rf

or database commands that delete or modify large amounts of data.

4. Use Git

Before allowing an AI coding agent to make substantial changes:

git status

Create a commit or branch so you have an easy rollback point.

For example:

git checkout -b ai-experiment

Then let Claude Code work on the branch.

5. Don’t give an AI agent unnecessary credentials

Avoid putting production passwords, database credentials, private keys, or other secrets into prompts.


Is OpenRouter Better Than Using Claude Directly?

It depends on your goal.

If you want the best possible compatibility with Claude Code, using Anthropic’s own models is the safer choice.

If you want to experiment with multiple models from different providers, OpenRouter is much more flexible.

OpenRouter provides access to a large catalog of models through a common API, while its free-model router makes it easy to experiment without immediately purchasing credits.

For developers who are learning, experimenting, or building small projects, the free route can be a useful way to learn how AI coding agents work.


Frequently Asked Questions

Can I use Claude Code without a Claude Pro subscription?

Yes, when you configure Claude Code to route requests through OpenRouter, you can use an OpenRouter API key instead of relying on a Claude subscription for the backend. OpenRouter documents this integration directly.

Is Claude Code itself free?

The Claude Code CLI can be installed, but the underlying model access is not necessarily free. If you use paid Anthropic or OpenRouter models, you can incur charges.

The zero-cost approach described here relies on OpenRouter’s free models.

Are Claude Sonnet and Claude Opus free through OpenRouter?

No. Do not assume Anthropic’s Claude models are free through OpenRouter.

OpenRouter has free models, but Claude models are generally priced according to their provider/model pricing.

What is OpenRouter’s free model?

There isn’t just one free model.

OpenRouter maintains a changing selection of free models and also provides:

openrouter/free

which automatically chooses an available free model.

How many free requests can I make?

OpenRouter currently documents a limit of 50 free-model requests per day for accounts that haven’t purchased at least $10 in credits. Accounts that meet the credit-purchase condition can receive up to 1,000 free-model requests per day.

Always check OpenRouter’s current limits because these policies can change.

Can I use OpenRouter with Windows?

Yes. Claude Code supports Windows, including PowerShell and Windows setups using Git for Windows or WSL.

Do I need Node.js?

The current native Claude Code installer does not require you to manually install Node.js first. If you use the npm installation method, Node.js 18 or newer is required.

Is OpenRouter safe to use?

OpenRouter is a legitimate API gateway, but you should still treat API keys and source code as sensitive information.

Review OpenRouter’s current privacy and data policies before using it with confidential or proprietary code.

Can I use Claude Code with a paid OpenRouter model later?

Yes. That’s one of the useful things about the setup.

You can start with a free model and move to a paid model when you need better performance or compatibility.


Final Thoughts

Using Claude Code with OpenRouter’s free models is a useful way to experiment with AI-powered coding without immediately paying for an Anthropic subscription or API usage.

The basic process is:

1. Install Claude Code
       ↓
2. Create an OpenRouter account
       ↓
3. Generate an OpenRouter API key
       ↓
4. Configure Claude Code
       ↓
5. Point Claude Code to OpenRouter
       ↓
6. Select a free model
       ↓
7. Start Claude Code
       ↓
8. Verify with /status
       ↓
9. Monitor usage

The most important thing to remember is that “Claude Code for free” does not mean “free Claude models.”

You’re using the Claude Code interface and workflow while routing the underlying requests through OpenRouter’s free model infrastructure.

For learning, experimenting, small projects, and testing AI coding workflows, this can be a very useful setup. For production development or complex agentic tasks, you may eventually get better results from a supported Anthropic model or another paid coding model.

Official Resources


Related DevStackIO Resources

Related Tools

Try these companion tools on DevStackIO Tools: