Extending zelk
You extend zelk in four ways: a Go tool of your own, an MCP server, a subagent, a hook. Each plugs into the loop at a different place, and the place decides what zelk can promise about it. A tool zelk can trust to repeat is recovered one way after a crash; a tool it can’t is recovered another. A hook that decides before a call starts has no call to clean up after.
The diagram is the loop’s ring from The loop, with each extension drawn where it attaches. The scenes below it play a hook that says no and one that asks you, an MCP call, a subagent, and a crash in the middle of an MCP call.
- Gate hook (between ask and record intent): decides before the call’s intent exists; its decision is recorded and never re-run on replay.
- Go tool (do it): shares a wave and is run again after a crash only as far as it declared read-only, idempotent or an idempotency key.
- MCP server (do it): never read-only, so it runs alone; a call cut off by a crash is recorded as unknown.
- Subagent (do it): a session of its own, with a log and a lease; the parent’s log holds the call and two records that link the logs.
- A hook says no: A gate hook decides before the call has an intent. The fold asks for the hook, not the call. The hook’s decision is recorded, and deny turns the call back with a refusal as its result. No intent is ever written, so a crash leaves nothing to reconcile, and a replay reads the recorded decision instead of running the hook again.
- A hook asks you: Ask sends the call out to a person. The call waits as an approval and nothing runs. If you allow it, its intent is recorded and it goes on. If you deny it, it ends as a refusal with no intent, as deny does. A hook that answers defer asks the same way, and lets the session suspend while it waits.
- An MCP call: A tool from an MCP server never shares a wave. order_status is a Go tool that declared itself read-only, and zelk trusts the host’s own tools, so it gets a wave. The MCP tool says it is read-only too, but zelk never relies on a server’s word: it runs alone, behind its own gate. The hook’s allow still meets the permission rules.
- A subagent: A subagent is a session of its own. The Task call starts it, runs alone like any call that may change things, and waits. The child goes round the same loop with its own log. When it ends, its report comes back as the call’s result, and the parent’s log gains only the call and two records that link the logs.
- A crash mid-MCP-call: A call cut off by a crash is unknown, not run again. The log ends at the intent. A new process finds the call open and can’t tell whether the server acted, so it records the outcome as unknown and tells the model to check. A Go tool that declared a read-only, idempotent call, or enforces an idempotency key, is run again instead.
Two places matter. A gate hook sits between asking for a call and recording its intent. Everything else sits at do it: a Go tool, an MCP tool and a subagent are three ways to run a tool call.
Your own Go tools
Section titled “Your own Go tools”A Go tool declares what it is. tool.Define takes the schema from the
input type, and options say whether the tool is read-only, idempotent, or
keyed by an idempotency key (Custom tools lists them). zelk
checks the model’s input against the schema before the handler runs.
The declarations are promises, and zelk acts on them:
- Read-only lets the call share a wave with other read-only calls and run in plan mode. Any other call runs alone.
- Read-only and idempotent lets recovery run the call again after a crash, since a repeat can’t change anything.
- An idempotency key lets recovery run the call again with the same key, once the tool deduplicates by it. The key is the same on every attempt.
A tool that declares none of these is left unknown after a crash: zelk
can’t tell whether it ran. zelk believes the declarations of tools written
in Go by the host, so a tool that claims to be read-only and isn’t breaks
the promise.
MCP servers
Section titled “MCP servers”An MCP server is a separate program that offers tools over the Model
Context Protocol. Its tools join the tool list as mcp__server__tool, and
rules and hook matchers name them like any other. zelk never trusts a
server’s claim that a tool is read-only, so an MCP call runs alone, asks in
default mode until a rule allows it, and is recorded unknown if a crash
cuts it off. A stdio server runs under the sandbox like any command; what an
HTTP server does on its own host is beyond any sandbox.
MCP servers explains the protocol and each of these.
Subagents
Section titled “Subagents”A subagent is a child session that a Task call starts, with its own log,
its own lease and, if the host set one, its own share of the budget. Its
authority only narrows from its parent’s, at most five run at once, and a
child can’t start children of its own. Its questions reach you through its
parent. Subagents explains how a tree of sessions
runs, asks and recovers.
A hook runs your code at a fixed point in a session. A gate hook, such
as PreToolUse, decides before a call has an intent, so a denied call never
starts; its decision is recorded and never run again on replay. An async
hook only observes, best effort. Hooks lists every
event and what each decision and failure does.
When to use which
Section titled “When to use which”| You want to | Use | It plugs in at | Watch for |
|---|---|---|---|
| Give the model an action only your code can do | A Go tool | do it | Your declarations decide waves and recovery, so they must be true |
| Use tools someone else wrote, in any language | An MCP server | do it | A call runs alone, asks by default and ends unknown after a crash |
| Hand off a piece of work with its own context | A subagent | do it, as a Task call |
A child has less authority than its parent, and can’t start children |
| Refuse, rewrite or ask about a call by policy | A gate hook | before the intent | A hooks.json hook that fails lets the call go unless it blocks on failure |
| Watch what happens without changing it | An async or observe hook | after the fact | It is best effort and may not run |
Where to go deeper
Section titled “Where to go deeper”- MCP servers, Subagents and Hooks: each extension on its own page
- Custom tools, Skills and subagents, MCP servers and Hooks: how to write and configure each
- The loop: the ring, its waves and its subagents
- Durability and recovery: how recovery settles a call a crash left open
- Permissions: where hooks sit in each decision
- The tools contract, the hooks contract and the embedding contract: the exact rules
- The durability contract gives the hook protocol and how a tree of sessions suspends.