Agent guide · rapid-mlx 1.1.1 · ← Back to README

Run Claude Code with a local model on Mac

Run rapid-mlx launch claude-code to use Claude Code with a local model on your Apple Silicon Mac. Rapid-MLX saves a private agent profile and starts a local model when needed.

One command to launch Claude Code

First install Rapid-MLX and install Claude Code. If you used the install script, restart Terminal or run export PATH="$HOME/.local/bin:$PATH" first. Then run:

$ rapid-mlx launch claude-code

Tomorrow: Run rapid-mlx launch claude-code again. Rapid reuses the saved profile, model, loopback key and port. It does not change your existing Claude Code configuration. To remove only Rapid's private profile, run rapid-mlx launch claude-code --remove.

Mac unified memoryModel choicesDownload and memory guidance
16 GBqwen3.5-4b-4bit fits 16 GB per the registry; not verified live on a 16 GB Mac.About 3 GB download.
18–36 GBqwen3.5-9b-4bit default; start with qwen3.5-4b-4bit on 18–24 GB.About 6 GB for 9B or 3 GB for 4B.
48 GB+qwen3.5-9b-4bit responsive default; qwen3.8-27b-4bit higher-capability option.About 6 GB for 9B or 16 GB for 27B; 27B needs roughly 20–26 GB free unified memory.

Download size is not runtime memory use. Leave room for the client, context and other applications; keep context short when memory is tight.

First reply: The first reply can take longer than later turns: an uncached model must download, the server must load it, and the agent may send a long prompt that takes time to prefill. Wait for the model to become ready; there is no fixed first-reply time. A warm, cached model is usually quicker.

Quick answer

How do I use Claude Code with a local model on Mac? Install Rapid-MLX, then run rapid-mlx launch claude-code. The same command reconnects on another day; --remove removes Rapid's private profile.

The agent hub covers the other supported agents. The alternative three-step setup below edits your regular agent configuration; launch uses Rapid’s private profile.

Alternative: local setup in 3 steps (edits your regular config)

# 1. Install
brew install rapid-mlx
npm install -g @anthropic-ai/claude-code
# 2. Terminal 1: start the model; leave running
rapid-mlx serve qwen3.5-9b-4bit
# 3. Terminal 2: configure and send a request
rapid-mlx agents claude-code --setup
claude -p "say hello"

Wait for the server to be ready before step 3. Setup previews changes to your regular agent settings and asks before writing. A text reply confirms the connection; it does not prove a coding task will succeed. Choose a model that fits your Mac.

TIER-1 AGENT   Wire: /v1/messages (Anthropic SDK) · Setup: rapid-mlx agents claude-code --setup · Matrix cell: ✅ ✅ ✅ ✅ (Qwen 3.6 / Gemma 4 / DeepSeek / gpt-oss on 2026-07-07 pilot).
Re-verified 2026-08-01 — a real end-to-end bug fix: Claude Code pointed at the local server via ANTHROPIC_BASE_URL and asked to find and fix a failing factorial, which it did (agent_smoke, claude 2.1.218). Plus the Anthropic SDK deep flow — plain, system prompt, multi-turn, streaming, tool use — 5/5. On rapid-mlx 0.11.5: the fix against gpt-oss-20b-mxfp4-q8, the SDK flow against qwen3.5-9b-4bit, both on an M2 Pro Mac mini (32 GB).

New to this? The 5-minute walkthrough on the blog is the fastest path from zero to a working local agent — this page is the complete reference behind it.

Install

Claude Code is upstream Anthropic — install their vendor CLI:

$ npm install -g @anthropic-ai/claude-code
# or download the binary from anthropic.com/claude-code

Config

Run setup before or after starting the server:

$ rapid-mlx agents claude-code --setup --dry-run   # preview the diff
$ rapid-mlx agents claude-code --setup             # confirm and write
# legacy config-writing launch:
$ rapid-mlx launch claude-code --legacy-config --model qwen3.5-9b-4bit

These manual setup commands write the env block of ~/.claude/settings.json. Every other key (permissions, MCP servers, …) is kept, and the old file is copied to settings.json.bak.<unix-time> first. agents --setup also shows the exact diff, asks before writing (--yes in scripts), and checks the server afterwards.

