Quickstart: the zelk command in scripts and CI
The zelk command runs without a person at the keyboard: in a shell script,
a scheduled job or CI. Print mode (zelk -p) runs one task and prints
the answer. zelk exec keeps its sessions, so a later run can resume
them, and can write structured output. Neither opens the terminal UI, and
neither asks you anything. This page takes you from a built zelk to a
command you can put in a script. If you haven’t built it yet, start with
Get zelk.
Give it a model
Section titled “Give it a model”Print mode and exec take the provider from flags and environment
variables. They don’t read the terminal UI’s providers file, so a machine
where you only ever run scripts needs no setup screen. The default provider
is openai-compat, an OpenAI-compatible API, and it reads its key from
OPENAI_API_KEY:
export OPENAI_API_KEY=…zelk -p -mode plan "What does this repository do?"$env:OPENAI_API_KEY = '…'zelk -p -mode plan "What does this repository do?"The default model is gpt-5, so the commands on this page leave
-provider and -model out. To use another provider or model, give
-provider and -model on every command, since neither is remembered
between runs:
export ANTHROPIC_API_KEY=…zelk -p -mode plan -provider anthropic -model claude-sonnet-5-5 "What does this repository do?"-provider picks the API (openai-compat, openai, anthropic, gemini,
opencode, chatgpt, or ollama, lmstudio and llamacpp for a server on
your machine). The key comes from the provider’s variable, such as
ANTHROPIC_API_KEY or OPENAI_API_KEY, and -base-url (or OPENAI_BASE_URL
and its siblings) points at another server. With the default provider,
OPENAI_BASE_URL alone is enough for a server that needs no key:
export OPENAI_BASE_URL=http://localhost:11434/v1zelk -p -mode plan -model qwen3:8b "What does this repository do?"Get zelk lists every provider with its variables. When neither a key nor a base URL is set, zelk stops with exit status 2 and says which variables to set.
The provider and the model come only from flags and variables, not from
config.json: it rejects both keys. Saved run options such as sandbox,
deny and max_turns do live there, in ~/.config/zelk/config.json
(%APPDATA%\zelk\config.json on Windows), and stand in for flags you leave
out; the settings reference lists them. A script that
must behave the same on every machine should give its flags itself.
Run one task
Section titled “Run one task”zelk -p -mode plan "How many lines does README.md have?"README.md has 12 lines.The answer goes to standard output. What the agent does along the way goes to standard error, so a script can capture the answer and keep the log. Each tool call is one line there, naming the tool and its input:
→ Read {"file_path":"README.md"}A run that only answers writes nothing to standard error.
Name the permission mode every time you run unattended. Print mode starts in
bypass, which lets anything a rule doesn’t deny run, and nobody is there to
stop it. -mode plan is read-only: the agent explores and answers.
-mode accept-edits lets it edit the workspace and still refuses what needs
a person, such as a command that isn’t read-only. Permissions
explains each mode and In CI shows a locked-down
job.
The task is the argument, or the standard input when there is none:
echo "How many lines does README.md have?" | zelk -mode planWithout a terminal on standard input or output, zelk is in print mode
already, so -p is for a terminal.
Keep the session with exec
Section titled “Keep the session with exec”zelk exec runs a task headless and keeps the session in the state
directory, so a later run can continue it. It is read-only unless you give
it -mode, and says so on standard error:
zelk exec "summarize the open TODOs"zelk exec -mode accept-edits "fix the typo in README.md"zelk exec resume --last "and the one in CONTRIBUTING.md"Flags go before resume. --last takes this directory’s last exec
session; the session keeps its conversation and the new launch decides its
mode and limits. -state DIR keeps sessions somewhere else, which is the
way to give a job a scratch state, and zelk sessions -state DIR list shows
what it kept (Sessions); it prints a JSON array, one object
per session, with its ID, title and timestamps, so pipe it to jq to pick
fields. A line on standard error ends each exec run with its turns and
tokens:
zelk exec: 2 turns · 200 input tokens · context 100 tokensChoose the output
Section titled “Choose the output”| Flag | Writes |
|---|---|
| (none) | the final message to standard output, progress to standard error |
-json |
every event as JSON Lines to standard output |
-o FILE |
the last message (or the structured result) to a file |
-result FILE |
the outcome, usage, report and final text as JSON |
-output-schema FILE |
makes the run deliver a value that fits a JSON Schema, on standard output |
-result is the one to read from a script: the outcome is a field, not
something to parse out of prose.
zelk -p -mode plan -result result.json "How many lines does README.md have?"{ "outcome": "success", "turns": 1, "usage": { "input_tokens": 100, "output_tokens": 10 }, "report": { "goal": "How many lines does README.md have?", "goal_revision": 1, "goal_status": "met", "verification": "none_available", "claimed": "met", "summary": "README.md has 12 lines.", "requirements": [ { "requirement": "the request", "confirmed": "ran_check", "how": "checked in this run" } ] }, "text": "README.md has 12 lines."}The numbers here are those of a scripted test model; a real run reports its own. Print mode and exec shows an output schema and what each flag writes.
Act on the exit status
Section titled “Act on the exit status”A script decides on the exit status, not on the text:
| Status | Means |
|---|---|
| 0 | the run succeeded, with every requirement confirmed |
| 1 | the run didn’t succeed (work left undone, or it failed), or an error stopped it |
| 2 | a usage error: a bad flag, no provider, no task |
| 3 | the run finished but is unverified: a requirement the model had no way to check here, which standard error names |
| 130 | interrupted |
Status 3 is the one scripts miss. The agent did what it was asked and says so, but couldn’t confirm part of it. Whether that passes is your call, so handle it on purpose:
status=0zelk exec -mode plan -result result.json "How many lines does README.md have?" </dev/null || status=$?case $status in 0) echo "done" ;; 3) echo "done, not fully verified: see the log" >&2 ;; *) echo "zelk failed" >&2; exit 1 ;;esacCapturing the status with || status=$? keeps the script going under
set -e, where a bare zelk that exits with 3 would end it before the
case ran.
Give the agent a check to run, such as -verify 'test=go test ./...', and a
run can’t end as a success while that check is failing, so status 0 means
something. Runs and completion explains the outcomes.
Run it where nobody is watching
Section titled “Run it where nobody is watching”- Redirect standard input from
/dev/nullwhen nothing is piped in, sinceexecreads piped input until it ends and a CI shell’s input may never end. In PowerShell, pipe$null:$null | zelk exec "…". - Nobody can answer a request, so
-input deny(the default) refuses what the mode wouldn’t allow. A sandbox (-sandbox bwrapon Linux,seatbelton macOS) with-network offlimits what an allowed command can reach. -max-turns Ncaps a run.
In CI covers these in a job, and the pages on policy and credentials cover what a shared machine needs.
- Print mode and exec: every output flag, schemas and sessions
- Permissions in practice: modes, rules and approvals
- The CLI reference: every command and flag
- Embed zelk in Go when a script outgrows the command
- Try the terminal UI