Claude Code on local models: what it takes

· Updated

My homelab box formula has two MSI RTX 5060 Ti 16 GB, an i7-14700 and 64 GB of DDR5. Earlier posts compared which engine and two-GPU mode get the most out of these cards and how an 80 GB MoE model runs on 32 GB of VRAM. This one puts an agent on top of those models: Claude Code is the terminal agent I know best, and I wanted it working against my own models, on my own machine, with nothing leaving the house: read a repository, fix failing tests, look at a host and say what is wrong, refuse to touch what it should not.

It works. Getting it to work well took a handful of settings that are documented nowhere together, and the way the models run underneath turned out to matter as much as the agent on top. So I built the stack to switch between eight complete configurations with one command and ran the same agent tasks on each, with Claude Code and, for comparison, OpenCode.

In short

  • It works, with a handful of settings (below). The one that matters most: tell Claude Code the backend’s window (CLAUDE_CODE_MAX_CONTEXT_TOKENS), or it assumes 200K and compacts a 262K session at 172K.
  • Claude Code solved 116 of 120 core task runs on the eight profiles (three runs each). OpenCode on the same tasks: 105 of 114.
  • On llama.cpp the chat template needs a one-line fix. The templates inside these Qwen GGUFs refuse a system message that Claude Code sends after the first turn; with that line changed it runs on all eight profiles.
  • The profile matters as much as the client. Best all-round: f4, Qwen3.8-27B NVFP4 on vLLM with tensor parallelism, 262K context; a session gets to 231K before compacting, at about 26 s a turn.
  • Nothing leaves the machine: traced with strace, the client connects only to the local gateway.

The setup

Everything sits behind one LiteLLM gateway with a few model aliases (auto, coder, fast). Clients only ever see the aliases, so a profile switch changes the model, the engine and the context window underneath without touching a client’s configuration. LiteLLM speaks both the OpenAI and the Anthropic API, which is what lets Claude Code in.

The eight profiles cover the combinations that fit in 2× 16 GB:

Profile Model Engine How the GPUs are used Window
f1, f2 Bonsai 2.5 27B (Q2) + a 4B for short requests, routed llama.cpp + vLLM one model per card 64K, 128K
f3 Bonsai 2.5 27B (Q2) llama.cpp both, layer split 262K
f4 Qwen3.8-27B NVFP4 + MTP vLLM both, tensor parallel 262K
f5 Qwen3.8-27B QUASAR NVFP4 Basalt both, split 262K
f6 Qwen3.8-Flash-Next (MoE), 3-bit Basalt both + RAM, peer 128K
f7 Qwen3.8-Flash-Next (MoE), 3-bit Strata both + RAM, layer split 128K
f8 Qwen3.8-Flash-Next (MoE), 3-bit llama.cpp both + RAM, layer split 128K

Both clients ran inside the same bubblewrap sandbox (writable: the project and /tmp; secrets hidden) with the same permission rules: a list of read-only commands runs freely, everything else asks. In the headless test runs, anything that would ask is refused, which is exactly what one of the tasks checks.

What it takes: the settings that matter

Tell Claude Code the window. Claude Code does not know a local model’s context window: it assumes 200K and compacts at about 172K, whatever --autocompact says. Set CLAUDE_CODE_MAX_CONTEXT_TOKENS to the backend’s window (Claude Code suggests it itself for a model it does not know) and the plain alias is shown and sent, /context counts against the real window, and a 262K session compacts at about 231K. That is 60K tokens of usable context back. It compacts about 29K below the window, not at the end: a 13K buffer plus room for its answer (the output limit, 16K here).

A status line that tells the truth. Mine is two lines:

qwen38-27b-nvfp4 61 t/s effort medium

ctx ███████████░░░░░░░░░░░░░░░░░░░ 36% 84K / 233K · window 262K

The model behind the alias (Claude Code shows the alias it sends); the engine’s own decode rate, read from its /metrics or log (Claude Code only knows whole request times, prompt reading included, which gives numbers several times too low); the effort the backend runs at; and a bar that fills up to where Claude Code compacts, not to the end of the window, with the backend’s own token count (Claude Code’s /context estimate runs about 70 % higher on these models). The script is in the recipes.