// ~/.claude/settings.json
{
  "env": {
    "ANTHROPIC_BASE_URL": "http://localhost:8000",
    "ANTHROPIC_API_KEY": "sk-noop",
    "ANTHROPIC_AUTH_TOKEN": "",
    "ANTHROPIC_MODEL": "qwen3.5-9b-4bit",
    "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "262144"
  }
}

ANTHROPIC_MODEL and CLAUDE_CODE_MAX_CONTEXT_TOKENS come from the running server (the values above are for qwen3.5-9b-4bit), so Claude Code uses the model's real context window instead of guessing one for a model id it doesn't know. ANTHROPIC_AUTH_TOKEN is blanked so that a token inherited from a proxy or account switcher can't conflict with the key.

Auth. A bare rapid-mlx serve needs no key, so ANTHROPIC_API_KEY is a placeholder. For a keyed server (--api-key, RAPID_MLX_API_KEY, or the desktop app), export RAPID_MLX_API_KEY before running setup: its value is written as ANTHROPIC_API_KEY, because Claude Code reads the key from this file. The setup diff shows credential values as <redacted>.

To try it in one shell without touching the settings file: Anthropic's SDK honors the ANTHROPIC_BASE_URL env var. Set it to the root of your rapid-mlx server (no /v1 suffix — the SDK appends the path itself):

$ export ANTHROPIC_BASE_URL=http://localhost:8000
$ export ANTHROPIC_API_KEY=not-needed
$ claude
# or inline:
$ ANTHROPIC_BASE_URL=http://localhost:8000 ANTHROPIC_API_KEY=not-needed claude

Anthropic SDK (Python)

For a complete script setup, see Anthropic SDK with local models on Mac.

If you're driving the same wire from a script, the Python SDK snippet is (verified by tests/integrations/test_anthropic_sdk.py):

$ ~/.rapid-mlx/bin/python -m pip install anthropic
# Note the base_url is the ROOT, not /v1 — the SDK appends /v1/messages itself.
# The test file strips /v1 with ``_BASE.rstrip('/').removesuffix('/v1')``.
from anthropic import Anthropic

client = Anthropic(
    base_url="http://localhost:8000",
    api_key="not-needed",
)

message = client.messages.create(
    model="default",
    max_tokens=256,
    messages=[{"role": "user", "content": "Say hello"}],
)
# Reasoning models emit a ThinkingBlock first — walk content and find the
# first block with type == "text" (see _first_text in the test file).
for block in message.content:
    if getattr(block, "type", None) == "text":
        print(block.text)
        break

Run

$ rapid-mlx serve qwen3.5-9b-4bit
# in another shell:
$ ANTHROPIC_BASE_URL=http://localhost:8000 ANTHROPIC_API_KEY=not-needed claude
# headless one-shot, and a follow-up in the same session:
$ claude -p "find and fix the failing test"
$ claude -p --continue "now add a regression test"

Prefix cache across turns

Claude Code (2.1.287 and later) adds a small system message to every request that holds only a running token counter (<total_tokens>… tokens left</total_tokens>). The server drops that counter-only message, but only in the position Claude Code puts it; it carries no instruction. Its changing value therefore never lands at the front of the prompt, and later turns of a session reuse the prefix cache instead of re-processing Claude Code's whole system prompt and tool list. No server flag is needed.

No tool flags needed. serve auto-configures the tool-call parser from the model's alias profile and turns on grammar-constrained tool calling by default, so tool calls come back guaranteed-parseable. Verified end-to-end: a bare serve + an Anthropic /v1/messages request with a tool returns a tool_use block.

Gotchas

Empirical

The claude-code row of the integration matrix is ✅ across all four Tier-1 families (Qwen 3.6, Gemma 4, DeepSeek R1-Distill, gpt-oss) on the 2026-07-07 pilot. The dedicated Anthropic SDK deep flow at test_anthropic_sdk.py covers plain, system prompt, multi-turn, streaming, and tool use.

See also

Build on the same local server

Write a script with the Anthropic SDK, compare Codex CLI, or inspect the measured Mac inference-server comparison. For tool-use results and model-specific limits, use the integration matrix.