Running Gemma 4 locally with LM Studio's new headless CLI and Claude Code

404 points
1/21/1970
5 days ago
by vbtechguy

Comments


d4rkp4ttern

You can use llama.cpp server directly to serve local LLMs and use them in Claude Code or other CLI agents. I’ve collected full setup instructions for Gemma4 and other recent open-weight LLMs here, tested on my M1 Max 64 GB MacBook:

https://pchalasani.github.io/claude-code-tools/integrations/...

The 26BA4B is the most interesting to run on such hardware, and I get nearly double the token-gen speed (40 tok/s) compared to Qwen3.5 35BA3B. However the tau2 bench results[1] for this Gemma4 variant lag far behind the Qwen variant (68% vs 81%), so I don’t expect the former to do well on heavy agentic tool-heavy tasks:

[1] https://news.ycombinator.com/item?id=47616761

4 days ago

peder

Did you have any Anthropic vs OpenAI specification issues with Claude Code? I have been using mlx_vlm and vMLX and I get 400 Bad Request errors from Claude Code. Presumably you're not seeing those issues with llama-server ?

4 days ago

d4rkp4ttern

Correct, no issues because since at least a few months, llama.cpp/server exposes an Anthropic messages API at v1/messages, in addition to the OpenAI-compatible API at v1/chat/completions. Claude Code uses the former.

4 days ago

selectodude

I’ve jumped over to oMLX. A ton of rough edges but I think it’s the future.

4 days ago

d4rkp4ttern

At least for the Gemma4-26B-A4B, Token-gen speed with OMLX is far worse on my M1 Max 64GB Macbook, compared to llama-server:

  Quick benchmark on M1 Max 64GB, Gemma 4 26B-A4B (MoE), comparing matched dynamic 4-bit quants. Workload
  was Claude Code, which sends ~35K tokens of input context per request (system prompt + tools + user
  message):

  llama.cpp (unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q4_K_XL, llama-server -fa on -c 131072 --jinja --temp 1.0
  --top-p 0.95 --top-k 64):
  - pp ≈ 395 tok/s
  - tg ≈ 40 tok/s

  oMLX (unsloth/gemma-4-26b-a4b-it-UD-MLX-4bit, omlx serve --model-dir ~/models/omlx, with
  sampling.max_context_window and max_tokens bumped to 131072 in ~/.omlx/settings.json):
  - pp ≈ 350 tok/s
  - tg ≈ 5–13 tok/s

  Same model family and quant tier. Prompt processing is comparable, but oMLX's token generation is 3–7x
  slower than llama.cpp's Metal backend. Counter-intuitive given MLX is Apple's native ML framework.
4 days ago

vlowther

Same. Opencode + oMLX (0.3.4) + unsloth-Qwen3-Coder-Next-mlx-8bit on my M5 Max w 128GB is the sweet spot for me locally. The prompt decode caching keeps things coherent and fast even when contexts get north of 100k tokens.

4 days ago

peder

Have you been using `omlx serve`? If so, how are you bumping up the max context size? I'm not seeing a param to go above 32k?

4 days ago

d4rkp4ttern

you can set it in the .omlx/settings.json - ask a code-agent to figure it out by pointing it at the omlx repo

4 days ago

unstatusthequo

Check out vMLX if you use Apple Silicon. https://github.com/jjang-ai/mlxstudio

17 hours ago

tatrions

[flagged]

4 days ago

seifbenayed1992

Local models are finally starting to feel pleasant instead of just "possible." The headless LM Studio flow is especially nice because it makes local inference usable from real tools instead of as a demo.

Related note from someone building in this space: I've been working on cloclo (https://www.npmjs.com/package/cloclo), an open-source coding agent CLI, and this is exactly the direction I'm excited about. It natively supports LM Studio, Ollama, vLLM, Jan, and llama.cpp as providers alongside cloud models, so you can swap between local and hosted backends without changing how you work.

Feels like we're getting closer to a good default setup where local models are private/cheap enough to use daily, and cloud models are still there when you need the extra capability.

4 days ago

SeriousM

How does cloclo differ from pi-mono?

4 days ago

seifbenayed1992

pi-mono is a great toolkit — coding agent CLI, unified LLM API, web UI, Slack bot, vLLM pods.

cloclo is a runtime for agent toolkits. You plug it into your own agents and it gives them multi-agent orchestration (AICL protocol), 13 providers, skill registry, native browser/docs/phone tools, memory, and an NDJSON bridge. Zero native deps.

4 days ago

trvz

  ollama launch claude --model gemma4:26b
5 days ago

datadrivenangel

It's amazing how simple this is, and it just works if you have ollama and claude installed!

