Claude Code has been one of the bright spots in the AI revolution. Personal friends have vouched for it as an invaluable development tool. Thus, I've been interested in using it and scoping out its capabilities.

However, whether it be due to prudence, caution, or being conservative, I have an aversion towards depending on third parties when it comes to my core workflow, as I view it as basically handing your gonads to someone who is not bound by fiduciary duty. This is a view that has been lost amongst the short-sighted software development culture of today, but has been vindicated by recent history from the behaviors of Oracle and Java, Broadcom and VMWare, and Adobe. Thus, while I am interested in working with Claude Code, it is necessary that it be done on my terms.

Fortunately, it seems that Claude Code supports local LLMs, and there have been many people who have shared a similar perspective as mine and have done the hard work of getting it to work. Unfortunately, though, the information online is not always complete nor up-to-date, so I hope this will be a comprehensive source of doing this, current at least as of the time of this writing. I will be using Claude Code version 2.1.186 on a Debian 13 VM and Ollama version 0.21.0 running locally.

The configuration requires settings for both Claude Code and Ollama, so they are listed as follows, along with a description of why they are needed.

Claude Code

To point Claude Code to a custom URL to access a local LLM, set the environmental variable ANTHROPIC_BASE_URL:

ANTHROPIC_BASE_URL=http://localhost:123/path

Note that the URL can have a custom port and path. Claude Code will send requests to http://localhost:123/path/v1/messages, for example.

By default, Claude Code accesses Claude's LLMs, which required a Claude account, as to be able to track and bill usage. Thus, some more environmental variables need to be set:

ANTHROPIC_AUTH_TOKEN=ollama

CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1

Alternatively, these settings can be set in the ~/.claude/settings.json file:

{

"apiKeyHelper": "~/.claude/api-key-helper.sh",

"env": {

"ANTHROPIC_BASE_URL": "http://localhost:123/path",

"CLAUDE_CODE_ATTRIBUTION_HEADER": "0",

"DISABLE_TELEMETRY": "1",

"DISABLE_ERROR_REPORTING": "1",

"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",

"CLAUDE_CODE_DISABLE_FEEDBACK_SURVEY": "1"

},

"theme": "dark",

"autocompact": {

"tokens": 32000,

"threshold": 28000

},

"model": "gemma-4"

}

Note that autocompact is limiting the context window to be 32000 tokens here. By default, it is 128000. The Ollama settings need to correspond to the limit set here, as we will show below.

Finally, we need to create a custom script, located at the apiKeyHelper setting above. The contents are fairly simple. It's basically a stub to get Claude authentication off your back:

#!/bin/bash

echo "ollama"

Some guides say to set the environmental variable ANTHROPIC_API_KEY. I found that this does nothing and conflicts with apiKeyHelper, so if anything, make sure that this is not set.

Ollama

Ollama has a context window of 4096 by default that is too small for Claude Code. Increase the context length by setting the OLLAMA_CONTEXT_LENGTH environmental variable. Claude Code has a context window of 128000, by default. The range of values to set here would be between 32000 and 128000, depending on the capabilities of your specific graphics card. As I have Ollama running as a job, I do it with the following:

Environment="OLLAMA_CONTEXT_LENGTH=32000"

As a bonus, if you have a reverse proxy in front of Ollama, such as a NodeJS app, it may, by default, not be able to pass the entire request and response to and from Claude Code. Be sure to configure this:

app.use(express.json({ limit: '50mb' }))

app.use(express.urlencoded({ extended: true, limit: '50mb' }))

Claude Code needs Ollama's POST /v1/messages API endpoint exposed so be sure to expose that in the reverse proxy.

That should be it. But, if you're concerned Claude Code may be phoning home, maybe you need to switch to OpenCode... Next up...

Written on July 12, 2026
Updated on November 23, 2025. © Copyright 2026 David Chang. All Rights Reserved. Log in | Visitors