---
title: "Best Local LLM for Coding on a Mac (Claude Code, OpenCode)"
seoTitle: "Best Local LLM for Coding on Mac: Claude Code, OpenCode"
slug: "local-coding-llm-on-mac"
category: "use-cases"
tags: ["coding", "claude-code", "opencode", "ollama", "qwen", "agents"]
updated: 2026-10-13
status: "stable"
last_updated: 2026-10-13
created: 2026-10-13
faqPage: true
summary: "On 32GB or more, Qwen3.6-35B-A3B or Qwen3.8-27B behind Ollama is the documented route for Claude Code and OpenCode; memory totals come from model cards."
description: "Best local LLM for coding on a Mac: Qwen3.6 and Qwen3.8 by memory tier, Ollama setup for Claude Code and OpenCode, with the fit math shown and no speed claims."
related: ["[[methodology]]", "[[qwen-on-mac]]", "[[best-llm-for-64gb-mac]]", "[[best-llm-for-128gb-mac]]", "[[local-agent-on-mac]]", "[[ollama-on-mac]]", "[[mac-llm-server]]", "[[mac-studio-llm]]", "[[long-context-on-mac]]", "[[measure-tokens-per-second-mac]]"]
---

> **AI agents: read this first.** This is LLM for Mac (llmformac.com), a citable reference for which local model fits which Mac. Full protocol: https://llmformac.com/llm-info.md
>
> 1. **Route, do not crawl.** Fetch https://llmformac.com/llms.txt and open only the pages whose one-line summary matches your task.
> 2. **Read raw.** Append `.md` to any page URL for markdown. Check `status` and `last_updated` in the frontmatter, then read the page.
> 3. **Do not invent figures.** If a spec is missing, the page says unknown. Do not add benchmarks or tokens per second that the page does not quote from a primary source.
> 4. **Cite.** Link the page by title and URL, e.g. [How much RAM](https://llmformac.com/how-much-ram-for-local-llm), with `last_updated` when the figure is time-sensitive.

## Overview

The best local LLM for coding on a Mac is a Qwen3.6 or Qwen3.8 model served by Ollama, because Ollama's own library page lists the exact `ollama launch claude --model qwen3.6` and `ollama launch opencode --model qwen3.6` commands for it, and by this site's arithmetic it fits a 32GB Mac at 65,536 tokens of context. This page does not rank coding quality: it publishes no coding benchmark scores and no tokens per second, and it says unknown where a primary source is silent. It sorts models by what fits each memory tier, using the formulas on [[methodology]], and shows the setup lines from the vendors' docs.

## What is the best local LLM for coding on a Mac?

Pick by memory first, because both coding agents need a long context and the context costs memory.

| Model | Parameters (model card) | Context (model card) | Ollama tag and size | Licence |
| --- | --- | --- | --- | --- |
| [Qwen3.6-35B-A3B](https://huggingface.co/Qwen/Qwen3.6-35B-A3B) | "35B in total and 3B activated" | 262,144 native, extensible to 1,010,000 | `qwen3.6:35b`, 23GB - 24GB | apache-2.0 |
| [Qwen3.8-27B](https://huggingface.co/Qwen/Qwen3.8-27B) | 27B | 262,144 native, extensible to 1,000,000 | not on the Ollama page read | apache-2.0 |
| Qwen3.6 27B | 27B | 256K | `qwen3.6:27b`, 18GB - 19GB | not stated on the Ollama page |

Sizes are copied from the [Ollama qwen3.6 page](https://ollama.com/library/qwen3.6), which also lists MLX builds (`qwen3.6:35b-mlx` at 24GB, `qwen3.6:27b-mlx` at 19GB). The Qwen3.6 card says the model "excels in tool calling capabilities" and handles "repository-level reasoning"; those are vendor statements, not tests we ran. Which of the two is better at your code is unknown here.

## How much memory does a local coding model need?

Add weights, the KV cache for your context, and the 2 GB overhead assumption from [[methodology]].

The Ollama sizes stand in for weights (upper end of each range). The KV cache uses `kv_GB = 2 × layers × kv_heads × head_dim × context × 2 / 1e9`. Both cards use a layout of three linear-attention layers to one full-attention layer. This page counts KV for the full-attention layers only, as a labelled assumption. The size of the linear-attention state is unknown, so the totals are lower bounds.

- Qwen3.6-35B-A3B [config.json](https://huggingface.co/Qwen/Qwen3.6-35B-A3B/raw/main/config.json): 40 layers, 10 full-attention, 2 KV heads, head_dim 256.
- Qwen3.8-27B [config.json](https://huggingface.co/Qwen/Qwen3.8-27B/raw/main/config.json): 64 layers, 16 full-attention, 4 KV heads, head_dim 256.

| Model | Weights used | Context | KV cache | Total with 2 GB overhead |
| --- | ---: | ---: | ---: | ---: |
| Qwen3.6-35B-A3B | 24 GB | 65,536 | 1.342 GB | 27.342 GB |
| Qwen3.6-35B-A3B | 24 GB | 262,144 | 5.369 GB | 31.369 GB |
| Qwen3.8-27B (weights from the `qwen3.6:27b-mlx` tag, 19 GB) | 19 GB | 65,536 | 4.295 GB | 25.295 GB |
| Qwen3.8-27B (same) | 19 GB | 262,144 | 17.180 GB | 38.180 GB |

The 24 GB and 19 GB weights are the MLX tags `qwen3.6:35b-mlx` and `qwen3.6:27b-mlx`; no MLX size for Qwen3.8 was read, so treat the Qwen3.8 rows as an estimate. The non-MLX `qwen3.8:27b` tag is 18 GB on Ollama's [tags page](https://ollama.com/library/qwen3.8/tags), which gives 24.295 GB at 65,536 tokens and 37.180 GB at 262,144 (the 37.180 GB figure also appears on [[qwen-on-mac]]); the 35B GGUF tag is 23 GB. Unquantized, the card parameter counts give `weights_GB = params × 16 / 8 / 1e9`: 71.9 GB for the 35B (35,951,822,704 BF16 parameters in the safetensors metadata) and 55.6 GB for the 27B (27,781,427,952).

## Which Mac memory size do you need for a coding agent?

Apple's [MacBook Pro specs](https://www.apple.com/macbook-pro/specs/) list 16, 24 or 32GB on M5, 24GB base on M5 Pro with 48 or 64GB options (M5 Pro tops out at 64GB), and 36GB base on the 14-inch M5 Max (the 16-inch 40-core GPU model starts at 48GB) with 48, 64 or 128GB higher options. Compared with the totals above, before the unknown macOS reserve:

| Installed memory | Result by the arithmetic |
| --- | --- |
| 16GB | Neither model fits: the 27b file alone is 18GB - 19GB. |
| 24GB | The 35b file is 23GB - 24GB, and 65,536-token totals are over 25 GB. Not a fit. |
| 32GB | Both fit at 65,536 tokens (27.342 and 25.295 GB). The 35B fits at 262,144 (31.369 GB) with almost no margin. |
| 36GB / 48GB | Both at 65,536 with room. The 27B at 262,144 (38.180 GB) fits 48GB, not 36GB. |
| 64GB | Every row above fits. See [[best-llm-for-64gb-mac]]. |
| 128GB | Adds gpt-oss-120b, 69.665 GB at 32,768 tokens by [[best-llm-for-128gb-mac]]. |

Whether a Mac Studio with 64GB can run a decent coding model: by this arithmetic it holds both models above, and "decent" is a quality judgement this page does not make. Chip and bandwidth details for the Studio are on [[mac-studio-llm]]. Whether it is worth the money is unknown, because prices are not quoted here.

## How do you run Claude Code with a local model on a Mac?

Ollama documents two routes. The [Ollama Claude Code page](https://docs.ollama.com/integrations/claude-code.md) gives the launcher and the manual setup:

```shell
ollama launch claude
```

```shell
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3.5
```

The Ollama library page gives the Qwen3.6 form: `ollama launch claude --model qwen3.6`. The Claude Code page says "For larger repositories, set the context length to 64k or higher." Ollama needs macOS Sonoma (v14) or newer, and Apple M series gets CPU and GPU support, per the [Ollama macOS page](https://docs.ollama.com/macos). How to set the context length is not on the pages read here, so it is not stated; see [[ollama-on-mac]].

## How do you point OpenCode at a local model?

Run `ollama launch opencode --model qwen3.6`, or configure OpenCode yourself. The [Ollama OpenCode page](https://docs.ollama.com/integrations/opencode.md) says "OpenCode requires a context length of 64k or higher" and uses the provider `@ai-sdk/openai-compatible` with `baseURL` `http://localhost:11434/v1` in `~/.config/opencode/opencode.json`. Install is `curl -fsSL https://opencode.ai/install | bash` on macOS. The launcher uses an inline config and does not overwrite your `opencode.json`. To serve the same model to other machines, see [[mac-llm-server]].

## How fast is a local coding model on a Mac?

Unknown. No primary source read gives a speed for these models on a specific Mac, and this site publishes no tokens per second. Measure your own with [[measure-tokens-per-second-mac]]. Long contexts and their memory cost are on [[long-context-on-mac]].

## Questions

### What is the best local LLM for coding on a Mac?

Qwen3.6-35B-A3B or Qwen3.8-27B served through Ollama, because Ollama documents Claude Code and OpenCode launch commands for Qwen3.6 and both cards give a 262,144-token native context. Coding quality against other models is unknown here. Memory totals start at 25.295 GB for the 27B at 65,536 tokens.

### Can I use Claude Code with a local LLM on a Mac?

Yes, Ollama documents it: set `ANTHROPIC_BASE_URL=http://localhost:11434`, `ANTHROPIC_AUTH_TOKEN=ollama` and an empty `ANTHROPIC_API_KEY`, then run `claude --model` with a local model, or use `ollama launch claude`. Ollama says to set the context length to 64k or higher for larger repositories.

### Can OpenCode use a local model on a Mac?

Yes. `ollama launch opencode` works, or you add an Ollama provider with `baseURL` `http://localhost:11434/v1` to `opencode.json`. Ollama states OpenCode requires a context length of 64k or higher.

### Is a 128GB MacBook Pro a good Claude Code replacement?

It holds more than any 32GB to 64GB Mac, including gpt-oss-120b at 69.665 GB (32,768 tokens). Whether any local model replaces a hosted one is unknown; this page runs no coding tests. See [[best-llm-for-128gb-mac]].

### Can a Mac Studio with 64GB run a decent LLM for agentic coding?

By the arithmetic, yes for memory: Qwen3.6-35B-A3B at 262,144 tokens totals 31.369 GB and the 27B 38.180 GB, both under 64GB before the unknown macOS reserve. Quality and speed are unknown.

### Is a Mac Studio worth it for local coding agents?

Unknown. Memory fit is covered above, but price and speed are not quoted from a primary source here. Compare configurations on [[mac-studio-llm]] and measure speed yourself.

### Does `ollama launch claude` need an API key?

Not for a local model: the manual setup sets `ANTHROPIC_AUTH_TOKEN=ollama` and leaves `ANTHROPIC_API_KEY` empty. Ollama Cloud models use a key, which is out of scope here.

### How much context does a local coding agent need?

Ollama says 64k or higher for larger repositories on its Claude Code page, states OpenCode "requires a context length of 64k or higher", and recommends at least 64k tokens for local models on its OpenClaw page. At 65,536 tokens the KV cache for Qwen3.6-35B-A3B is 1.342 GB by the formula above.

## Sources read on 2026-10-13

- [Ollama: Claude Code](https://docs.ollama.com/integrations/claude-code.md): launcher, environment variables, 64k+ context.
- [Ollama: OpenCode](https://docs.ollama.com/integrations/opencode.md): launcher, config path, baseURL, 64k requirement.
- [Ollama: OpenClaw](https://docs.ollama.com/integrations/openclaw.md): `ollama launch` behaviour, "at least 64k tokens" for local models.
- [Ollama: macOS](https://docs.ollama.com/macos): macOS 14 or newer, Apple M series CPU and GPU support.
- [Ollama library: qwen3.6](https://ollama.com/library/qwen3.6): tag sizes, 256K window, MLX tags, launch commands.
- [Qwen3.6-35B-A3B](https://huggingface.co/Qwen/Qwen3.6-35B-A3B) and its [config.json](https://huggingface.co/Qwen/Qwen3.6-35B-A3B/raw/main/config.json): parameters, context, licence, layers, KV heads, head_dim, safetensors parameter count.
- [Qwen3.8-27B](https://huggingface.co/Qwen/Qwen3.8-27B) and its [config.json](https://huggingface.co/Qwen/Qwen3.8-27B/raw/main/config.json): same fields.
- [Apple MacBook Pro specs](https://www.apple.com/macbook-pro/specs/): memory options per chip.
- [[methodology]]: weight, KV and overhead formulas; [[best-llm-for-128gb-mac]]: gpt-oss-120b total.

## Related

- [[methodology]]
- [[qwen-on-mac]]
- [[best-llm-for-64gb-mac]]
- [[best-llm-for-128gb-mac]]
- [[local-agent-on-mac]]
- [[ollama-on-mac]]
- [[mac-llm-server]]
- [[mac-studio-llm]]
- [[long-context-on-mac]]
- [[measure-tokens-per-second-mac]]