5 days ago

gcampos

You need to increase the context window size or the tool calling feature wont work

5 days ago

mil22

For those wondering how to do this:

  OLLAMA_CONTEXT_LENGTH=64000 ollama serve
or if you're using the app, open the Ollama app's Settings dialog and adjust there.

Codex also works:

  ollama launch codex --model gemma4:26b
5 days ago

pshirshov

For some reason, that doesn't work for me, claude never returns from some ill loop. Nemotron, glm and qwen 3.5 work just fine, gemma - doesn't.

5 days ago

trvz

Since that defaults to the q4 variant, try the q8 one:

  ollama launch claude --model gemma4:26b-a4b-it-q8_0
5 days ago

pshirshov

Even tried gemma4:31b and gemma4:31b with 128k context (I have 72GiB VRAM). Nothing. I'm cursed I guess. That's ollama-rocm if that matters (I had weird bugs on Vulkan, maybe gemma misbehaves on radeons somehow?..).

UPD: tried ollama-vulkan. It works, gemma4:31b-it-q8_0 with 64k context!

5 days ago

alfiedotwtf

The default context is 128k for the smaller Gemma 4’s and 256k for the bigger ones, so you’re cutting off context and it doesn’t know how to continue.

Bump it to native (or -c 0 may work too)

4 days ago

pshirshov

In that case the model descriptor on ollama.com is incorrect, because it defaults to 16k. So I have to manually change that to 64/128k. I think you are talking about maximum context size.

4 days ago

trvz

No, the default context in Ollama varies by the memory available: https://docs.ollama.com/context-length

4 days ago

martinald

Just FYI, MoE doesn't really save (V)RAM. You still need all weights loaded in memory, it just means you consult less per forward pass. So it improves tok/s but not vram usage.

5 days ago

IceWreck

It does if you use an inference engine where you can offload some of the experts from VRAM to CPU RAM. That means I can fit a 35 billion param MoE in let's say 12 GB VRAM GPU + 16 gigs of memory.

5 days ago

Yukonv

With that you are taking a significant performance penalty and become severely I/O bottlenecked. I've been able to stream Qwen3.5-397B-A17B from my M5 Max (12 GB/s SSD Read) using the Flash MoE technique at the brisk pace of 10 tokens per second. As tokens are generated different experts need to be consulted resulting in a lot of I/O churn. So while feasible it's only great for batch jobs not interactive usage.

5 days ago

IceWreck

> So while feasible it's only great for batch jobs not interactive usage.

I mean yeah true but depends on how big the model is. The example I gave (Qwen 3.5 35BA3B) was fitting a 35B Q4 K_M (say 20 GB in size) model in 12 GB VRAM. With a 4070Ti + high speed 32 GB DDR5 ram you can easily get 700 token/sec prompt processing and 55-60 token/sec generation which is quite fast.

On the other hand if I try to fit a 120B model in 96 GB of DDR5 + the same 12 GB VRAM I get 2-5 token/sec generation.

5 days ago

zozbot234

Your 120B model likely has way more active parameters, so it can probably only fit a few shared layers in the VRAM for your dGPU. You might be better off running that model on a unified memory platform, slower VRAM but a lot more of it.

5 days ago

IceWreck

Yep, I understand I was giving an example to the person I was replying to.

4 days ago

zozbot234

10 tok/s is quite fine for chatting, though less so for interaction with agentic workloads. So the technique itself is still worthwhile for running a huge model locally.

5 days ago

functional_dev

This confused me at first as well.. inactive experts skip compute, but weights are sill loaded. So memory does not shrink at all.

I found this visualisation helpful - https://vectree.io/c/sparse-activation-patterns-and-memory-e...

4 days ago

charcircuit

You never need to have all weights in memory. You can swap them in from RAM, disk, the network, etc. MOE reduces the amount of data that will need to be swapped in for the next forward pass.

5 days ago

martinald

Yes you're right technically, but in reality you'd be swapping them the (vast?) majority in and out per inference request so would create an enormous bottleneck for the use case the author is using for.

5 days ago

charcircuit

You don't have to only have the experts being actively used in VRAM. You can load as many weights as will fit. If there is a "cache miss" you have to pay the price to swap in the weights, but if there is a hit you don't.

5 days ago

zozbot234

With unified memory, reading from RAM to GPU compute buffer is not that painful, and you can use partial RAM caching to minimize the impact of other kinds of swapping.

5 days ago

mikkupikku

In practical terms, is this kind of architecture available to consumers except through Apple?

4 days ago

the_pwner224