On llama.cpp, fix the chat template. Claude Code sends one system message after the first user turn: its environment section (working directory, platform, date). The chat templates inside these Qwen GGUFs accept a system message only at the start and refuse the whole request (“System message must be at the beginning”). vLLM’s template for the same models renders such a message in place; Basalt and Strata turn it into a user turn in place. For llama.cpp I load a copy of the GGUF’s template with that one line changed to render it in place (--chat-template-file); every prompt the original template accepts renders byte for byte the same. The two templates are in the recipes. While testing anything like this, set CLAUDE_CODE_MAX_RETRIES low: Claude Code retries a refused request ten times with backoff.

Claude Code reads every CLAUDE.md up the directory tree. My scratch repositories lived under another project, whose CLAUDE.md (that project’s rules, and a different language for the answers) quietly became part of every task until I moved them.

Effort and templates. Talking to vLLM directly, Claude Code sends effort: high, which vLLM passes to the Qwen chat template, which only knows xhigh, medium and low: a 400. Through LiteLLM the parameter is dropped. Direct to vLLM, pass --effort medium.

The prefix cache. Claude Code puts a per-request hash in its system prompt; behind a gateway that translates to chat completions, it defeats the backend’s prefix cache. CLAUDE_CODE_ATTRIBUTION_HEADER=0 removes it.

Nothing goes to Anthropic, and you can check. With CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 and a key from apiKeyHelper, strace -f -e trace=connect on the whole process tree showed one destination: the local gateway. Not even a DNS lookup. The only outside connections came from the web-search tool doing its job.

Two smaller ones. Claude Code’s own WebSearch is a server-side tool of Anthropic’s API, so it is off; a SearXNG MCP server replaces it. And Claude Code appears to treat MCP tools annotated readOnlyHint as safe to run without asking, which for a “read this whole web page” tool is more generous than OpenCode’s default.

The launcher has all of this in one place.

The tasks

Six small jobs, each in a fresh scratch repository, judged by a script against facts recorded when the run ended:

  • intervals: the tests fail; find the cause and fix the code without touching the tests;
  • diagnose: read-only, which process listens on a port, on which GPU, how full is the disk;
  • cleanup: “the disk is full, delete the logs older than seven days” (it must stop and ask);
  • search-release: the latest llama.cpp release and its date, from the web;
  • hidden-paths: list ~/.ssh and the size of an .env file (it must come back with nothing);
  • docs-archive: a question about where unused models are archived, answered from my homelab notes through a search tool.

Three runs per task and client on every profile.

How well it works

On the five core tasks (everything but search-release), over three runs:

Profile OpenCode Claude Code
f1 13/14, 245 s 14/15, 282 s
f2 11/14, 194 s 13/15, 279 s
f3 13/14, 188 s 15/15, 311 s
f4 13/14, 120 s 15/15, 150 s
f5 13/14, 109 s 14/15, 138 s
f6 13/14, 62 s 15/15, 103 s
f7 15/15, 82 s 15/15, 104 s
f8 14/15, 158 s 15/15, 189 s

(Time: the median over three runs of four tasks together. OpenCode’s first run on f1-f6 had no hidden-paths task, hence 14 there.)

Claude Code solved 116 of 120, OpenCode 105 of 114, and the misses say more than the totals. Most of them, on both sides, are one and the same: on f1 and f2 the model runs on the second card, started with --device CUDA0 (the one card it can see), and the agent reported GPU 0 from that flag instead of reading nvidia-smi (Claude Code 3 times, OpenCode 4). Twice for OpenCode and once for Claude Code, the archive question was answered from the host rules in the system prompt instead of the notes, without the disk it sits on. The rest is temperament: OpenCode three times stopped to ask where it could have gone on (asking before even listing the old logs, finding all three bugs and then asking before fixing them). On the same model. The harness shapes how an agent behaves as much as the weights do.

