Built from scratch in under two weeks. Skimmed the Zig docs for a couple of days, then started coding. The idea came while reading pi-mono's source — could this be simpler? One binary, zero dependencies, copy it and run. That's zcode.
A full-featured AI coding agent in a 1.7 MB native binary — built in Zig. Interactive REPL, streaming output, 7 built-in tools, session persistence, multi-provider support. No runtime, no npm install, single static executable.
- Interactive REPL with raw-mode line editor (UTF-8 aware, multi-line input)
- Non-interactive mode — pipe messages directly from the command line
- 7 built-in tools —
bash,edit,read,write,ls,find,grep - Multi-provider — Moonshot (Kimi), DeepSeek, and Ollama
- Streaming output — responses appear in real-time as tokens arrive
- Session persistence — sessions saved to SQLite, resume any time
- Thinking levels —
off,low,medium,high,xhighfor reasoning models - Token stats & cost estimation — track usage and estimate spend per session
- Zig ≥ 0.16.0
# Build
zig build
# Run interactive mode
zig build run
# Run non-interactive (single prompt)
zig build run -- "explain src/main.zig"# Run with specific provider/model
zig build run -- --provider deepseek --model deepseek-v4-flash "hello"# Continue last session
zig build run -- -c
# Resume a specific session
zig build run -- -r <session_id># Run tests
zig build test# Build examples
zig build examples| Flag | Description |
|---|---|
-c, --continue | Continue the most recent session |
-r, --resume <id> | Resume a specific session by ID |
--session-file <file> | Use a specific session file |
--session-dir <dir> | Directory for session storage |
--provider <name> | Override default provider |
--model <id> | Override default model |
--thinking <level> | Thinking level: off, low, medium, high, xhigh |
--api-key <key> | Use a specific API key |
--list-models | List all available models |
--list-providers | List configured providers |
--tools <list> | Specify which tools to enable (comma-separated) |
--debug | Show debug output |
--help | Show usage |
--version | Show version |
| Command | Description |
|---|---|
/help | Show available commands |
/quit, /exit | Exit the program |
/session | Show current session info |
/stats | Show token usage, cost estimate, and memory |
/new | Start a fresh session |
/model <id> | Switch to a different model |
/thinking <level> | Set thinking level |
/name <name> | Name the current session |
/clear | Clear the screen |
Set the corresponding environment variable to enable a provider:
| Provider | Env Var (API Key) | Env Var (Base URL) | Default URL |
|---|---|---|---|
| DeepSeek (default) | DEEPSEEK_API_KEY | DEEPSEEK_BASE_URL | https://api.deepseek.com |
| Moonshot (Kimi) | MOONSHOT_API_KEY | MOONSHOT_BASE_URL | https://api.moonshot.cn |
| Ollama | OLLAMA_API_KEY | OLLAMA_BASE_URL | http://localhost:11434 |
At startup, zcode checks for these environment variables and enables the corresponding providers automatically. Models are fetched from each provider's API and cached locally.
You can also store credentials in ~/.zig-code/agent/auth.json.
Settings are read from ~/.zig-code/agent/settings.json. Supported keys:
| Key | Type | Description |
|---|---|---|
defaultProvider | string | Default provider name |
defaultModel | string | Default model ID |
defaultThinkingLevel | string | Default thinking level |
hideThinkingBlock | bool | Hide thinking output in streaming |
showHardwareCursor | bool | Use hardware cursor in line editor |
followUpMode | string | Follow-up behavior |
transport | string | HTTP transport override |
All 7 tools are enabled by default in interactive mode:
| Tool | Description |
|---|---|
bash | Execute shell commands |
edit | Edit files with targeted find-and-replace |
read | Read file contents |
write | Create or overwrite files |
ls | List directory contents |
find | Find files by glob pattern |
grep | Search file contents |
MIT