AMD Strix Halo. Available in the Framework desktop, various mini PCs, and the Asus Rog Flow Z13 "gaming tablet." The Z13 is still at $2700 for 128 GB which is an incredible deal with today's RAM prices.

There's also the Nvidia DGX Spark.

4 days ago

vbtechguy

Here is how I set up Gemma 4 26B for local inference on macOS that can be used with Claude Code.

5 days ago

canyon289

This is a nice writeup!

5 days ago

bicepjai

Totally agree lmstudio headless server on a remote machine but control models from your laptop is an amazing workflow. But Gemma 4 was not a good model atleast in my trials “find me the largest text file in all of the current sub folders” it went on a loopy tool call for ever even with Q8

2 days ago

jonplackett

So wait what is the interaction between Gemma and Claude?

5 days ago

unsnap_biceps

lm studio offers an Anthropic compatible local endpoint, so you can point Claude code at it and it'll use your local model for it's requests, however, I've had a lot of problems with LM Studio and Claude code losing it's place. It'll think for awhile, come up with a plan, start to do it and then just halt in the middle. I'll ask it to continue and it'll do a small change and get stuck again.

Using ollama's api doesn't have the same issue, so I've stuck to using ollama for local development work.

5 days ago

keerthiko

Claude Code is fairly notoriously token inefficient as far as coding agent/harnesses go (i come from aider pre-CC). It's only viable because the Max subscriptions give you approximately unlimited token budget, which resets in a few hours even if you hit the limit. But this also only works because cloud models have massive token windows (1M tokens on opus right now) which is a bit difficult to make happen locally with the VRAM needed.

And if you somehow managed to open up a big enough VRAM playground, the open weights models are not quite as good at wrangling such large context windows (even opus is hardly capable) without basically getting confused about what they were doing before they finish parsing it.

5 days ago

unsnap_biceps

I use CC at work, so I haven't explored other options. Is there a better one to use locally? I presumed they were all going to be pretty similar.

5 days ago

jaggederest

If you want to experiment with same-harness-different-models Opencode is classically the one to use. After their recent kerfluffle with Anthropic you'll have to use API pricing for opus/sonnet/haiku which makes it kind of a non-starter, but it lets you swap out any number of cloud or local models using e.g. ollama or z.ai or whatever backend provider you like.

I'd rate their coding agent harness as slightly to significantly less capable than claude code, but it also plays better with alternate models.

5 days ago

blitzar

I am hopeful the leaked claude code narrows the capability, perhaps even googles offering will be viable once they borrow some ideas from claude.

5 days ago

andhuman

I have good experience with Mistral Vibe.

4 days ago

satvikpendem

OpenCode

5 days ago

storus

Can't you use Claude caveman mode?

https://github.com/JuliusBrussee/caveman

5 days ago

aplomb1026

[dead]

5 days ago

tatrions

[flagged]

4 days ago

mbesto

I don't get why I would use Claude Code when OpenCode, Cursor, Zed, etc. all exist, are "free" and work with virtually any llm. Seems like a weird use case unless I'm missing something.

5 days ago

superb_dev

From my experience, Claude Code is just better. Although I recently started using Zed and it’s pretty good

5 days ago

blitzar

previously I have found claude code to be just better than the alternatives, using large models or local. It is, however, closer now and not much excuse for the competition after the claude code leak. Personally, I will be giving this a go with OpenCode.

5 days ago

panagathon

> I don't get why I would use Claude Code when OpenCode, Cursor, Zed, etc. all exist, are "free" and work with virtually any llm. Seems like a weird use case unless I'm missing something.

I'm with you on this. I've tried Gemma and Claude code and it's not good. Forgets it can use bash!

However, Gemma running locally with Pi as the harness is a beast.

4 days ago

bdangubic

this is like asking why use intellij or vscode or … when there is vim and emacs

5 days ago

NamlchakKhandro

No it's more like, why use a Microsoft paid for distro of nvim when lazyvim, astronvim exist

5 days ago

rachel_rig

[dead]

2 days ago

alfiedotwtf

PSA: For those getting stuck in a repetitive loop or just stopping without completing a task, try the interactive template. I just tried it now and it's blowing my already impressive results out of the water (llama.cpp):

    --jinja --chat-template-file models/templates/google-gemma-4-31B-it-interleaved.jinja
3 days ago

jedisct1

Running Gemma 4 with llama.cpp and Swival:

$ llama-server --reasoning auto --fit on -hf unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q4_K_XL --temp 1.0 --top-p 0.95 --top-k 64

$ uvx swival --provider llamacpp

Done.

4 days ago

asymmetric

Is a framework desktop with >48GB of RAM a good machine to try this out?

5 days ago

pshirshov