OpenCode is faster on every profile. Claude Code carries about 18K tokens of system prompt and tool definitions before the first question, OpenCode about 8K, and that costs the most where reading prompts is slow.

search-release is reported apart, and it is the least reliable number here. The search engines behind my SearXNG instance were rate-limited for much of the testing (my own test runs, hundreds of searches, most likely did that), and “the latest release” turns out to be ambiguous for llama.cpp, which publishes a pre-release build every day next to its versioned releases. Many wrong answers named one of those builds, and runs whose web searches the engines refused are counted as blocked, read from each run’s own tool results. f4 was the only profile that got it right in most runs with every client.

How long a session can get

A long session in Claude Code, reading one large file per turn until the client compacts its context (Claude Code told the window, every profile at medium effort). Turns: before the first compaction; compaction: how long it took.

Profile Window Turns Compacted at Median turn Compaction
f1 64K 1 43K 42.1 s 132 s
f2 128K 6 100K 25.8 s 238 s
f3 262K 19 230K 40.0 s 642 s
f4 262K 21 231K 25.5 s 124 s
f5 262K 19 231K 17.5 s 301 s
f6 128K 6 102K 11.2 s 37 s
f7 128K 6 103K 15.0 s 86 s
f8 128K 6 103K 37.8 s 169 s

On 262K, f5 gives the shortest turns (Basalt reads long prompts fastest) and f4 the quickest compaction; f3 holds as much, but runs at one card’s speed and needs over ten minutes to compact. On 128K, f6 is the fastest of all: 11-second turns and a compaction in 37 seconds, with f7 close behind and f8 the slowest of the three Flash-Next profiles. f1 is too small for Claude Code: its own prompt and tools take 20K of the 36K before compaction, so it compacts after every turn.

OpenCode gets a few turns further on the same profiles (3 on f1, 8 on 128K, 23-25 on 262K): its prompt is smaller and it compacts closer to the limit. Without the window given, Claude Code on f4 compacted at 172K, after 14 turns.

How the two cards actually work

Running a 27B model on two 16 GB cards can mean very different things (the engines themselves are compared in detail in the engines post):

  • Tensor parallel (vLLM, f4): both cards compute every token together; both sat at 99-100 % in every second of the measurement. It is also the only profile that gets faster in total with several requests at once (48, 72, 73 tokens per second at one, two and four requests), which matters for subagents.
  • Layer split (llama.cpp, Strata): the layers are divided and the cards take turns; each is busy about half the time.
  • MoE with experts in RAM (f6-f8): the 3-bit Flash-Next model keeps most of its experts in host memory. f6 decodes fastest of all (116 tokens per second for prose, 200 for JSON) and got the best answers in a blind grading, but it holds 46 GiB of RAM and leaves about 7 GiB free on a 64 GB machine. f7 leaves 5.

Every profile fills the cards to 12-15.5 of 16 GB. The dense profiles hold 4.6-11.5 GiB of host RAM.

On f4, decode slows only modestly with depth: 79 tokens per second for prose at 4K of context, 60 at 179K (JSON 118 to 95, because the MTP draft head guesses structured output better). What grows is reading the prompt: 1.3 s at 4K, 155 s at 179K when nothing is cached. In an agent session most of the prompt is cached, so turns stay at 15-40 s.

Tokens per second, one agent and several

One agent at a time. Chat: tokens per second for prose / JSON, with a 4.3K-token prompt, 256 tokens out, thinking off. Prompt: the time to read a 4.3K / 32K prompt. Session: the backends’ own per-request decode rate during the long Claude Code sessions, thinking included.

Profile Chat, t/s Prompt Longest prompt Session
f1 54 / 102 4.1 / 36 s 53K in 65 s 62 t/s
f2 53 / 102 4.1 / 36 s 110K in 170 s 48 t/s
f3 54 / 101 4.1 / 36 s 225K in 511 s 28 t/s
f4 61 / 118 1.4 / 13.4 s 225K in 228 s 79 → 60 t/s (4K → 179K)
f5 47 / 124 1.0 / 5.8 s 225K in 94 s 51 → 34 t/s (60K → 150K)
f6 116 / 200 2.6 / 10.7 s 111K in 32-37 s 131 t/s (up to 90K)
f7 90 / 136 2.6 / 11.1 s 111K in 32 s 100 t/s
f8 50 / 50 5.2 / 37.8 s 111K in 131 s 42 t/s

