Exam angleD3 · D5

The Local Bridge Stack: Claude Code on Llama.cpp + Gemma 4 at 22-28 t/s

Route Claude Code through Llama.cpp to a local Gemma 4 31B model and you get 22-28 tokens/sec autonomous coding, zero API spend, and data that never leaves your NVMe. The trick is two env vars (ANTHROPIC_BASE_URL, ANTHROPIC_API_KEY) plus the free-claude-code bridge, a 32768-token context window, and a one-line CLAUDE_CODE_MAX_TOKENS=16384 ceiling so the client doesn't try a 200k context and wipe the run.

Painterly walnut signal-routing console with brass pneumatic tubes curving inward back to a workshop bench. A hand-painted brass dial reads LOCAL // CLOUD with the needle locked to LOCAL. Loop in wire-rim glasses reads a BASE_URL instruction card at the workbench.
Painterly walnut signal-routing console with brass pneumatic tubes curving inward back to a workshop bench. A hand-painted brass dial reads LOCAL // CLOUD with the needle locked to LOCAL. Loop in wire-rim glasses reads a BASE_URL instruction card at the workbench.
Key takeaways
  • Route Claude Code through Llama.cpp to a local Gemma 4 31B model and you get 22-28 tokens/sec autonomous coding, zero API spend, and data that never leaves your NVMe. The trick is two env vars (ANTHROPIC_BASE_URL, ANTHROPIC_API_KEY) plus the free-claude-code bridge, a 32768-token context window, and a one-line CLAUDE_CODE_MAX_TOKENS=16384 ceiling so the client doesn't try a 200k context and wipe the run.
  • The local stack runs the same Claude Code client - every Claude Code architecture question still applies, the inference layer just moves.
  • Local inference is the highest-leverage privacy + cost lever for personal-productivity agents.
  • Anthropic-format tooling is smart, not psychic - the repo-mapping CLAUDE.md tip in this post is a direct application of the hierarchy concept.

Quick answer

The Local Bridge Stack = Claude Code client + ANTHROPIC_BASE_URL redirect + free-claude-code proxy + Llama.cpp + Gemma 4 31B. Output: 22-28 t/s autonomous coding on an RTX 4090, zero API bill, data stays local. Two non-obvious env vars do the heavy lifting (CLAUDE_CODE_MAX_TOKENS=16384, --api-type anthropic). A root CLAUDE.md mapping the repo architecture is the highest-leverage configuration step after the env vars.

01 — Article

The setup, in 11 lines

Running Anthropic Claude Code with Llama.cpp and Gemma 4 has a new sweet spot. Before: weekend science project. After: a stack worth running every day.

  1. Route Claude Code to local inference with ANTHROPIC_BASE_URL="http://localhost:8080/v1" so Anthropic-format calls hit Llama.cpp.
  2. Set ANTHROPIC_API_KEY="sk-local-token" anyway. The bridge accepts any placeholder; the client refuses to start without one. Yes, it feels illegal.
  3. Install the modern stack with uv, not pip detours: uv tool install @anthropic-ai/claude-code.
  4. Don't use old uv. Pre-v0.6.0 reportedly breaks free-claude-code's proxy dependency resolution. Upgrade first.
  5. Run the bridge from free-claude-code so Claude Code can talk to a local server without pretending it's a cloud app.
  6. Start Llama.cpp with --ctx-size 32768. Smaller contexts look fine until repo analysis lands and everything catches fire.
  7. Add --cont-batching - Claude Code isn't one clean completion. It's a think/act loop, and batching matters.
  8. On newer Llama.cpp builds, use --api-type anthropic so /v1/messages works natively. Less glue code, fewer haunted bugs.
  9. Set CLAUDE_CODE_MAX_TOKENS=16384. Most people miss this. If you don't set it, Claude Code may try a 200k context and wipe your local run.
  10. Pick the right Gemma variant. Gemma 4 31B Q4_K_M is the practical logic/speed tradeoff; the 26B-A4B MoE is faster but loops more on harder refactors.
  11. The payoff: Gemma 4 31B on an RTX 4090 reportedly runs autonomous coding at 22-28 tokens/sec, with data staying local instead of leaving your NVMe.
02 — Article

The bonus tip nobody mentions

Create a root CLAUDE.md mapping the repo architecture. Top-level dirs, module roles, where side-effects live, entry points. Anthropic-format tooling is smart, not psychic - and a structural index in CLAUDE.md gives the local model navigational grip even when individual file contents aren't in context. Twenty minutes of authoring; pays back across every session.

03 — Article

Where it still goes weird

Three honest failure modes:

  • Deletions over 500 lines get weird. The model's reasoning about cross-file impact thins out at that scale.
  • Repo-wide refactors need explicit chunking via Plan Mode. Don't ask for them in one prompt.
  • The 32768 context is enough for most files but not whole-repo analysis. Pair with the root CLAUDE.md above.

This isn't perfect. It's just good enough to be the default for most personal-productivity coding work.

How this shows up on the exam

D3 (Claude Code Configuration) repeatedly tests whether you understand that the client and the inference layer are separable concerns. Most candidates assume the Claude Code workflows (Plan Mode, CLAUDE.md hierarchy, Skills, hooks, slash commands) are tied to Anthropic's API. They're not - the protocols are public, the bridge layer is real, and the workflows survive a model swap. Exam questions that ask "where does configuration X live?" expect you to know it lives in the client and the file system, not in the API.

D5 (Context Management) tests the same pattern from the other side. The CLAUDE_CODE_MAX_TOKENS=16384 ceiling and --ctx-size 32768 are the worked example of deliberate context budgeting - you don't just take whatever the default is, you size the budget to the model and the task. The exam will distract you with "raise the context limit" answers; the correct architecture is to bound the budget and use Plan Mode + CLAUDE.md to make the bounded context productive.

04 — Article

If you're running a different local stack, what token/sec are you seeing - or where's the bottleneck?

That's the question worth asking around. The local-Claude-Code field is moving fast enough that the sweet spot in May 2026 won't be the sweet spot in August. But the architectural patterns - env-var redirect, bridge proxy, deliberate context budgeting, structural CLAUDE.md - survive every model swap.

How this shows up on the exam

4 direct routes into the scored material.

CAC
CAC Editorial

Independent exam-prep editors. Exam claims link back to the evidence-led guide; community excerpts remain attributed to their public source.

Help someone pass

Share this post.

One share is one less person stuck on the same question.