Skip to main content
AI Tools9 min read

How to Run Claude Code on Open-Source Models with Zap

x

xSquad Team

Claude Code is the most capable agentic coding CLI available in 2026, but running it against Anthropic's frontier models gets expensive quickly. Every long reasoning chain, every file re-read, every tool output flows through tokens you pay for. Open-source models like GLM 5.2, Kimi K2, and Qwen have closed the coding quality gap dramatically, yet until now there was no clean way to drive them from the Claude Code interface you already use. That is the gap Zap fills. Zap is a metered wrapper that lets you run Claude Code and Codex against open-source models, billed by time and compute rather than token count, so long reasoning chains do not sting. The npm package @xsquads/zap is the client, and the instructions below mirror the official guide at zap.xsquads.ai.

What Zap actually is

Zap is not a fork of Claude Code and it is not a local model router you have to host. It is a thin client plus a hosted worker. The worker speaks the Anthropic and OpenAI wire formats natively, so zap claude simply sets environment variables and spawns the real claude CLI, and zap codex points the real Codex CLI at the worker through -c config overrides. The CLIs themselves stay external prerequisites on your PATH. Zap never writes to ~/.claude/ or ~/.codex/, so your existing Anthropic and OpenAI config stays untouched. You keep the interfaces you already know, and you only pay for what you use through credits.

That design matters because it means Zap is not a second tool to learn. If you know Claude Code, you already know Zap Claude Code. The only difference is which model answers.

Prerequisites

You need Node 20 or newer, plus the CLIs you intend to drive. Install them globally:

``sh

npm install -g @anthropic-ai/claude-code # for zap claude

npm install -g @openai/codex # for zap codex

`

If you only want to run Claude Code against open models, you only need the first line. Codex is optional.

Step 1: Install Zap

`sh

npm install -g @xsquads/zap

`

Verify it landed:

`sh

zap -v

`

Zap checks npm for a newer version at most once a day (a 2-second budget, cached in ~/.zap/update-check.json). When a newer version exists it asks Update now? [y/N], and a yes runs npm install -g @xsquads/zap@latest. In non-interactive shells it just prints a one-line notice. It never installs anything without an explicit yes. If you want to silence the check entirely, set ZAP_UPDATE_CHECK=0 or run in CI.

Step 2: Log in

`sh

zap login

`

This opens Google OAuth in your browser. If the browser does not open, the command prints the URL and you can copy it manually. Your session token is stored locally and used to authenticate every request to the Zap worker.

Confirm you are logged in and check your balance:

`sh

zap whoami # prints your email plus balance in USD

zap credits # balance plus recent ledger activity

`

Step 3: Run Claude Code on an open model

`sh

zap claude

`

That single command verifies you are logged in, confirms claude is on your PATH, fetches the model list from the Zap API, and launches Claude Code with your terminal's stdio. You are now in a normal Claude Code session, routed to open-source models.

The key feature is gateway model discovery. zap claude populates the Claude Code /model picker with every Zap model, so you can switch models at runtime. Open the picker with /model to see the list, or switch directly with /model :

`

/model glm-5.2

`

Runtime switching via the picker requires Claude Code v2.1.129 or newer, but /model works on any version. The default model is glm-5.2 when available, otherwise the first model the worker returns.

You can also pass a model explicitly for a single run, forwarding arguments after --:

`sh

zap claude -- --model glm-5.2 "explain this file"

`

The exit code of claude is propagated, so Zap drops cleanly into existing scripts and CI.

Step 4: Run Codex on an open model (optional)

If you also use the OpenAI Codex CLI, Zap drives it the same way:

`sh

zap codex

`

zap codex points the Codex CLI at the Zap worker's OpenAI-compatible /v1 endpoint through -c config overrides. No config file is ever written. The default model is again glm-5.2 when listed, otherwise the first available. Forward extra arguments after --:

`sh

zap codex -- "explain this file"