Only for chat sessions, not for agentic coding. It's just too slow to be practical (10 minutes to answer a simple question about a 2k LoC project - and that's with a 5070 addon card).

5 days ago

ac29

This article is about a MoE model with only 4B active parameters, it shouldn't take 10 minutes to answer a question about a small project.

I measured a 4bit quant of this model at 1300t/s prefill and ~60t/s decode on Ryzen 395+.

4 days ago

nl

Doesn't the framework desktop have a Ryzen 395 AI? That's a unified memory architecture like the Macs.

4 days ago

pshirshov

Ah, forgot to add, it's not really "unified" you have to explicitly specify your allocations. You may have a reasonably good 48gb chunk assigned to the GPU, but that DDR5 is 5-10 times slower than GDDR/HBM and the GPU itself isn't stellar.

So, framework laptops are great for chatting but nearly useless in agentic coding.

My Radeon W7900 answers a question ("what is this project") in 2 minutes, it takes my Framework 16 with 5070 addon around 11 minutes without the addon - around 23 (qwen 3.5 27b, claude code)

4 days ago

pshirshov

That's discrete DDR5, it's not as fast as your regular VRAM.

4 days ago

pseudosavant

I want local models to succeed, but today the gap vs cloud models still seems continually too large. Even with a $2k GPU or a $4k MBP, the quality and speed tradeoff usually isn’t sensible.

Credit to Google for releasing Gemma 4, though. I’d love to see local models reach the point where a 32 GB machine can handle high quality agentic coding at a practical speed.

4 days ago

ffsm8

Fwiw, the real reason we don't have 100+ GB GPUs is because Nvidia likes to segment their markets. They could sell the consumer cards with 200gb gddr RAM on it, they just know that'd eat into their enterprise offering which is quiet literally all their profit margin (which I may add is gargantuan as of 2025)

3 days ago

drob518

Seems like this might be a great way to do web software testing. We’ve had Selenium and Puppeteer for a long time but they are a bit brittle with respect to the web design. Change something about the design and there’s a high likelihood that a test will break. Seems like this might be able to be smarter about adapting to changes. That’s also a great use for a smaller model like this.

4 days ago

robot_jesus

Yeah. I think that's an interesting use case. Especially if I can kick it off or schedule it when I'm not actively working. Inference speed (especially with tool calling involved) won't be great on my machines, but if I schedule nightly usability tests of dev sites while I sleep, that could be really cool.

4 days ago

drob518

You’re right about inference speed being a concern. I was assuming it’s a small model but even then, one of the browser automation frameworks is going to be faster.

4 days ago

Someone1234

Using Claude Code seems like a popular frontend currently, I wonder how long until Anthropic releases an update to make it a little to a lot less turn-key? They've been very clear that they aren't exactly champions of this stuff being used outside of very specific ways.

5 days ago

nerdix

I don't think there is any incentive to do so right now because the open models aren't as good. The vast majority of businesses are going to just pay the extra cost for access to a frontier model. The model is what gives them a competitive advantage, not the harness. The harness is a lot easier to replicate than Opus.

There are benefits too. Some developers might learn to use Claude Code outside of work with cheaper models and then advocate for using Claude Code at work (where their companies will just buy access from Anthropic, Bedrock, etc). Similar to how free ESXi licenses for personal use helped infrastructure folks gain skills with that product which created a healthy supply of labor and VMware evangelists that were eager to spread the gospel. Anthropic can't just give away access to Claude models because of cost so there is use in allowing alternative ways for developers to learn how to use Claude Code and develop a workflow with it.

5 days ago

deskamess

Are the Claude Code (desktop) models very different from what Bedrock has? I thought you could hook up VSCode (not Claude Desktop) to Bedrock Anthropic models. Are there features in Claude Desktop that are not in VSCode/cli?

5 days ago

chvid

Is it not about the same as using OpenCode?

And is running a local model with Claude Code actually usable for any practical work compared to the hosted Anthropic models?

5 days ago

falcor84

Well, if they did, it would probably be shooting themselves in the foot, seeing that the Claude Code source is out there now, and people are waiting for an excuse to "clean-room" reimplement and fork it

5 days ago

alfiedotwtf

Yet Codex specifically aims out to be compatible with all backends! Up until Gemma 4 though it’s been pretty solid, but totally fails with unknown tool (I’m guessing a template issue)

4 days ago

wyre

I think CC is popular because they are catering to the common denominator programmer and are going to continue to do that, not because CC is particularly turn-key.

5 days ago

moomin

Right now it suits them down to the ground. You pay for the product and you don’t cost their servers anything.

5 days ago

phainopepla2

