morphy

Claude Code and Codex with Ollama, OpenRouter and free models (2026)

How to run Claude Code and Codex on free and local models in 2026: Ollama, LM Studio, OpenRouter's free models and DeepSeek, with the exact setup, the limits, and what works less well.

Short answer: both agents can run on models that aren't their own. For Claude Code, point it at another address with two settings, ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN, or let Ollama do it with ollama launch claude. For Codex, codex --oss uses a model on your own computer through Ollama or LM Studio, and other providers go in its config.toml. You don't need a Claude or ChatGPT plan for any of it. You do give something up: these agents are built for their own models, and Anthropic says plainly that it doesn't support Claude Code on other models.

Everything below is from the official docs of Anthropic, OpenAI, Ollama, LM Studio, OpenRouter and DeepSeek, checked on October 24, 2026. (I build Morphy, which runs free and local models as chats; it comes up near the end.)

Your options at a glance

OptionWhat it costsWhere the model runsWorks with
Ollama, local modelsFreeYour computerClaude Code, Codex, OpenCode
Ollama CloudFree plan with starter credits; Pro $20 a monthOllama's serversClaude Code, Codex, OpenCode
LM StudioFreeYour computerClaude Code, Codex
OpenRouter's free modelsFree: 50 requests a day, or 1,000 once you've bought 10 creditsOpenRouter's providersClaude Code, Codex
DeepSeek's APIPay per tokenDeepSeek's serversClaude Code
OpenCode's free modelsFree, many for a limited timeOpenCode's providersOpenCode

The catch with the free hosted models is volume. An agent sends a request at every step (read a file, run a command, edit, check), so 50 requests a day doesn't go far. Local models have no daily limit, but they need a capable computer and a long context window.

Can Claude Code use other models?

It can, but it isn't designed to. Claude Code talks to whatever address ANTHROPIC_BASE_URL points to, as long as that address speaks Anthropic's API. Ollama, LM Studio, OpenRouter and DeepSeek all offer one. Anthropic's own docs say it "doesn't support routing Claude Code to non-Claude models through any gateway", and OpenRouter warns that "Claude Code is optimized for Anthropic models and may not work correctly with other providers."

In practice, basic chat and file edits work with a capable model, and the extras are where it gets patchy: Ollama notes that hosted web search and "advanced tool controls are not fully supported" with its cloud models.

Two things to know before you start:

  • The settings replace your Claude login. While ANTHROPIC_AUTH_TOKEN is set, Claude Code uses it instead of your Claude subscription. Unset it (or open a new terminal) to go back.
  • Leave ANTHROPIC_API_KEY empty. A real Anthropic key in that variable would be sent instead, so the guides set it to an empty string.

Claude Code with Ollama

The quickest way, once Ollama is installed:

ollama launch claude

It starts Claude Code with Ollama's settings already in place. To set it up yourself, on macOS or Linux:

export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3.5

On Windows, in PowerShell:

$env:ANTHROPIC_AUTH_TOKEN="ollama"
$env:ANTHROPIC_BASE_URL="http://localhost:11434"
claude --model qwen3.5

If ANTHROPIC_API_KEY is set on your PC, remove it for that window with Remove-Item Env:ANTHROPIC_API_KEY. Pull the model first (ollama pull qwen3.5), and give it room: Ollama recommends a context length of 64k or more, set in Ollama's settings or with OLLAMA_CONTEXT_LENGTH. A short context is the most common reason a local model loses track halfway through a task.

Ollama's cloud models work the same way without a download. Point Claude Code at https://ollama.com with your Ollama API key as the token, and pick a cloud model, for example claude --model glm-5.3-flash. Ollama's free plan includes starter credits for its smaller cloud models, and Pro ($20 a month) adds larger ones.

On macOS, Ollama's app can also connect the Claude desktop app to Ollama's models (Apps → Connect Claude); Windows support is "coming soon".

Claude Code with LM Studio

LM Studio offers the same kind of Anthropic-compatible address. Start its server, then point Claude Code at it:

lms server start --port 1234
export ANTHROPIC_BASE_URL=http://localhost:1234
export ANTHROPIC_AUTH_TOKEN=lmstudio
claude --model openai/gpt-oss-20b

LM Studio asks for a model with more than about 25k of context; more is better.

Claude Code with OpenRouter

OpenRouter gives you hundreds of models through one key, including free ones (their IDs end in :free). Its own guide uses these settings:

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

On Windows, or to keep it to one project, put the same three in .claude/settings.local.json in your project, and keep that file out of git:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://openrouter.ai/api",
    "ANTHROPIC_AUTH_TOKEN": "sk-or-...",
    "ANTHROPIC_API_KEY": ""
  }
}

If you were signed in to Claude, run /logout and restart Claude Code. /status then shows the OpenRouter address. Mind the free limits: 20 requests a minute and 50 a day, or 1,000 a day once you've bought at least 10 credits in total.

Claude Code with DeepSeek

DeepSeek isn't free, but it's the other common way to run Claude Code without Anthropic. Its API has an Anthropic-compatible address, and DeepSeek's guide sets it up like this:

