localcode #
Fully offline AI coding environment for macOS Apple Silicon. Uses llama.cpp (llama-server in router mode) to serve local GGUF models to terminal coding agents — no API keys, no cloud, no costs.
Quick Start #
npm run build
npm run dev -- setup # installs llama.cpp, downloads models, sets up configs
localcode # launch with defaults (Pi + Qwen 3.5 9B)
Usage #
localcode # launch with last-used TUI + model
localcode pi # launch with Pi
localcode claude # launch with Claude Code
localcode pi-claude # launch with Pi running a remote Claude model
localcode gpt-oss # launch with GPT-OSS model
localcode pi gpt-oss # launch with both overrides
localcode models # list available models
localcode tuis # list available TUIs
localcode status # show config + server health
localcode start # start llama-server + download models
localcode stop # stop llama-server
localcode bench # benchmark the active chat model
localcode pipe "add type hints" # pipe stdin through the model
localcode set remote <provider/id> # switch the remote model pi-claude runs as its main model
localcode set summaries <on|off> # switch pi-claude's context summaries between local and remote
TUI and model names are auto-detected — just type the id directly. Last-used choices are saved for next time.
Backend #
One llama-server process on port 47821, started without a model. It discovers GGUFs in its download cache (the Hugging Face hub cache, ~/.cache/huggingface/hub) and loads the one a request names, keeping a single model resident. Downloads go through the same server, so localcode set model <id> fetches from Hugging Face on first use.
The server speaks both the OpenAI Chat Completions API (/v1/chat/completions) and the Anthropic Messages API (/v1/messages), which is how Claude Code connects.
TUIs #
Pi is the primary, tested target. The others are kept while they need nothing more than a URL.
| TUI | Launch | Method |
|---|---|---|
| Pi | localcode pi |
generated ~/.pi/agent/models.json |
| Pi + Claude | localcode pi-claude |
pi --model <remote>, local helper agents |
| Claude Code | localcode claude |
env vars (ANTHROPIC_BASE_URL) |
| OpenCode | localcode opencode |
generated ~/.config/opencode/opencode.json |
| Aider | localcode aider |
generated ~/.aider/aider.conf.yml |
Pi also has its own llama.cpp integration: /login llama.cpp then /llama lists, loads and downloads models from inside the TUI, against the same server.
Pi + Claude #
localcode pi-claude runs Pi with a remote Anthropic Claude model (localcode set remote <provider/id>, default a current Claude Sonnet) as the main model, with local-scout and local-worker helper agents, running on the local chat model, for simple lookups and mechanical edits. The helpers run through the subagent tool from the pi-tracks package (which also provides the track and spec-watch commands and chook); without it installed, pi-claude warns and launches without them. This mode is not offline: prompts and code go to Anthropic. It requires Anthropic sign-in — either pi then /login, or an ANTHROPIC_API_KEY — and warns if neither is set up, though it still launches. Unlike other launch choices, localcode pi-claude is not saved as the last-used TUI, so plain localcode and localcode pi stay fully local; localcode set tui pi-claude makes it the default deliberately.
Context compaction — summarising a long session once it outgrows the model's context window — normally runs on the remote main model. localcode set summaries on switches it to the local chat model instead, and localcode set summaries off (the default) switches it back. Running it locally is free and keeps the session text off Anthropic, but takes much longer and a small local model's summary can present unfinished work as settled, invent fixes it never made, and drop facts the session depended on; since a summary replaces the history it covers, those errors carry forward for the rest of the session.
Models #
src/registry/models.ts (the MODELS array) is the source of truth. Every entry is a Hugging Face GGUF reference in user/repo:QUANT form. Q4_K_XL selects Unsloth's dynamic 4-bit quant, used where the repo offers it.
| Model | ID | Size | Notes |
|---|---|---|---|
| Qwen 3.5 9B | qwen3.5-9b |
6 GB | Default. Fast small agent; verified tool calling |
| Qwen 3.5 4B | qwen3.5-4b |
3 GB | Smallest tool-capable option |
| Qwen 3.8 27B | qwen3.8-27b |
17 GB | Newest Qwen, 256K context |
| Muse Glimmer 30B | muse-glimmer |
18 GB | Meta agentic model, Apache 2.0 |
| Ornith 9B / 35B | ornith-9b, ornith-35b |
5.6 / 21 GB | Agentic coding, 256K context, MIT |
| Qwen3 Coder 30B-A3B | qwen3-coder |
18 GB | Strong coding benchmarks |
| GLM-4.7 Flash 30B-A3B | glm-flash |
18 GB | Strong coding, 198K context |
| GPT-OSS 20B | gpt-oss |
12 GB | Good for 32GB machines |
| Gemma 4 12B | gemma4 |
8 GB | Google, 128K context |
| Qwen 2.5 Coder 1.5B | qwen-1.5b-autocomplete |
1 GB | Autocomplete only |
All chat models support structured tool calling. Switch with localcode set model <id>.
Hardware Requirements #
- Mac with Apple Silicon (M1/M2/M3/M4)
- 32 GB RAM recommended
- Disk space depends on models downloaded
Configuration #
All stored in ~/.config/localcode/config.json — just the active model, autocomplete model, and TUI ids. llama-server's cache holds the model files.
Uninstall #
brew uninstall llama.cpp # remove llama.cpp
rm -rf ~/.cache/huggingface/hub/models--*-GGUF # remove downloaded models
rm ~/.local/bin/localcode # remove CLI wrapper
rm -rf ~/.config/localcode # remove config