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.
- It works. Claude Code read a file, found a bug and fixed it in seven model requests and about 14 seconds of model time, using its normal tools (reading and editing files).
- The context window is the trap. Claude Code sends about 9,900 tokens of instructions and tool definitions before any of your code. With Ollama's 8,192-token window, the prompt was cut to 4,098 tokens and the agent made no change at all. With a 64K window it worked first time.
- Context costs memory. Raising Qwen3-Coder from 8K to 64K tokens of context took its memory from 21.9 GB to 45.0 GB, with four people able to use it at once: about 98 KB per token of context per user.
- Agents resend almost everything. After the first request, 98–99.7% of each request's input was the same text as before. Ollama reuses that work, so those requests took 1–2 seconds instead of 7.
- It's cheap. At our prices, the whole fix cost $0.0023, with repeated (cached) input billed at a tenth of the normal input price. At full price for every input token it would have cost $0.0090.
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
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.
| 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
- One small task. A one-line fix shows the mechanics and the cost structure, not how well open models handle large, multi-file work. Quality against hosted frontier models was not measured.
- One model and one Mac. Larger coding models and mixture-of-experts models with different attention layouts need different amounts of memory per token.
- Claude Code only, end to end. The other agents' request formats were tested against the same API, but not run through a full task.
- Software moves fast. Agent prompts grow with each release; check the first-request size again after upgrading.
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.