Claude Code is one of the most capable AI coding assistants available today — it can edit files, run tests, write entire features, and reason about large codebases with minimal hand-holding. But there's a widespread misconception that you need an active Claude Pro or Max subscription to use it.

You don't. Claude Code is a CLI tool that works independently of the claude.ai web subscription. You can run it completely free using a local model via Ollama, or pay-as-you-go with an Anthropic API key, or route it through AWS Bedrock and Google Vertex AI if you have existing cloud credits. This post walks through every method, starting with the fully free local option.

TL;DR: Run Claude Code for free with Ollama + LiteLLM on your own machine — no API key, no subscription, no data leaving your laptop. Or grab an Anthropic API key ($5 free credits) for cloud-quality output in 5 minutes.

What Is Claude Code, Exactly?

Claude Code (@anthropic-ai/claude-code) is an agentic CLI released by Anthropic. Unlike a chat interface, it operates as an autonomous agent in your terminal: it reads your codebase, writes and edits files, executes shell commands, runs tests, and iterates until a task is done — all under your supervision.

It connects to the Anthropic API format to call models. By pointing its base URL to a compatible local server, you can swap in any model — including locally running open-source models — without touching a paid plan.

The Four Ways to Run Claude Code Without a Subscription

Method Cost Best For Setup Effort
Ollama + LiteLLM (Local) Free forever Privacy-first, offline, students 20 min
Anthropic API Key Pay-as-you-go ($5 free credits) Individual developers, freelancers 5 min
AWS Bedrock AWS billing (use existing credits) Teams already on AWS 15 min
Google Vertex AI GCP billing (use existing credits) Teams already on GCP 15 min

Method 1: Ollama + LiteLLM — Fully Local, Completely Free

This is the only method with zero ongoing cost. Everything runs on your machine — no tokens billed, no data sent to any cloud. The trick is using LiteLLM as a proxy that translates Ollama's OpenAI-compatible API into the Anthropic API format that Claude Code expects.

Hardware note: A 7B parameter model needs ~8 GB RAM. For a 13B model you'll want 16 GB+. The quality gap vs cloud models is real — Ollama works great for refactoring, tests, and boilerplate, but struggles with complex multi-file reasoning that Claude Sonnet handles easily.

Step 1 — Install Ollama

Download and install from ollama.com, then pull a code-capable model:

# Good options for coding tasks
ollama pull qwen2.5-coder:7b       # Best coding model at 7B, fast
ollama pull deepseek-coder-v2:16b  # Stronger reasoning, needs 16 GB RAM
ollama pull codellama:13b          # Meta's dedicated code model

Verify Ollama is running:

ollama list   # should show your pulled models
curl http://localhost:11434/api/tags   # should return JSON

Step 2 — Install LiteLLM

LiteLLM acts as the translation layer between Ollama and Claude Code. Python 3.8+ is required:

pip install litellm[proxy]

Step 3 — Start LiteLLM Proxy in Anthropic-Compatible Mode

Run LiteLLM pointing at your local Ollama model, exposing it on port 8082:

litellm --model ollama/qwen2.5-coder:7b \
        --port 8082 \
        --api_base http://localhost:11434

You should see output like:

INFO: LiteLLM Proxy running on http://0.0.0.0:8082

Leave this terminal open — it must stay running while you use Claude Code.

Step 4 — Install Claude Code

Node.js 18+ is required:

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

Step 5 — Point Claude Code at Your Local Proxy

Set these two environment variables. The API key value doesn't matter — it just can't be empty:

export ANTHROPIC_BASE_URL="http://localhost:8082"
export ANTHROPIC_API_KEY="local-ollama"

Step 6 — Run Claude Code

cd your-project
claude

Claude Code will now send all requests to your local LiteLLM proxy, which forwards them to Ollama. Everything stays on your machine — no internet required after the initial model download.

Persisting the setup: Add the two export lines to your ~/.bashrc or ~/.zshrc so they survive terminal restarts. Create a shell alias like alias start-local-claude="litellm --model ollama/qwen2.5-coder:7b --port 8082 --api_base http://localhost:11434 &" to launch the proxy in one command.

Switching Between Local Models

To swap models, restart LiteLLM with a different --model flag:

# Switch to a larger model for harder tasks
litellm --model ollama/deepseek-coder-v2:16b \
        --port 8082 \
        --api_base http://localhost:11434

Method 2: Anthropic API Key (5-Minute Setup)

If local model quality isn't quite cutting it, the Anthropic API gives you access to the real Claude models on a pay-per-token basis — no subscription required. As of 2026, claude-sonnet-4-5 costs $3 per million input tokens and $15 per million output tokens. Light daily use rarely exceeds $10–15/month.

Step 1 — Get Your API Key

  1. Go to console.anthropic.com and create a free account.
  2. Navigate to API Keys and generate a new key.
  3. New accounts automatically receive $5 in free credits — no credit card required upfront.

Step 2 — Install Claude Code

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

Step 3 — Set Your API Key

# Add to ~/.bashrc or ~/.zshrc
export ANTHROPIC_API_KEY="sk-ant-api03-..."
source ~/.bashrc   # or source ~/.zshrc

Step 4 — Run Claude Code

