Skip to content

Repository files navigation

zcode

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.

zcode

Features

  • 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 toolsbash, 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 levelsoff, low, medium, high, xhigh for reasoning models
  • Token stats & cost estimation — track usage and estimate spend per session

Requirements

  • Zig ≥ 0.16.0

Quick Start

# 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

CLI Options

FlagDescription
-c, --continueContinue 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-modelsList all available models
--list-providersList configured providers
--tools <list>Specify which tools to enable (comma-separated)
--debugShow debug output
--helpShow usage
--versionShow version

Interactive Commands (REPL)

CommandDescription
/helpShow available commands
/quit, /exitExit the program
/sessionShow current session info
/statsShow token usage, cost estimate, and memory
/newStart a fresh session
/model <id>Switch to a different model
/thinking <level>Set thinking level
/name <name>Name the current session
/clearClear the screen

Providers

Set the corresponding environment variable to enable a provider:

ProviderEnv Var (API Key)Env Var (Base URL)Default URL
DeepSeek (default)DEEPSEEK_API_KEYDEEPSEEK_BASE_URLhttps://api.deepseek.com
Moonshot (Kimi)MOONSHOT_API_KEYMOONSHOT_BASE_URLhttps://api.moonshot.cn
OllamaOLLAMA_API_KEYOLLAMA_BASE_URLhttp://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.

Configuration

Settings are read from ~/.zig-code/agent/settings.json. Supported keys:

KeyTypeDescription
defaultProviderstringDefault provider name
defaultModelstringDefault model ID
defaultThinkingLevelstringDefault thinking level
hideThinkingBlockboolHide thinking output in streaming
showHardwareCursorboolUse hardware cursor in line editor
followUpModestringFollow-up behavior
transportstringHTTP transport override

Built-in Tools

All 7 tools are enabled by default in interactive mode:

ToolDescription
bashExecute shell commands
editEdit files with targeted find-and-replace
readRead file contents
writeCreate or overwrite files
lsList directory contents
findFind files by glob pattern
grepSearch file contents

License

MIT

About

AI coding agent in a 1.7 MB Zig binary — zero dependencies, single executable

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages