DEV Community

Cover image for Claude Code on local models: what it takes
Gancho Stoychev
Gancho Stoychev

Posted on Originally published at gshell.dev on

Claude Code on local models: what it takes

My homelab box formula has two MSI RTX 5060 Ti 16 GB, an i7-14700 and 64 GB of DDR5. Earlier posts covered sandboxing Claude Code on Ubuntu and which engine and two-GPU mode get the most out of these cards. This one puts the two together: 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 few settings (below). The most important: tell Claude Code the backend's context window with CLAUDE_CODE_MAX_CONTEXT_TOKENS. Without it, Claude Code assumes 200K and compacts a 262K session at about 172K.
  • Claude Code solved 116 of 120 core task runs; OpenCode solved 105 of 114.
  • On llama.cpp, a one-line chat template change makes the Qwen GGUF templates accept the system message that Claude Code sends after the first turn. With it, the full client runs on every profile.
  • 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 about 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

Set the context window. Claude Code does not know a local model's context window, so without help it assumes 200K and compacts at about 172K. Setting CLAUDE_CODE_MAX_CONTEXT_TOKENS to the backend's window fixes this: the alias is still sent as auto, /context counts against the real window, and a 262K session compacts at about 231K, which gives back about 60K tokens. Compaction happens about 29K below the window: a 13K buffer plus a 16K output limit.

The llama.cpp chat template. Claude Code's full mode sends its system instructions as a system message after the first user turn. The Qwen GGUF templates refuse that. I load a copy of each template with one line changed (--chat-template-file); the rest of the template is byte-identical. On profiles that use Basalt and Strata, the message is turned into a user turn instead. Claude Code also retries a refused request ten times with backoff, so set CLAUDE_CODE_MAX_RETRIES low while testing.

Status line. A two-line display shows the model alias, the coder's decode rate, the effort level and the profile. A second line is a context bar that fills up to where Claude Code compacts:

qwen38-27b-nvfp4  61 t/s  effort medium
ctx ███████████░░░░░░░░░░░░░░░░░░░ 36%  84K / 233K · window 262K
Enter fullscreen mode Exit fullscreen mode

acceptEdits also deletes. The mode that lets an agent edit files in the project without asking also lets it run rm, mv and cp there. In one run the model deleted the logs it was supposed to ask about. Explicit ask rules for those commands win over the mode.

The full client 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. Talking to vLLM directly, Claude Code sends effort: high, which the Qwen chat template rejects with 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. Time is the median over three runs of four tasks together.

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

Claude Code solved 116 of 120 core runs; OpenCode solved 105 of 114. Most of the misses were the same: on f1 and f2 the model ran on the second card, and the agents reported GPU 0 from the launch flag instead of checking nvidia-smi. OpenCode sometimes stopped to ask questions it could have answered itself. The difference is partly temperament: on the same model, the harness shapes how an agent behaves as much as the weights do.

Claude Code's system prompt is larger (about 18K tokens against OpenCode's 8K), which 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, most likely by my own test runs, and llama.cpp publishes a pre-release build every day next to its versioned releases, so "the latest release" is ambiguous. Most "wrong" answers named one of those builds. 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 full Claude Code, reading one large file per turn until the client compacts its context, at medium effort with the window set:

Profile Window Turns before compacting Compacted at Median turn Compaction took
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 has the shortest turns and f4 the fastest compaction. On 128K, f6 is fastest overall. f1 is too small for Claude Code's full prompt, compacting after every turn. Without the window set, the same test 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 and both sit at 99–100 %. It is also the only profile that gains total throughput from several requests at once, 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 but 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. 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 (one chat: a 4.3K-token prompt, 256 tokens out; "session": the backends' own decode rate during the long Claude Code sessions):

Profile Chat, prose / JSON t/s Prompt reading, 4.3K / 32K Longest prompt read Session decode
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

Several at once (total tokens per second of the group, prose / JSON, with 1, 2 and 4 simultaneous requests; and three OpenCode agents given three different tasks, run in parallel versus one after another):

Profile Requests 1 · 2 · 4 Slots 3 agents: parallel / sequential
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 seq 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

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. Only f4 finishes three agents' work sooner together than one after another, because vLLM batches the requests.

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 is the default: it solved everything with every client, both cards work together, it is the only profile that gains from parallel requests, and with the window set a session gets to about 230K before compacting. f6 is for the best answers and short sessions; 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

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.

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.

Originally published at gshell.dev.

Top comments (0)