`

Step 5: Optionally compress prompts with Headroom

This is the step most people skip and then wonder why their credit burn is high. If the Headroom proxy is installed, zap claude and zap codex automatically route through it on 127.0.0.1 to compress prompts and tool outputs before they reach the Zap worker. Fewer tokens means less energy, lower credit burn, and longer sessions:

`sh

pip install "headroom-ai[proxy]" # or: uv tool install "headroom-ai[proxy]"

`

Nothing else to configure. Zap starts and stops the proxy per session and falls back to a direct connection if Headroom is missing or fails to start. To disable it explicitly, set ZAP_HEADROOM=0.

Step 6: Manage your account

The everyday commands:

`sh

zap whoami # email + balance in USD

zap credits # balance + recent ledger activity

zap logout # revoke session + clear local token

zap -v # display the current version

`

A 401 from the API tells you the session expired and to run zap login. A 402 prints the server's out-of-credits message. If the API is unreachable, you get a clear "Could not reach the zap API" error and a nonzero exit, never a stack trace.

Configuration and environment variables

The API base URL resolves in this order, highest first:

1. saved ~/.zap/config.json api_base

2. ZAP_API_BASE environment variable

3. the baked-in default, https://zap.xsquads.ai

Point Zap at a different worker for staging or self-hosting:

`sh

ZAP_API_BASE=https://staging.api.example.com zap whoami

`

The full set of toggles:

VariablePurpose
ZAP_API_BASEOverride the worker origin ZAP_HEADROOMSet to 0 to disable prompt compression ZAP_UPDATE_CHECKSet to 0 to disable the daily update check

Which models can you run?

The worker exposes the open-source models it currently serves. At the time of writing, Zap lists the families highlighted on the site: GLM 5.2, Kimi K2, and Qwen, with model ids like glm-5.2, kimi k2.7, and qwen-3.7 appearing in the picker. The exact list evolves as new open weights ship, and because Zap fetches the model list at launch, you always see the current set without reinstalling. Open /model inside Claude Code to see what is available right now.

Why this is worth doing

The argument for running Claude Code on open models is not just cost, though cost is the easy part. Frontier model tokens are expensive, and agentic loops multiply that cost because every step re-sends context. Zap's billing model is built around that reality: you are billed by time and compute, not token count, so a model that thinks longer per turn does not punish your wallet the way per-token pricing does. That is what the site means by "no more token anxiety."

The deeper win is optionality. When you can switch between GLM, Kimi, and Qwen with a /model command, you stop being locked into one vendor's pricing or rate limits. You can pick the model that fits the task: a cheaper open model for bulk refactors, a stronger one for the hard architectural question. And because Zap never touches your ~/.claude/ or ~/.codex/ config, you can fall back to your native Anthropic or OpenAI setup at any time by just running claude or codex directly.

Putting it together

The full setup, start to finish:

`sh

npm install -g @anthropic-ai/claude-code

npm install -g @xsquads/zap

zap login

zap claude

`

Inside the session, /model to pick GLM 5.2, Kimi K2, or Qwen. zap whoami to check your balance. zap logout when you are done. That is the whole loop, and it is the loop described on zap.xsquads.ai and in the @xsquads/zap` package readme.

How xSquad fits in

Zap is an xSquad product, and it sits naturally inside the way we think about agent factories. The factory model only delivers speed when you control cost, model choice, and governance at the same time. Letting your agents run on open-source models through a metered wrapper is one of the cleanest cost controls available, and it keeps you on the Claude Code and Codex interfaces your team already knows. If you are scaling beyond a single CLI into a full coding factory, that same cost discipline is what keeps unattended agents profitable at scale. If you want to go further and run coordinated dev squads that ship production code with senior human oversight, that is what xSquad is built for. Zap is the single-developer on-ramp to the same philosophy.

Ready to Scale Your Development Team?

See how xSquad can help you ship production code in 48 hours, not 6 months.