You can use the Claude Code CLI with free models by connecting it to OpenRouter, running a local model through Ollama, or using FreeLLMAPI to route between provider free tiers. A free Claude.ai account by itself does not include Claude Code access. These methods keep the Claude Code interface and change which service runs the model. They do not unlock paid Anthropic models for free.

Free Claude Code setup options at a glance

MethodWhat you needMain trade-off
OpenRouter free modelsAn OpenRouter key and internet accessQuick setup. Free requests have limits and the available models can change.
Ollama local modelOllama and a machine that can run a tool-capable modelLocal inference has no per-request API charge. Speed and context depend on your hardware.
FreeLLMAPIA local gateway and your own provider keysMore routing control. You manage the gateway and each provider’s limits.

Install the CLI using Anthropic’s official Claude Code setup guide and confirm claude --version works. Start in a throwaway repository so your first test sends only sample files. For a hosted route, check the selected provider’s data policy before using private code.

Method 1: Use Claude Code for free with OpenRouter

  1. Create your own OpenRouter API key. Keep it out of Git and shared settings.
  2. Open a separate terminal in the sample repository. If Claude Code already has a cached Anthropic login and reports an auth conflict, OpenRouter documents signing out with /logout before relaunching. That signs the CLI out of its previous session.
  3. Set OpenRouter’s Anthropic-compatible URL to https://openrouter.ai/api. The OpenAI-style /api/v1 URL is for a different protocol.
  4. Start with openrouter/free, or pick an available :free model that supports tools. Keep every model role on the intended free route, including subagents.

PowerShell 7 example

$env:ANTHROPIC_BASE_URL = "https://openrouter.ai/api"
$env:ANTHROPIC_AUTH_TOKEN = Read-Host "OpenRouter API key" -MaskInput
$env:ANTHROPIC_API_KEY = ""
$model = "openrouter/free"
$env:ANTHROPIC_DEFAULT_FABLE_MODEL = $model
$env:ANTHROPIC_DEFAULT_OPUS_MODEL = $model
$env:ANTHROPIC_DEFAULT_SONNET_MODEL = $model
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL = $model
$env:CLAUDE_CODE_SUBAGENT_MODEL = $model
claude --model $model

Bash example

read -rsp "OpenRouter API key: " ANTHROPIC_AUTH_TOKEN
printf '\n'
export ANTHROPIC_AUTH_TOKEN
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_API_KEY=""
model="openrouter/free"
export ANTHROPIC_DEFAULT_FABLE_MODEL="$model"
export ANTHROPIC_DEFAULT_OPUS_MODEL="$model"
export ANTHROPIC_DEFAULT_SONNET_MODEL="$model"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="$model"
export CLAUDE_CODE_SUBAGENT_MODEL="$model"
claude --model "$model"

Inside Claude Code, use /status to check the base URL and authentication. Ask it to read a small sample README and explain it without editing. Check OpenRouter Activity for the served model and request cost. If the free router cannot find a model that supports your request, choose a compatible model from the free model catalog. See the OpenRouter Claude Code integration for authentication and model mapping.

Method 2: Run Claude Code with a local Ollama model

Install Ollama and Claude Code, then run ollama launch claude in the sample repository. Select a downloaded local model that supports tools. In Ollama’s picker, a cloud model uses a hosted service, so choose a local entry if the inference needs to stay on your machine. Start with a small code-reading task and verify that file tools work before asking the model to edit a project. If it runs out of memory or context, use a smaller repository or model and check Ollama’s context guidance. Ollama’s Claude Code setup.

Method 3: Route your free API tiers with FreeLLMAPI

FreeLLMAPI is a self-hosted gateway. Install it from the official project, start the local server, and configure your own keys for the providers you want to use. In its dashboard, check which model routes are enabled and leave paid routes out if you want a free-only setup. With the gateway running and Claude Code installed, the project documents npx freellmapi launch. Verify that the package name and command match the current project documentation before running it.

Running the gateway locally keeps routing on your machine. Prompts still go to the provider that serves the request unless you route them to a local model. A fallback can help when one provider is busy, but all connected free tiers can run out.

Claude Code usage limit reached or plan expired? What to do next

Check the message before changing your setup. If your paid plan is still active and Claude Code shows a reset time, you have reached an included usage limit. If the subscription ended and the account is on Claude Free, waiting for a quota reset will not restore the paid plan’s CLI access. You can renew, use a separately billed API account, or use the free-model routes above.

SituationWhat to doHow it is billed
Active plan with a quota reset timeWait until the displayed reset. If the limit is specific to one model and the plan allows another, check /model before switching.Waiting adds no charge beyond your subscription.
Active paid plan and you need to continue nowCheck whether Usage credits is available in Claude’s usage settings. Review the cap and auto-reload settings before enabling it.Additional usage is billed separately at API rates.
Plan expired and you want Anthropic modelsRenew the plan or authenticate separately with an authorized Claude Console account. If your employer already provides Claude access through a supported cloud service, use its documented setup.Subscription or separate API and cloud billing.
Plan expired and you want no additional model billChoose a local Ollama model or an explicitly free OpenRouter or FreeLLMAPI route. Start a fresh session and check the provider and model before sending your project.Local inference has no per-request API charge. Hosted free routes have quotas and can change.

Claude Console, Amazon Bedrock, Google Cloud’s Agent Platform, and Microsoft Foundry are separate billing routes. Check the cloud account or organization’s policy before using them. Ollama’s cloud pay-as-you-go option has no subscription fee, but it charges for cloud model tokens. Choose a local Ollama model if you want to avoid those charges. Claude plan and quota guidance · Claude Code deployment options · Ollama pricing.

How do I pick up the same coding task with another model?

Review your working tree first. Write a short handoff with the goal, changed files, commands already run, and the next test. Give that handoff to the new session and ask it to inspect the diff before making changes. If the message was about a full context window instead of account usage, try /compact or a fresh conversation on your existing plan. Check /status after switching credentials so you know which route is active.

Common problems

  • Claude Code asks you to log in: Check that you launched from the terminal where you set the gateway variables. Read the integration’s auth troubleshooting section before changing saved credentials.
  • Model unavailable or HTTP 429: Check the live catalog and the provider’s quota. Try a different explicitly free model or wait for the quota to reset.
  • Chat works, but file tools fail: Pick a model that supports tool calls and retry the same one-file task. Test one configuration change at a time.

Does this give you Claude Sonnet or Opus for free?

Access and pricing depend on the model you actually route to. A free route can use a different model inside Claude Code. Check the served model and cost in the provider’s dashboard. Once the setup works, try a small reusable workflow from our Claude Skills guide.