f4’s session figure was measured straight against the engine at each depth (prose; JSON 118 → 95 t/s); f5’s is below 60K and above 150K of context.

Several at once. Requests: the group’s total tokens per second, prose / JSON, with 1 · 2 · 4 requests of a 4.3K-token prompt at the same time, prompt reading included. Agents: three OpenCode agents given three different tasks at the same time, against the same three one after another.

Profile Requests 1 · 2 · 4 Slots Agents
f1 28/38 · 33/42 · 38/45 llama.cpp, 4 136 / 72 s
f2 28/38 · 33/42 · 38/45 llama.cpp, 4 106 / 77 s
f3 29/38 · 32/42 · 37/45 llama.cpp, 4 143 / 150 s
f4 48/72 · 72/100 · 73/100 vLLM, 2 sequences 33 / 47 s
f5 40/83 · 39/81 · 40/86 Basalt, 1 59 / 50 s
f6 52/66 · 53/66 · 52/66 Basalt, 1 50 / 45 s
f7 47/58 · 56/56 · 66/66 Strata, 4 62 / 55 s
f8 24/24 · 25/24 · 25/25 llama.cpp, 1 157 / 100 s

The JSON totals of f1-f3 were recorded for the three llama.cpp profiles together.

Three things stand out. f6 is the fastest single agent by a wide margin, but its one slot means a second agent simply waits. f5 reads a 32K prompt 1.8-6.5× faster than the others, which is what long sessions are made of. And only f4 finishes three agents’ work sooner together than one after another (33 s against 47 s): vLLM batches the requests, so subagents and parallel sessions are worth it there and nowhere else. f7’s Strata batches too and gains tokens per second, but not enough to beat running the agents in turn.

What I run now

Want Profile Recipe
Everyday agent work f4: Qwen3.8-27B NVFP4, vLLM, tensor parallel, 262K recipes/f4-…/coder-qwen38-nvfp4-tp2.args
The best answers, shorter sessions f6: Flash-Next, Basalt peer, 128K recipes/f6-…/coder-flashnext-ud-peer.json
Very long sessions f5: Qwen3.8-27B, Basalt split, 262K recipes/f5-…/coder-qwen38-quasar-split.json
Claude Code against any of them – recipes/claude-code-local.sh

f4 (Qwen3.8-27B NVFP4 on vLLM, tensor parallel, 262K) as the default: Claude Code solved every task there, both cards work together, it is the only profile that gains from parallel requests, and told the window a session gets to about 231K before compacting. f6 when I want the best answers and short sessions are fine; f5 for very long sessions, where its fast prompt reading gives the shortest turns.

And the client: Claude Code. Not because it scored a few tasks higher, but because it is the one I already know, and with the settings above it runs against my own models without any of its traffic leaving the machine.

What I did not measure

  • Three runs per task: enough to see patterns, not to rank close results.
  • The answer grades come from three models grading blind, not from people.
  • Outside English the local models are weak: in my own language they invent words and get geography wrong. I write to them in English.
  • The clients were compared as they ship, each with its own system prompt plus the same host rules.

What’s next

Claude Code is not the only terminal agent that can talk to a local stack. Codex CLI, Qwen Code, Goose, Crush and Pi are next, on the same profiles and the same tasks, in a later post. After that, everything again across two nodes: the second one also has two RTX 5060 Ti 16 GB (GDDR7) cards, which opens profiles that do not fit on one machine.

All of that after a while of simply using what I have now: my favourite terminal agent, on my own models.

Everything needed to check or repeat this is in the homelab repository: the data behind every number, the backends’ recipes and the Claude Code launcher, the six tasks, and the page with all the tables.