export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
export ANTHROPIC_AUTH_TOKEN=<your DeepSeek API key>
export ANTHROPIC_MODEL=deepseek-flash[1m]

The guide also sets the Opus, Sonnet, Haiku and subagent models to DeepSeek's, so nothing falls back to a Claude name. If one does, DeepSeek maps it: Claude's Opus names go to deepseek-v4-pro, and the rest to deepseek-flash. MCP tools and document attachments aren't supported through this address.

Codex with Ollama or LM Studio

Codex has local models built in. With Ollama installed:

ollama launch codex

or, without the helper:

codex --oss
codex --oss -m gpt-oss:120b

--oss asks which local app to use. To skip the question, set oss_provider = "ollama" (or "lmstudio") in ~/.codex/config.toml. Codex also needs at least 64k of context. Inside a session, /model switches between the models you've pulled.

In the ChatGPT desktop app, where the Codex app now lives, Ollama 0.34 or later can add up to five local or cloud models to Codex's model picker: open Ollama's app, go to Apps, and turn on ChatGPT. They work in Codex mode only; ChatGPT's regular chat keeps its own models.

Codex with OpenRouter

Other providers go in Codex's config.toml, and they have to speak OpenAI's newer Responses API, which OpenRouter does. OpenRouter's guide:

model_provider = "openrouter"
model = "~openai/gpt-sol-latest"

[model_providers.openrouter]
name = "openrouter"
base_url = "https://openrouter.ai/api/v1"

[model_providers.openrouter.auth]
command = "sh"
args = ["-c", "echo $OPENROUTER_API_KEY"]

On Windows, the auth section runs PowerShell instead: command = "powershell" with args = ["-NoProfile", "-Command", "Write-Output $env:OPENROUTER_API_KEY"]. Swap the model for one ending in :free to use a free one.

OpenCode: free models with no setup

OpenCode is an open-source coding agent with free models of its own (from OpenCode Zen), so there's nothing to configure. In October 2026 they include GLM-5.3-Flash, DeepSeek V4.1 Flash and a few others. Most are free "for a limited time", and some collect your prompts to improve the model: OpenCode says GLM-5.3-Flash, DeepSeek V4.1 Flash and LongCat keep nothing, while for NVIDIA's trial models it warns "do not submit personal or confidential data." ollama launch opencode connects it to Ollama too.

Which model should you use?

Open models change every month, so check what's current before you settle on one. What matters:

  • It must use tools well. An agent works by calling tools; a model that can't do that reliably stalls or loops. The models in each tool's own docs (qwen3.5 and glm-5.3-flash for Ollama, gpt-oss for Codex and LM Studio) are a safe start.
  • Context of 64k or more, for Claude Code and Codex alike.
  • Enough memory. OpenAI says gpt-oss-20b runs with 16 GB of memory, while gpt-oss-120b needs a single 80 GB GPU. If your computer can't run a model fast enough, a cloud model is the better free option.

Expect a step down from the agents' own models. The top of the coding benchmarks still belongs to closed models: on Terminal-Bench 4.0, Opus 5.5, Sonnet 5.5 and GPT-6 Astra lead (the numbers). Free and local models are best for simple, well-defined work, for privacy, and for when your plan's limit has run out.

In Morphy

Morphy runs free and local models as ordinary chats on its canvas, set up in Settings instead of environment variables. OpenRouter connects with a click, and its model picker lists the free models first, with the newest free one as the default. Ollama's local and cloud models show up once Ollama is running and the Codex CLI is installed, and OpenCode chats get OpenCode's free models. OpenRouter and Ollama chats run on Codex's own agent, so Claude Code is never pointed at a model Anthropic doesn't support. On Pro, a custom provider can be any OpenAI-compatible API.

What it's handy for: a Claude Code chat on your plan and an Ollama chat on the same project, side by side, and when your plan's limit runs out, handing the conversation to a free model in a new chat. See Connect your AI.

Questions

Can Claude Code use local models? Yes, through Ollama (ollama launch claude) or LM Studio, which both offer an Anthropic-compatible address on your computer. Anthropic doesn't support it, and some features work less well.

Is Claude Code free with Ollama? Yes. Claude Code doesn't need a Claude plan when it's pointed at Ollama, and local models cost nothing. Ollama's cloud models have a free plan with starter credits.

Can I use OpenRouter's free models in Claude Code? Yes, with the settings above and a model ending in :free. The limit of 50 requests a day (1,000 after buying 10 credits) runs out quickly with an agent.

Does Codex work with Ollama? Yes: codex --oss or ollama launch codex. In the ChatGPT desktop app, Ollama's app can add its models to Codex's picker.

What's the best free model for Claude Code? There's no lasting answer: it changes with every release. Pick one that handles tool calls, with 64k of context or more, and start with the models in Ollama's or LM Studio's own guides.

Will it count against my Claude or ChatGPT limits? No. Requests to another provider don't touch your plan. See Claude Code's usage limits and Codex's for how those work.

References