TellWorldAI World Archive
Ask中文

Home›Practice›Practice

Practice

Running Claude Code against Ollama models

Connect Claude Code to local or cloud models through Ollama's Anthropic-compatible API. Covers one-command launch, manual environment setup, context length, and tool-calling limits.

Who this is for and what you will be able to do

This guide is for people who want Claude Code's workflow but prefer to keep code away from a remote model API, or who want to try a local model first. After reading it you will be able to start Claude Code through Ollama, connect either a local server or Ollama's cloud, and judge whether a model can handle your repository.

What the integration is

Ollama exposes an API that is compatible with Anthropic's. Through it, Claude Code can use models running on your own machine as well as models hosted in Ollama's cloud[1]. File reading and editing, command running, and tool calling then work with any compatible model.

Through Ollama, Claude Code can chat about a repository or task, run commands under its normal permission flow, read and edit project files, use subagents, perform web search and web fetch, take images and screenshots, and apply thinking controls where the model supports them[1]. Tool calling and thinking depend on compatible models.

Preparation: a machine and a model

The simplest path is to install Claude Code and pick a model. The model needs enough context to hold your repository. Cloud models can be used without downloading anything. For local models, set the context window to 64k or more[1]. The larger the repository, the more this matters[1].

Because Claude Code relies on tool calls, choose a model that supports tools. Basic chat and file edits work with compatible models, but hosted WebSearch and some advanced tool controls are not fully supported[1]. A model that cannot call tools may still chat, but it cannot take on the full workflow.

Choosing a connection path

There are three ways in, and each suits a different situation.

  • If Ollama is already installed locally, ollama launch claude starts everything in one command and walks you through choosing a model[1].
  • If you do not want Ollama on the machine, connect to the cloud directly. You only need Claude Code and an API key in OLLAMA_API_KEY[1].
  • If you want full manual control, install Claude Code yourself and set environment variables that point at the local service[1].

Option one: one-command launch

If Ollama is already installed on your machine, the most direct route is[1]:

ollama launch claude

Option two: connect straight to Ollama's cloud

You can also skip the local install and connect to the cloud directly. Install Claude Code, place your API key in OLLAMA_API_KEY, and you do not need Ollama itself[1].

In Bash or Zsh, the command looks like this[1]:

ANTHROPIC_BASE_URL=https://ollama.com \
ANTHROPIC_AUTH_TOKEN="$OLLAMA_API_KEY" \
ANTHROPIC_API_KEY="" \
claude --model glm-5.3-flash

ANTHROPIC_AUTH_TOKEN provides bearer authentication. Claude settings can override shell variables, so if you put a base URL or credential in a settings file, update it there too. Then run /status to check the connection[1].

Option three: manual setup with a local Ollama server

For a fully manual setup, install Claude Code on macOS or Linux first[1]:

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

Next, set three environment variables so Claude Code points at the local Ollama server[1]:

export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434

Then start Claude Code with claude --model qwen3.5 to run that local model[1].

If you would rather not export anything, put the variables in front of the command on one line[1]:

ANTHROPIC_AUTH_TOKEN=ollama ANTHROPIC_BASE_URL=http://localhost:11434 ANTHROPIC_API_KEY="" claude --model kimi-k2.7-code:cloud

Running without interaction: scripts, Docker, and CI

For scripts, Docker, or CI, add --yes, as in[1]:

ollama launch claude --model gemma4:cloud --yes -- -p "how does this repository work?"

The --yes flag skips the selectors, pulls the model when it is needed, and requires --model. Anything after -- goes straight to Claude Code[1], so the -p prompt flag in the example is handled by Claude Code itself.

Permissions: automation needs an extra check

Claude Code asks for permission on most actions, and that flow still applies when you use Ollama[1]. If the bot or script must work unattended, configure permission rules. The other option is to pass --dangerously-skip-permissions inside an isolated environment, which skips the checks and should stay confined to that environment[1].

Scheduled prompts and Telegram

Inside Claude Code, /loop repeats a prompt or slash command at a set interval, in the form /loop <interval> <prompt or /command>[1]. The official examples check open PRs every 30 minutes, research AI news every hour, and triage new GitHub issues every 15 minutes[1].

To talk to a Claude Code session through a Telegram bot, install the Telegram plugin, create a bot with BotFather, and launch with[1]:

ollama launch claude -- --channels plugin:telegram@claude-plugins-official

Checking that the setup works

Once connected, do not start with code changes. Run /status to confirm that the connection and the model are the ones you chose[1]. Then ask a read-only question, such as a summary of the repository layout, to see whether Claude can read files and answer sensibly. That separates a connection problem from a model or task problem. Only after that should you ask for a small file edit, which exercises tool calling[1].

Limits and common problems

  • Context runs out. A large repository can overflow a small window, so raise the model's context length to 64k or more[1].
  • Tools are missing. Pick a model that supports tools. Hosted WebSearch and some advanced tool controls are not fully supported[1].
  • Settings override the environment. A base URL or credential in a settings file takes precedence over the shell, so check with /status after changes[1].
  • Auto-approval is risky. Use --dangerously-skip-permissions only in an isolated environment[1].

Next steps

For details such as configuring web search and the Anthropic compatibility notes, see the Ollama documentation[1].

Adapted from the Claude Code integration page in the Ollama documentation[1], released under the MIT License.

Sources

  1. 1

Cite this page: Running Claude Code against Ollama models. TellWorld, https://www.tellworld.net/practice/practice-claude-code-ollama. Updated 2026-11-14

Related news

View all