A cloud coding agent stops mid-task when the token quota runs out. Instead, run Qwen 4 locally with llama.cpp, so it uses no cloud tokens.
Meet the Mac requirements first. Install llama.cpp after that.
Requirements
Use Apple Silicon with 32 GB RAM or more.
Note: With 24 GB RAM, download both parts from the
IQ3_XXS/folder instealth-model/Qwen4-35B-A3B-GGUF. The files areIQ3_XXS/Qwen4-35B-A3B-IQ3_XXS-00001-of-00002.ggufandIQ3_XXS/Qwen4-35B-A3B-IQ3_XXS-00002-of-00002.gguf. Point-mat the-00001-of-00002file.
Install
Install llama.cpp with Homebrew so llama-server is on your PATH.
brew install llama.cpp
llama-server --version
Note: Version 1.1.0 or older cannot load Qwen 4. If
brew install llama.cppstill gives 1.1.0, Homebrew has not picked up 1.1.1 yet. Wait a day or two and runbrew upgrade llama.cpp, or build from source with the commands below.
git clone --depth 1 --branch v1.1.1 \
https://github.com/ggml-org/llama.cpp.git
cd llama.cpp
# only if you get "'cstdio' file not found"
export CXXFLAGS="-isystem $(xcrun --show-sdk-path)/usr/include/c++/v1"
cmake -B build -DCMAKE_BUILD_TYPE=Release \
-DLLAMA_BUILD_TESTS=OFF
cmake --build build -j 8
# run it from here: ./build/bin/llama-server
Meet the Linux requirements first. Install llama.cpp after that.
Requirements
Use an x86_64 machine with an NVIDIA GPU and enough VRAM plus system RAM for the model. A 16 GB card can run this MoE if some expert layers stay in RAM with --n-cpu-moe.
Install
Qwen 4 needs llama.cpp v1.1.1 or newer. The stable v1.1.1 tag documents Qwen4-35B-A3B support. At the time of writing (4 Dec 2026), the v1.1.1 release has no Linux tarballs. Nightly b… pre-releases do. Pick a release at or after v1.1.1 that publishes the Ubuntu CUDA 12.8 x64 tarballs. Build b12986 is one such build.
Download the official prebuilt binaries from the llama.cpp releases. NVIDIA drivers must already work. The prebuilt tarballs bundle the CUDA runtime, so a full CUDA toolkit is not required for this path.
BUILD=b12986
cd "$(mktemp -d)"
mkdir -p ~/.local/share/llama.cpp/$BUILD
curl -L -C - -O \
https://github.com/ggml-org/llama.cpp/releases/download/$BUILD/llama-$BUILD-bin-ubuntu-cuda-12.8-x64.tar.gz
curl -L -C - -O \
https://github.com/ggml-org/llama.cpp/releases/download/$BUILD/cudart-llama-$BUILD-bin-ubuntu-cuda-12.8-x64.tar.gz
tar -xzf llama-$BUILD-bin-ubuntu-cuda-12.8-x64.tar.gz \
-C ~/.local/share/llama.cpp/$BUILD --strip-components=1
tar -xzf cudart-llama-$BUILD-bin-ubuntu-cuda-12.8-x64.tar.gz \
-C ~/.local/share/llama.cpp/$BUILD --strip-components=1
ln -sfn ~/.local/share/llama.cpp/$BUILD ~/.local/share/llama.cpp/current
mkdir -p ~/.local/bin
ln -sfn ~/.local/share/llama.cpp/current/llama-server \
~/.local/bin/llama-server
Set BUILD to the release you picked. The cd line enters a temporary directory so the tarballs do not stay in the directory you started from. The --strip-components=1 flag puts llama-server in that directory. The cudart tarball supplies the CUDA runtime libraries. The current symlink points at this build. The link into ~/.local/bin puts llama-server on PATH.
Add ~/.local/bin to PATH if llama-server --version is not found after the link.
The source build is optional and needs the CUDA toolkit. Start it from your home directory, because the prebuilt commands left you in a temporary directory.
git clone --depth 1 --branch v1.1.1 \
https://github.com/ggml-org/llama.cpp.git
cd llama.cpp
cmake -B build -DGGML_CUDA=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release -j 8
# run it from here: ./build/bin/llama-server
Meet the Windows requirements first. Install llama.cpp after that.
Requirements
The Windows requirements match Linux: an NVIDIA GPU, and a 16 GB card can use --n-cpu-moe.
Install
Qwen 4 needs llama.cpp v1.1.1 or newer. At the time of writing (4 Dec 2026), the v1.1.1 release has no Windows zips. Build b12986 has CUDA 12.4 and 13.5 zips on the llama.cpp releases.
NVIDIA drivers must already work. The cudart zip supplies the CUDA runtime, so a full CUDA toolkit is not required for this path.
Pick the pair that matches the CUDA version nvidia-smi shows. The commands below use 12.4.
Run the commands in PowerShell. PowerShell aliases curl to Invoke-WebRequest, so these commands call curl.exe.
$Build = 'b12986'
$Cuda = '12.4'
$Dest = "$env:LOCALAPPDATA\llama.cpp\$Build"
$Tmp = New-TemporaryFile | ForEach-Object { Remove-Item $_; New-Item -ItemType Directory -Path $_ }
Set-Location $Tmp
curl.exe -L -C - -O "https://github.com/ggml-org/llama.cpp/releases/download/$Build/llama-$Build-bin-win-cuda-$Cuda-x64.zip"
curl.exe -L -C - -O "https://github.com/ggml-org/llama.cpp/releases/download/$Build/cudart-llama-bin-win-cuda-$Cuda-x64.zip"
New-Item -ItemType Directory -Path $Dest -Force
Expand-Archive "llama-$Build-bin-win-cuda-$Cuda-x64.zip" -DestinationPath $Dest -Force
Expand-Archive "cudart-llama-bin-win-cuda-$Cuda-x64.zip" -DestinationPath $Dest -Force
$Current = "$env:LOCALAPPDATA\llama.cpp\current"
if (Test-Path $Current) { Remove-Item $Current -Force }
New-Item -ItemType Junction -Path $Current -Target $Dest
$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
if ([string]::IsNullOrEmpty($userPath)) {
[Environment]::SetEnvironmentVariable('Path', $Current, 'User')
} elseif ($userPath -notlike "*$Current*") {
[Environment]::SetEnvironmentVariable('Path', ($userPath.TrimEnd(';') + ';' + $Current), 'User')
}
$env:Path = "$Current;$env:Path"
llama-server --version
Set $Build to the release you picked and $Cuda to 12.4 or 13.5. The temp directory keeps the zips out of the starting folder. Both zips extract into the same folder, with llama-server.exe at the root. The current junction points at this build. The user PATH line makes llama-server available in new terminals.
Note: At the time of writing (4 Dec 2026),
winget install llama.cppinstalls the Vulkan package at version b12973, which is older than v1.1.1. Use the official CUDA zips instead.
You need about 40 GB of free disk.
Download the three Q4_K_M files into ~/models.
mkdir -p ~/models && cd ~/models
for i in 1 2 3; do
curl -L -C - -O \
https://huggingface.co/ggml-org/Qwen4-35B-A3B-GGUF/resolve/main/Qwen4-35B-A3B-Q4_K_M-0000$i-of-00003.gguf
done
The three files are about 33 GB. The -C - flag resumes an interrupted download. When -m points at the first file, llama.cpp loads the other splits.
Windows needs curl.exe because curl is a PowerShell alias. The loop below downloads the same three files.
New-Item -ItemType Directory -Path "$HOME\models" -Force | Out-Null
Set-Location "$HOME\models"
1..3 | ForEach-Object {
curl.exe -L -C - -O "https://huggingface.co/ggml-org/Qwen4-35B-A3B-GGUF/resolve/main/Qwen4-35B-A3B-Q4_K_M-0000$_-of-00003.gguf"
}
Start an OpenAI-compatible server on 127.0.0.1:8090.
llama-server -m ~/models/Qwen4-35B-A3B-Q4_K_M-00001-of-00003.gguf --alias local \
-ngl all -fa on -c 32768 --jinja --host 127.0.0.1 --port 8090 \
--temp 1.0 --top-p 0.95 --top-k 20 --min-p 0
The --alias local flag is the model name clients send in their requests. The -c flag sets the context size. A larger value uses more memory. Thinking is on by default. A request can lower it with "reasoning_effort": "low".
--n-cpu-moe 20 as a starting point for a 16 GB card. Tune it from there.
llama-server -m ~/models/Qwen4-35B-A3B-Q4_K_M-00001-of-00003.gguf --alias local \
-ngl all -fa on -c 32768 --jinja --host 127.0.0.1 --port 8090 \
--temp 1.0 --top-p 0.95 --top-k 20 --min-p 0 \
--n-cpu-moe 20
Note: Keep expert weights for 20 layers in system RAM with this flag. Lower N keeps more experts on the GPU and is faster. Raise N if the server runs out of VRAM. Twenty is a starting value to tune.
PowerShell continues a line with a backtick.
llama-server -m "$HOME\models\Qwen4-35B-A3B-Q4_K_M-00001-of-00003.gguf" --alias local `
-ngl all -fa on -c 32768 --jinja --host 127.0.0.1 --port 8090 `
--temp 1.0 --top-p 0.95 --top-k 20 --min-p 0 `
--n-cpu-moe 20
Confirm the server with a health call and one chat request.
curl -s 127.0.0.1:8090/health
curl -s 127.0.0.1:8090/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"local","messages":[{"role":"user","content":"Say hi"}]}'
The first command should print {"status":"ok"}. The second should return a short reply. A 32 GB Mac answers at about 30 tokens per second.
PowerShell can strip quotes in curl.exe arguments, so this step uses Invoke-RestMethod.
Invoke-RestMethod 'http://127.0.0.1:8090/health'
Invoke-RestMethod 'http://127.0.0.1:8090/v1/chat/completions' `
-Method Post -ContentType 'application/json' `
-Body '{"model":"local","messages":[{"role":"user","content":"Say hi"}]}'
Start the server when you log in.
Create ~/Library/LaunchAgents/local.llama-server.plist so the server starts at login. Replace YOURNAME with your username. Paths must be absolute (~ does not work here).
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>Label</key><string>local.llama-server</string>
<key>ProgramArguments</key><array>
<string>/opt/homebrew/bin/llama-server</string>
<string>-m</string><string>/Users/YOURNAME/models/Qwen4-35B-A3B-Q4_K_M-00001-of-00003.gguf</string>
<string>--alias</string><string>local</string>
<string>-ngl</string><string>all</string>
<string>-fa</string><string>on</string>
<string>-c</string><string>32768</string>
<string>--jinja</string>
<string>--host</string><string>127.0.0.1</string>
<string>--port</string><string>8090</string>
<string>--temp</string><string>1.0</string>
<string>--top-p</string><string>0.95</string>
<string>--top-k</string><string>20</string>
<string>--min-p</string><string>0</string>
<string>--sleep-idle-seconds</string><string>600</string>
</array>
<key>RunAtLoad</key><true/>
<key>KeepAlive</key><true/>
<key>StandardOutPath</key><string>/Users/YOURNAME/Library/Logs/llama-server.log</string>
<key>StandardErrorPath</key><string>/Users/YOURNAME/Library/Logs/llama-server.log</string>
</dict></plist>
Point the first path at your own build/bin/llama-server when you built llama.cpp from source.
Load the agent.
launchctl bootstrap gui/$(id -u) \
~/Library/LaunchAgents/local.llama-server.plist
To stop it or change settings, run launchctl bootout gui/$(id -u)/local.llama-server, edit the file, and run bootstrap again.
If the server does not start, ~/Library/Logs/llama-server.log shows why.
Create ~/.config/systemd/user if it is missing, then save this unit as llama-server.service. Replace YOURNAME with your username. Paths must be absolute (~ does not work here).
mkdir -p ~/.config/systemd/user
[Unit]
Description=llama.cpp server
[Service]
ExecStart=/home/YOURNAME/.local/share/llama.cpp/current/llama-server \
-m /home/YOURNAME/models/Qwen4-35B-A3B-Q4_K_M-00001-of-00003.gguf \
--alias local \
-ngl all -fa on -c 32768 --jinja \
--host 127.0.0.1 --port 8090 \
--temp 1.0 --top-p 0.95 --top-k 20 --min-p 0 \
--n-cpu-moe 20 \
--sleep-idle-seconds 600
Restart=on-failure
[Install]
WantedBy=default.target
Point ExecStart at the absolute path of your build/bin/llama-server when you built llama.cpp from source.
Enable the service.
systemctl --user daemon-reload
systemctl --user enable --now llama-server.service
To change settings, run systemctl --user stop llama-server.service, edit the unit, run systemctl --user daemon-reload, and run systemctl --user start llama-server.service.
If the server does not start, journalctl --user -u llama-server.service shows why.
Start the server at login with a hidden Task Scheduler task. The script stores absolute paths.
$exe = "$env:LOCALAPPDATA\llama.cpp\current\llama-server.exe"
$model = "$env:USERPROFILE\models\Qwen4-35B-A3B-Q4_K_M-00001-of-00003.gguf"
$arguments = "-m `"$model`" --alias local -ngl all -fa on -c 32768 --jinja --host 127.0.0.1 --port 8090 --temp 1.0 --top-p 0.95 --top-k 20 --min-p 0 --n-cpu-moe 20 --sleep-idle-seconds 600"
$action = New-ScheduledTaskAction -Execute $exe -Argument $arguments
$trigger = New-ScheduledTaskTrigger -AtLogOn
$settings = New-ScheduledTaskSettingsSet -Hidden
$principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -LogonType Interactive -RunLevel Limited
Register-ScheduledTask -TaskName "llama-server" -Action $action -Trigger $trigger -Settings $settings -Principal $principal
The quotes around the model path keep a username with a space as one argument.
To change settings, unregister the task, edit the command, and register it again.
Unregister-ScheduledTask -TaskName "llama-server" -Confirm:$false
If the server does not start, open Task Scheduler, find llama-server, and check the Last Run Result.
On any of these systems, any tool that speaks the OpenAI API can use http://127.0.0.1:8090/v1 with model name local. The model is there after login and costs no tokens.
For simple tasks, an optional last step is Bot Widget, a tiny animated desktop face for your own AI bot.