Datagram whitepaper

Coding Agents on Private Hardware: Claude Code and Open Models on Apple Silicon

November 23, 2026

Executive summary

Coding agents such as Claude Code, goose, Cline and Hermes can run entirely on open models on one Mac, with no code leaving private hardware. We connected Claude Code 2.1.330 to Qwen3-Coder 30B on a Mac Studio M5 Max through our API and measured what it takes.

Our advice: give agents a model with at least 64K tokens of context and good tool use, budget memory for the context, and bill or measure cached input separately, because it is most of what an agent sends.

Why run an agent on private hardware

A coding agent reads your files, your terminal output and often your secrets in configuration files, and sends them to a model with every step. With a hosted model, all of that leaves your network. For code under NDA, regulated data, or companies that simply don't allow source code to leave, the model has to run on hardware you control or trust.

Open coding models are now good enough for everyday agent work: small fixes, tests, refactors, explaining code. They are not as strong as the largest hosted models on hard problems, and this paper doesn't claim otherwise. It measures what it takes to run them well.

Setup

Part What we used
Mac Mac Studio M5 Max, 128 GB, in our datacenter
Model server Ollama 0.40.17, 4 requests at once (OLLAMA_NUM_PARALLEL=4)
Model Qwen3-Coder 30B-A3B (qwen3-coder:30b, GGUF Q4_K_M, a mixture-of-experts model with 3B active parameters)
Agent Claude Code 2.1.330, pointed at our API with ANTHROPIC_BASE_URL
API Datagram's API, passing Anthropic Messages requests to Ollama's Anthropic-compatible endpoint
Task A Python file with return a + b in a function called mul: "Fix the bug in calc.py."

Claude Code speaks Anthropic's Messages format, not OpenAI's. Ollama 0.40 understands that format too, including streaming and tool calls, so no translation layer was needed. Ollama doesn't provide Anthropic's token-counting endpoint; Claude Code falls back to an estimate, and our API returns one.

The context window trap

Ollama gives every model a context window of its own default unless told otherwise; ours was set to 8,192 tokens, which suits chat. Claude Code's first request was 9,911 tokens: its system instructions and the definitions of its tools, before reading a single file.

Context window What reached the model Result
8,192 tokens 4,098 tokens (the start of the prompt was cut) No change made: most of the instructions were missing
65,536 tokens 9,911 tokens, then the file and tool results Bug found and fixed

The failure is silent: no error, just an agent that does nothing useful. Any agent setup should check that the model's window is well above the agent's first prompt. Claude Code also needs to be told the window size (CLAUDE_CODE_MAX_CONTEXT_TOKENS), or it assumes a far larger one and won't compact the conversation in time. Hermes Agent refuses to start with less than 64,000 tokens.

We created a 64K version of the model (qwen3-coder:30b-64k) with a two-line Ollama Modelfile (PARAMETER num_ctx 65536). It shares the same weights on disk, so it costs no extra storage, only memory while loaded.

Context costs memory

A 64K context window doubles the memory a coding model needsQwen3-Coder 30B (Q4_K_M) loaded with 4 parallel slots, GB of GPU memory8K context8K context: 21.9 GB21.9 GB64K context64K context: 45.0 GB45.0 GB
Datagram measurements, Mac Studio M5 Max 128 GB, Ollama 0.40.17, 4 parallel slots, 2026-11-23.

The extra 23.1 GB is the key-value cache: what the model remembers about every token in its window, for each of the four requests Ollama can serve at once. Qwen3-Coder has 48 layers with 4 key-value heads of 128 values each, so each token takes 48 × 2 × 4 × 128 × 2 bytes = 98 KB. That matches the measurement: 4 × 57,344 extra tokens × 98 KB ≈ 23 GB.

For one user's context of… Memory (this model)
8,192 tokens 0.8 GB
65,536 tokens 6.4 GB
262,144 tokens (the model's maximum) 25.8 GB

Multiply by the number of people the server should handle at once. On a 128 GB Mac, a 64K coding model for four users fits comfortably beside other models; a 256K window for four users would not.

Agents resend almost everything

Every step of an agent sends the whole conversation again: instructions, tools, files read so far, and the new tool result. Ollama keeps the model's work on the start of the prompt (the prompt cache) and only processes what is new.

After the first request, each agent step took one to two secondsClaude Code fixing a one-line bug, model already loaded: seconds per request and new (uncached) input tokensRequest 19,911 newRequest 1: 7.2 s7.2 sRequest 2100 newRequest 2: 1.2 s1.2 sRequest 3140 newRequest 3: 0.9 s0.9 sRequest 4154 newRequest 4: 0.8 s0.8 sRequest 573 newRequest 5: 1.2 s1.2 sRequest 629 newRequest 6: 2.0 s2.0 sRequest 7198 newRequest 7: 0.9 s0.9 s
Datagram measurements, Mac Studio M5 Max 128 GB, Ollama 0.40.17, 4 parallel slots, 2026-11-23.
Request New input tokens Cached input tokens Output tokens
1 9,911 0 47
2 100 9,930 77
3 140 10,053 51
4 154 10,243 45
5 73 10,441 84
6 29 10,597 151
7 198 10,675 46
Total 10,605 61,939 501

Of 72,544 input tokens, 85% were cached. The first request read 9,911 tokens in about 7 seconds (roughly 1,400 tokens a second including the first words of the answer); later steps took 0.8–2.0 seconds. When the model wasn't loaded yet, the first request took 17.2 seconds.

Each API format reports this differently, which matters for anyone billing or measuring agent use. In Ollama 0.40.17:

Format What the usage numbers mean
Anthropic Messages input_tokens is only the new part; cached tokens are in cache_read_input_tokens
Ollama native prompt_eval_count is the whole prompt; prompt_eval_cached_count is the cached part
OpenAI chat prompt_tokens is the whole prompt; cached_tokens is reported as 0 even when the cache was used

A meter that only reads the Anthropic input_tokens would see 10,605 input tokens for this task and miss the other 61,939.

Cost

At our API prices for this model ($0.12 per million input tokens, $0.50 per million output tokens, cached input at a tenth of the input price):

Tokens Cost
New input 10,605 $0.0013
Cached input 61,939 $0.0007
Output 501 $0.0003
Whole task $0.0023

Charging every input token at the full price would make the same task $0.0090, four times as much. A working day of agent use typically means hundreds of such steps on much larger files; the ratio between cached and new input matters more than the per-token price.

Practical guidance

If you are… Do this
Setting up an agent Use a model with at least 64K tokens of context and reliable tool calls (Qwen3-Coder is a good start). Tell the agent the window size.
Running the model server Budget memory for context: about 100 KB per token per user for a model like Qwen3-Coder. Create long-context variants instead of raising the default for every model.
Billing or tracking use Read cached tokens from each format separately. Most of an agent's input is cached.
Choosing hardware One Mac Studio with 128 GB comfortably serves a 64K coding model to four people at once beside other models.

Step-by-step setup for Claude Code, goose, Cline, Roo Code, Continue, JetBrains, Hermes and Buzz is in our AI API guides.

Limitations

Try it on our private AI API

The same models on our own Apple Silicon, by the token or by the image. Prompts and results are never stored.