The agent loop, as a Go library.
zelk runs the loop: model calls, tools, permissions, context and recovery. Your program keeps everything else: the process, storage, isolation, scheduling and who the user is. Embed it in a Go program, run the zelk command from scripts and CI, or try it in a terminal.
- 1session_startedtools Read Edit Write Glob Grep Bash
- 2command_acceptedfix the failing test in ./pkg/foo
- 3run_startedgoal: the request
- 4effect_startedcall_provider
- 5effect_finishedBash go test ./pkg/foo
- 6effect_startedrun_tool Bash
- 7effect_finishedexit 1 FAIL TestParseEmpty
- 14file_changedpkg/foo/parse.go
- 18effect_finishedexit 0 ok pkg/foo
- 19report_recordedmet, with the test run as evidence
- 20run_finishedmet
zelk runs the loop. Your program runs the rest.
Section titled “zelk runs the loop. Your program runs the rest.”zelk dictates nothing about where it runs. Everything it needs from the outside world arrives as a value you pass in, so the same loop works in a web service, a queue worker, a CI job or a terminal.
Your program a CLI, an HTTP service, a queue worker, a Temporal workflow, a CI job
zelk
- Model calls, with retries and budgets
- Tool dispatch and permission checks
- Context compaction before the window fills
- Completion checks before a run may end
- Recovery from the log after a crash
The model
zelk.New(ctx, provider.Provider)OpenAI, Anthropic, Gemini, any OpenAI-compatible server, or your own
Storage
WithStore(store.LogStore)in memory by default; files, or a database you own
Who runs a session
WithLease(lease.Lease)only one process runs a session at a time
The workspace
WithEnvironment(env.Environment, dir)a directory, a sandbox, a container
Your tools
WithTools(...*tool.Tool)beside Read, Edit, Bash and the rest
People
WithInputCallback(cb)questions, plans and approvals, answered live or later
One run, step by step:
- The run starts: zelk takes the session’s lease.
- The request is appended to the log.
- zelk calls the model.
- The model’s reply is appended.
- The model asks to run go test ./pkg/foo, so zelk asks a person.
- The person’s answer is appended.
- Approved: zelk hands the call to the tool,
- which runs it in the workspace.
- The result is appended.
- zelk calls the model again with the result.
- The model’s report is appended.
- The run ends: zelk releases the lease.
Stop it anywhere. It picks up.
Section titled “Stop it anywhere. It picks up.”The process dies; the log doesn’t. The next Start reads the log back and
settles whatever was in flight: a model call is tried again, and a command
that may already have acted is never run twice.
- Killed while a model call is in flight: the next start closes the attempt as lost and starts attempt 2.
- Killed while a command runs: the command is never run again; it is recorded with outcome unknown, and the model is told to verify before retrying.
- Killed between events: nothing was in flight, so the next start rebuilds the state from the log and goes on.
Three ways in
Section titled “Three ways in”Embed the library
The way zelk is meant to be used. One call runs a task with no setup at all.
When you need more, zelk.New takes each dependency as an option, and checks
the whole configuration before it runs anything. The call is
zelk.Run(ctx, task).
Run it from scripts and CI
zelk -p runs one task and prints the answer; zelk exec keeps resumable
sessions and structured output; zelk acp serves editors. The command is a
host like any other, built only on the public API.
zelk -p -mode plan "…"Try it in a terminal
The quickest look at zelk: a full-screen chat in your repository that asks before it edits. Build it, give it a model and give it a task in a minute.
zelkSee it in a terminal
Section titled “See it in a terminal”This is the terminal UI, the zelk command’s full-screen mode and the quick
way to try zelk. It is not the Go library but a host built on it, one that
asks before it edits. Here it works on a Go package with a failing test, from
one request to fix it. To embed zelk in your own program
instead, follow the Go quickstart, which runs an agent in a few
lines.
zelk asks before it runs the tests and before it edits, fixes Count,
runs the tests again and reports what it changed. Recorded with Claude
Sonnet 5.5 at its real pace; pauses longer than a second and a half are
shortened.
New here? Get zelk shows how to add it to a module or build the command, and How zelk works explains the ideas underneath.