cd your-project
claude
Cost tip: Use claude --model claude-haiku-4-5 for lighter tasks like refactoring or documentation. Haiku is ~20x cheaper than Sonnet and fast enough for most non-reasoning tasks.

Specifying the Model

claude --model claude-sonnet-4-5   # best balance
claude --model claude-opus-4-6     # complex architecture work
claude --model claude-haiku-4-5    # fast and cheap

Or set a persistent default for a project:

claude config set model claude-sonnet-4-5

Method 3: AWS Bedrock

If you or your team has AWS credits — from a startup program, enterprise agreement, or existing cloud spend — you can route all Claude Code requests through AWS Bedrock. This keeps billing within your AWS account and may qualify for reserved pricing.

Prerequisites

  • An AWS account with Bedrock access enabled
  • Claude models enabled in your Bedrock console (Bedrock → Model Access)
  • AWS CLI configured (aws configure) or an IAM role attached to your environment

Setup

export CLAUDE_CODE_USE_BEDROCK=1
export AWS_REGION=us-east-1

aws configure
# AWS Access Key ID: AKIA...
# AWS Secret Access Key: ...
# Default region name: us-east-1
claude

Claude Code detects CLAUDE_CODE_USE_BEDROCK=1 and routes all calls through Bedrock. No ANTHROPIC_API_KEY needed.

Model IDs on Bedrock: Bedrock uses different model ID strings internally, but Claude Code handles this mapping automatically when Bedrock mode is active.

Method 4: Google Vertex AI

GCP users can run Claude Code through Vertex AI — useful if your org keeps AI billing consolidated in Google Cloud.

Prerequisites

  • A GCP project with Vertex AI API enabled
  • Claude models enabled in Vertex AI Model Garden
  • Google Cloud CLI installed and authenticated

Setup

export CLAUDE_CODE_USE_VERTEX=1
export CLOUD_ML_REGION=us-east5
export ANTHROPIC_VERTEX_PROJECT_ID="your-gcp-project-id"

gcloud auth application-default login
claude

Claude Code uses your Application Default Credentials to authenticate. No ANTHROPIC_API_KEY required.

Estimating Monthly Cost (API Methods)

Using claude-sonnet-4-5 pricing ($3 input / $15 output per million tokens):

Usage Pattern Estimated Monthly Cost
Light use — 1–2 hrs/day, small codebase $5–$15
Moderate use — 4–6 hrs/day, mid-size project $20–$50
Heavy use — all-day agentic tasks, large repos $80–$150+

Set a spend limit in the Anthropic console under Billing → Usage Limits to avoid surprises.

Common Errors and How to Fix Them

Ollama: "Connection refused" on port 8082

Error: connect ECONNREFUSED 127.0.0.1:8082

Your LiteLLM proxy isn't running. Start it in a separate terminal with the litellm --model ollama/... command from Method 1.

Ollama: Model responds but output is garbled

The model isn't following Claude Code's system prompt format well. Switch to a stronger model like qwen2.5-coder:7b or deepseek-coder-v2:16b — they have better instruction-following than general-purpose models.

API: "Authentication error" or "Invalid API key"

AuthenticationError: invalid x-api-key

Run echo $ANTHROPIC_API_KEY to verify the variable is exported in your current shell. Re-source your shell profile if needed.

API: "Rate limit exceeded"

RateLimitError: 429 Too Many Requests

New API accounts start on Tier 1 with conservative limits. Claude Code will auto-retry. To increase limits, add a payment method and request a tier upgrade at console.anthropic.com → Limits.

Bedrock: "No credentials found"

NoCredentialProviders: no valid providers in chain

Run aws sts get-caller-identity to verify credentials are active. If it fails, re-run aws configure.

Which Method Should You Choose?

  • Ollama wins if you're privacy-conscious, working offline, or just want zero cost forever. Expect model quality ~60–70% of cloud Claude for coding tasks.
  • Anthropic API key wins if you want full Claude quality with no subscription commitment. The $5 free credits are enough to evaluate it properly.
  • Bedrock/Vertex wins if you have existing cloud credits, need data residency guarantees, or your company requires AI spend within a specific cloud account.
  • Claude Max subscription wins if you're using Claude Code 6+ hours a day — the flat fee becomes cheaper than API costs at that volume, plus you get higher rate limits.
"Start local with Ollama — it costs nothing and teaches you exactly what you're getting. Then decide if the quality gap is worth paying for."

Final Checklist

For Ollama (local, free):

  1. ollama pull qwen2.5-coder:7b
  2. pip install litellm[proxy]
  3. Start proxy: litellm --model ollama/qwen2.5-coder:7b --port 8082 --api_base http://localhost:11434
  4. npm install -g @anthropic-ai/claude-code
  5. export ANTHROPIC_BASE_URL="http://localhost:8082" && export ANTHROPIC_API_KEY="local-ollama"
  6. claude

For Anthropic API (cloud, pay-as-you-go):

  1. npm install -g @anthropic-ai/claude-code
  2. Get API key from console.anthropic.com
  3. export ANTHROPIC_API_KEY="sk-ant-..."
  4. claude
  5. Optionally: set a spend limit in the console

Either way, you're running the same powerful agentic CLI that engineers across the world are using to ship code faster — without paying a subscription fee.