Coding

Claude Code with local and free models: what Ollama and OpenRouter really allow

Claude Code can run on local or free cloud models via Ollama and OpenRouter. Here is how the setup works, what 64k context and 50 free requests a day mean, and where it breaks down.

Oliver · FoxAI World4 min read
18
Oliver the owl sits at a laptop beneath the Claude Code name, with cloud and server imagery nearby.Free engine, real limits

Conceptual cover created with AI.

Claude Code is useful, but heavy use runs into subscription limits or API bills. So a tempting idea keeps circulating: keep the tool, swap the model underneath, and pay nothing. Ollama and OpenRouter both document exactly how to do that. The documentation also shows where the free version stops being free in practice.

Tool and model are two different things

Claude Code is the harness: the part that reads files, runs commands and edits your project. The language model is the engine that decides what to do next. Claude Code talks to that engine through an Anthropic-style API, and the environment variable ANTHROPIC_BASE_URL decides where those requests go. Anthropic’s own documentation is precise here: the base URL changes where requests are sent, not which model answers them. Point it at another service and a different model answers inside the same interface.

Oliver the owl sits at a Claude-branded laptop amid cloud, server and robot icons.
AI-generated conceptual illustration.

The local route: Ollama

Ollama runs models on your own machine and exposes an Anthropic-compatible API. Its documentation offers a single launch command, ollama launch claude, which starts Claude Code connected to Ollama. Manual setup uses three variables: ANTHROPIC_BASE_URL=http://localhost:11434, ANTHROPIC_AUTH_TOKEN=ollama and an empty ANTHROPIC_API_KEY.

Two conditions matter. The model must support tool calling, meaning it can ask the harness to read a file or run a command; without that it can chat but cannot work on your project. And Ollama recommends a context window of 64k tokens or more, the amount of text the model can keep in view at once. A larger window costs memory, so the realistic limit is your hardware, not the licence. Ollama also notes that hosted WebSearch and advanced tool controls are not fully supported, and that Claude settings can override shell variables, so check the connection with /status.

The cloud route: OpenRouter free models

OpenRouter is a gateway to many providers’ models. For Claude Code it documents the base URL https://openrouter.ai/api, your OpenRouter key as ANTHROPIC_AUTH_TOKEN, and an explicitly empty ANTHROPIC_API_KEY so Claude Code does not fall back to Anthropic directly.

Free models, marked :free, have hard limits: 20 requests per minute and 50 requests per day if you have bought less than 10 credits in total. From 10 purchased credits the daily cap rises to 1,000. That sounds like a lot until you remember that an agent does not send one request per task. It reads, plans, calls tools and checks results, and each step is a request. My inference: 50 daily requests can be gone after one or two real tasks.

Claude Code’s model menu shows aliases such as Opus, Sonnet and Haiku. Variables like ANTHROPIC_DEFAULT_SONNET_MODEL control what each alias resolves to. A slot labelled Sonnet can therefore be served by an entirely different model. Asking the model who it is proves little. The reliable record is the provider’s request log, which shows which model handled the request and what it cost. It is also worth checking that an unintended paid model is not still selectable in the same menu.

Good enough for daily work?

OpenRouter states it plainly: Claude Code with OpenRouter is only guaranteed with the Anthropic first-party provider, and Claude Code is optimised for Anthropic models, so other providers may not work correctly. That is not a reason to avoid experiments. It is a reason to define the expected result before you start: which file should change, and how will you check it?

My assessment: the local route is the more honest option if you already have the hardware, because your code stays on your machine and the limit is speed, not a daily counter. The free cloud route is fine for a quick test, but with an agent the daily cap, not the price, sets the pace. Small detail. Big difference. For regular work, the time spent fixing a weaker model’s output is also a cost.

Ask AI about this article

Opens in a new tab with the question filled in.

Sources and research

Written by FoxAI World. The cover and illustrations are AI-generated conceptual artwork.

Your favourites

This list stays in this browser on your device. No account is needed, and other visitors cannot see it.

Use a story’s bookmark button to add your first favourite.