You don't pay anything to use Claude Code as a front end to non-Anthropic models

5 days ago

quinnjh

so no subscription is needed?

5 days ago

kenmacd

not to use the cli tool. You can install it and change the settings to point to pretty much any other model.

It's an okay-enough tool, but I don't see a lot of point in using it when open sources tools like Pi and OpenCode exist (or octofriend, or forge, or droid, etc).

5 days ago

ttul

I could see a future in which the major AI labs run a local LLM to offload much of the computational effort currently undertaken in the cloud, leaving the heavy lifting to cloud-hosted models and the easier stuff for local inference.

4 days ago

dominotw

wouldnt that be counter to their whole business model?

4 days ago

ttul

I don't think so. Acquiring hardware for inference is a chokepoint on growth. If they can offload some inference to the customer's machine, that allows them to use more of their online capacity to generate money.

4 days ago

janalsncm

Qwen3-coder has been better for coding in my experience and has similar sizes. Either way, after a bunch of frustration with the quality and price of CC lately I’m happy there are local options.

4 days ago

AbuAssar

omlx gives better performance than ollama on apple silicon

4 days ago

Imanari

How well do the Gemma 4 models perform on agentic coding? What are your impressions?

4 days ago

aetherspawn

Can you use the smaller Gemma 4B model as speculative decoding for the larger 31B model?

Why/why not?

5 days ago

MeetRickAI

[dead]

5 days ago

tiku

I hate that my M5 with 24 gb has so much trouble with these models. Not getting any good speeds, even with simple models.

4 days ago

_2fnr

[flagged]

4 days ago

satvikpendem

Sounds like the exact opposite, models are being commoditized while the harness and tooling around a model is what actually gets significant gains, especially with RL around specific models.

For example, this article was posted recently, Improving 15 LLMs at Coding in One Afternoon. Only the Harness Changed [0].

[0] https://news.ycombinator.com/item?id=46988596

4 days ago

bckr

I think it’s ALL getting commoditized. The winners here are engineers (who are onboard with the agentic surge) and, hopefully, users who get more and better software.

4 days ago

vkou

> hopefully, users who get more and better software.

Users are definitely going to get more software and more features and redesigns in the software they use, but I have strong doubts that it's going to get better.

If pre-LLM developer productivity was used to build all sorts of deranged anti-user promo-padding bullshit, imagine how much more of it we can do with a 2x more productive employee base.

4 days ago

bckr

yes. But also some stuff will be amazing.

3 days ago

chappyasel

[dead]

4 days ago

Havoc

You could always point Claude Code and open code at a local http endpoint

4 days ago

jeremie_strand

[dead]

4 days ago

edinetdb

[flagged]

5 days ago

mjlee

I find MCP beneficial too, but do be aware of token usage. With a naive implementation MCP can use significantly more input tokens (and context) than equivalent skills would. With a handful of third party MCPs I’ve seen tens of thousands of tokens used before I’ve started anything.

Here’s an article from Anthropic explaining why, but it is 5 months old so perhaps it's irrelevant ancient history at this point.

https://www.anthropic.com/engineering/code-execution-with-mc...

4 days ago

chappyasel

[dead]

4 days ago

tatrions

[flagged]

4 days ago

meidad_g

[flagged]

4 days ago

techpulselab

[dead]

5 days ago

meidad_g

[flagged]

5 days ago

aplomb1026

[dead]

5 days ago

maxbeech

[dead]

4 days ago

inzlab

awesome, the lighter the hardware running big softwares the more novelty.

5 days ago

smcleod

Did you try the MLX model instead? In general MLX tends provide much better performance than GGUF/Llama.cpp on macOS.

4 days ago

NamlchakKhandro

I don't know why people bother with Claude code.

It's so jank, there are far superior cli coding harness out there

5 days ago

loveparade

What do you recommend? I've tried both pi and opencode and both are better than claude imo, but I wonder if there are others.

5 days ago

tarruda

Codex is the best out-of-box experience, especially due to its builtin sandboxing. Only drawback is that its edit tool requires the LLM to output a diff which only GPTs are trained to do correctly.

5 days ago

loveparade

Interesting, I don't like codex exactly because of its built-in sandboxing. If I need a sandbox I rather do a simple bwrap myself around the agent process, I prefer that over the agent cli doing a bunch of sandboxing magic that gets in my way.

5 days ago

prettyblocks

how is codex sandbox different from /sandbox on claude code?

5 days ago

dimgl

Vagueposting in Hacker News?

5 days ago

z0mghii

Can you elaborate what is jank about it?

5 days ago

threethirtytwo

it has visual artifacts when inferencing.

4 days ago