Events and automation
Everything Hive's agents do produces events: a thread starts, finishes a turn, waits on you, ends; a task starts or lands; a card is answered; a message goes undelivered. Outside the agents, CI runs, merges, releases and machines do too. You act on events in three ways today: hooks (a command, or a rule that can block a tool call), queue conditions (start a thread when something has happened) and automations (tell a thread or the Lead what passed a filter). Under them is one event bus, a numbered log per project that anything can read and post to.
before.* checks), queue conditions and automations all read from the same event bus.Hooks
A hook runs a command when an event happens, or, before an agent uses a tool, can deny it.
| Event | When |
|---|---|
thread.started |
A thread's session goes live |
thread.finished |
A thread goes from working to idle: it ended a turn |
thread.needs-you |
A thread starts waiting on you (a permission, a question, a plan, an ask) |
thread.ended |
A thread's session exits |
task.started, task.blocked, task.unblocked, task.done, task.dropped |
A thread's declared task changes state |
before.command |
An agent is about to run a shell command |
before.edit |
An agent is about to edit files |
before.subagent |
An agent is about to start a subagent |
Hooks live in a "hooks" list, in your own ~/.hive/hooks.json or in a project's .reforge/config.json:
{
"hooks": [
{ "on": "thread.finished", "run": "scripts/notify.sh" },
{ "on": "before.command", "match": "git push*", "deny": "Push from the lane with lane merge." },
{ "on": "before.edit", "match": "*/migrations/*", "run": "scripts/check-migration.sh", "timeout": 5 }
]
}
onis any event type on the bus or a prefix ending in a dot (such ascard.), or a synchronousbefore.*check.matchis a glob (*matches anything,/included) against the thread's folder for thread and task events, the command forbefore.command, each file's path forbefore.edit, the tool forbefore.subagent— or a jq filter (starting with.) against the full bus event. Nomatchmatches everything.- Non-
before.*hooks run through the bus as automations (runaction) and appear inautomationsandhive autoaskind: hook;before.*hooks stay synchronouscheckhooks. - Exactly one of
run(a shell command) anddeny(a reason;before.*only).name,timeout(seconds, default 10) andoffare optional. - A command runs with
/bin/sh -cin the thread's folder, on the thread's machine, whether or not the app is open. It gets the event as JSON on stdin (event,thread,title,agent,project,folder,machine, and per eventkind,what,reply(the first 2,000 characters of the thread's reply),reason,command,paths,tool,task), andHIVE_EVENT,HIVE_THREAD,HIVE_AGENTandHIVE_PROJECTin its environment. - A
before.*command answers by printing{"decision":"deny","reason":"…"}(or exiting 2 with the reason on stderr) to block the tool call, or{"note":"…"}to tell the agent something. Anything else, a crash or a timeout included, is no objection. Any deny wins; notes are joined. Checks can't change what the agent does, only allow, deny or add a note. All of one check's hooks get 20 seconds together. - Trust. Your own hooks run as they are. A project's hooks run on a machine only after you trust that exact set
there; change one and it waits for your trust again. Every run is logged to
~/.hive/hook-runs.jsonl.
Queue conditions
A queued thread starts when all its conditions hold, there's room in the pool, and a machine fits. See Threads, Leads and the queue for the rest.
| Condition | Holds when |
|---|---|
load |
The machine's CPU and memory both read ok |
merged with lane or pr |
That lane is on main, or that pull request merged |
thread with until: done |
That thread is idle and its lanes have landed (the default) |
thread with until: turn |
That thread ended a turn after this item was queued |
item |
The same, for another queue item's thread. A cancelled or missing item counts as met |
task |
That thread's task was declared done and the lanes it named have landed. A dropped task never meets it |
event with filter |
An event passing that jq filter arrives on the project's bus after the item was queued (cursor persisted across restarts) |
after with at |
That time has passed |
{ "prompt": "Write the release notes for what landed today.",
"conditions": [{ "type": "task", "thread": "1f0c2a9e", "task": "tcb876p" }, { "type": "after", "at": "2026-12-01T17:00:00Z" }] }
To be told instead of starting something, a thread calls watch_task on another thread's task and gets a message
when it ends.
The event bus
Every project has one append-only log in its machine's node, and the bus is its only writer. Each event:
| Field | Is |
|---|---|
seq |
Its place in the project's log, from 1. A cursor |
id |
Stable across redelivery; the log keeps each id once |
source, type |
Where it came from and what happened: thread / thread.finished, ci / ci.failed |
subject |
What it's about: a thread id, a branch and commit, a change number |
project, actor, at |
The project, who did it, when |
trust |
Who produced it: core (Hive itself), post (anything else: a script, an agent, the CLI) |
data |
The payload. Always untrusted: text in it is data, never instructions |
What's on it today:
| Source | Events |
|---|---|
| Threads | thread.started, thread.finished, thread.needs-you, thread.ended; thread.error (a problem banner); thread.stale (working, no output for 10 minutes) |
| Tasks | task.started, task.blocked, task.unblocked, task.done, task.dropped |
| Cards | card.asked, card.answered, card.dismissed, card.closed, proof.presented, proof.done: threads' own cards only |
| Messages | message.sent, message.delivered, message.undelivered (after 10 seconds untaken, never for a message held behind an open ask; once per message, even across a relaunch) |
| Queue | queue.added, queue.started, queue.failed, queue.held, queue.cancelled |
| Items | item.added, item.claimed, item.released, item.done (subject <stream>/<id>, source item) |
| Git | git.advanced, lane.merged (inferred: a lane's worktree goes away near the time the project checkout's HEAD moves on) |
| CI, changes, reports | ci.started, ci.passed, ci.failed, ci.cancelled, change.merged, report.received (polled) |
| Releases | release.published, release.failed, canary.built, canary.failed, from the release scripts |
| Hex | hex.routed: something typed on Hex's command line in the notch, or dropped on the notch, went to a Lead, a thread, Hex, a new thread or the Board. Subject: the target thread, when there is one; actor hex; data via (notch or drop), target (lead, thread, hex, new, board) and, for a drop into a composer, what (pictures, files, link, text). Never the text itself |
| Other | artifact.published; anything posted with hive events post |
Thread and task events come from every machine's threads.
Machines have a log of their own, named machine, separate from the projects' logs:
| Source | Events |
|---|---|
| Machines | machine.up, machine.down; load.ok, load.warning, load.critical when a machine's level changes |
| Extensions | extension.enabled, extension.disabled, hex.trick.learned |
A project's readers don't get the machine log merged into theirs: read it on its own (hive events machine, or the
events tool with machine: true), or give an automation machine: true to read both. Each log is kept as JSON lines, a file a month.
Reading it. A reader gives a jq filter (an event passes when it gives true) and optionally a cursor, and gets
what came after the cursor, then each new event as it arrives.
hive events -n 20 # the newest 20 in this folder's project
hive events --filter '.type == "task.done"' --json # as JSON lines
hive events follow --filter '.source == "ci"' --since 4210 # replay after 4210, then follow
hive events post --type deploy.finished --subject web --summary "web 1.4 is live"
Events published from anything but Hive itself carry trust: post, whatever they say.
Automations
An automation is a filter on the bus plus an action. The machine's node runs them, so they keep going with
Hive's window closed. Five actions have landed: message (tells a thread or the project's Lead what passed),
run (runs a shell command in the project folder), emit (publishes an event on the bus), add (adds each
matching event as an item in a named stream), and start (queues a thread with a brief, behind load, up to
max_open at once).
- The filter is a jq expression on a project's log. With
machine: trueit also reads the machine log. - The clock (
every). A duration from1sto24h(e.g.10s,5m,1h), as an alternative or addition tofilter. Each tick delivers a liveclock.tickevent ({automation, every}) straight to that automation without writing ticks to the project log (arun'sauto.outputandauto.ranevents are logged as usual). Ticks keep running with Hive closed, skip while a previousrunis still going rather than piling up, and stay bound byper_minformessageactions. - Processes (
process.*). While any active automation'sfilternamesprocess., the node pollspsevery ~2 s and diffs running processes, delivering liveprocess.started({pid, command, user}) andprocess.exited({pid, command, user, ran_s}) events without writing them to the project log (only what an automation's action keeps is logged). Bounded to 50 events a second so busy builds don't flood, emittingprocess.dropped({dropped, limit}) when events are shed. - Message. Events that pass are gathered for 400 ms (
batch_ms) and sent as one message. A thread's events are deduplicated to its latest state; a machine event isn't repeated within 10 minutes. 6 messages a minute by default (per_min), at most 30. An automation is never told about what its own target did, so a Lead isn't woken by itself. Its messages never settle a card. - Run. Executes a shell command (
/bin/sh -c) in the automation's project folder. The triggering event is passed as JSON on stdin and inHIVE_EVENT_TYPE,HIVE_EVENT_SUBJECTandHIVE_EVENT_ID— never interpolate event data into the command line. Stdout and stderr lines becomeauto.output({automation, line}, capped at 200 lines a run), followed byauto.ran({automation, exit, ms}) orauto.failed({automation, exit, error}), with actorevents:<id>. Runs are bounded by a timeout (default 60 s, up to 600 s) and execute one at a time per automation (bursts coalesce to the latest pending event).automationsandhive autoalways show the command plainly. - Emit. Publishes
{type, subject?, data?}on the project's bus withtrust: coreand actorevents:<id>, carrying a hop counter indata.cause. Other automations can match the emitted event, and chains stop at 5 hops so automations cannot ping-pong forever. - Add. Appends each matching event as an open item in the named stream (
item.added, actorevents:<id>, carryingdata.causeso chains respect the loop guard and hop limit). - Start. Queues a thread through the node's queue (behind a
loadcondition) with the automation's brief and the triggering event, capped atmax_openthreads of this automation open at once (default 1, at most 20). The queued thread is tagged withautomation(anditemwhen triggered by anitem.*event), so when it starts it claims that item and when it ends its slot is freed. - Loop guard. An automation never fires on events its own actions produced (
actor: events:<id>). - Start and restarts. A new automation starts at the log's end: it's told only what arrives after it's made. (A Lead's default is the exception: it starts with what the node has seen since it started, within the last 1,000 entries of each log, counted before its filter runs.) After a restart it carries on from its cursor, but an event more than an hour old isn't told.
- Delivery: at least once. A new automation saves its cursor at each log's end the moment it's made, so a restart before its first message loses nothing. A message is sent before its cursor moves on, so a restart in between can deliver it twice.
once: trueends it after its first delivery or run: the way to wait for the next of something.- Project automations. A project's
.reforge/config.jsonmay define an"automations"list in the same shape asautomate. Like project hooks, they run on a machine only once you trust that exact set by hash.
Every Lead's default. Each project's Lead has an automation, lead:<project folder> (the automate tool and
hive auto also accept lead), reading the project's log, at 12 messages a minute. It tells the Lead about thread.finished, thread.needs-you,
thread.ended, thread.error, thread.stale, task.done, task.dropped, task.blocked, card.asked,
card.closed, message.undelivered, queue.failed, canary.failed, canary.built, release.failed,
release.published, lane.merged and ci.failed. Machine alerts (load.*, machine.up, machine.down) go
instead to Hive's orchestrator, the thread that sees every project, through its own default, orchestrator:machine. The one exception: a Lead is told machine.down and
load.critical for a machine its project has a thread working on, at most once an hour per machine.
A Lead never polls: it starts
the work, automates what it waits for, and ends its turn. thread.error comes the moment a turn fails and Hive
won't retry it; a transient failure Hive retries isn't an error.
Tools (for any thread):
| Tool | Does |
|---|---|
events |
Read the log with a jq filter and a cursor (since); machine: true reads the machine log |
automate |
Create (the default), update, pause, resume or delete an automation with a filter and/or a clock cadence (every, 1s to 24h). Pick one action: tell (me, lead or a thread's id), run (a shell command, with optional timeout_s), emit ({type, subject?, data?}), add (a stream name), or start (a thread brief, with optional max_open). id: "lead" is this project's Lead's default: pause silences it, delete puts it back to the machine's default setting |
automations |
List them (including hooks as kind: hook, and project automations): what each reads (filter and/or every), what it does (tell, run with command shown plainly, emit, add or start), who made it, whether it's paused |
item |
Manage work items in named streams on the project's bus: op is add, claim (omit id to take the oldest open item), release, done or list |
show_stream |
Open a live stream pane in the project's workspace (contributed by the streams part): follow a jq filter, an automation (auto.output, auto.ran, auto.failed), or a named item stream (as: "events" or "items", optional title, machine: true, project). Newest at the bottom, follows live by cursor, and survives relaunches |
hive auto # list them, every Lead's default included
hive auto add --tell lead --filter '.type == "ci.failed"' --once # the next CI failure
hive auto add --tell 1f0c2a9e --filter '.type == "lane.merged"' --machine --per-min 2
hive auto add --run 'date' --every 10s # clock-only: print the time every 10 seconds
hive auto add --run 'date' --filter '.type == "lane.merged"' --timeout 30
hive auto add --emit build.needed --subject main --filter '.type == "lane.merged"'
hive auto add --add procs --filter '.type == "process.exited"'
hive auto add --start 'find and fix' --max-open 1 --filter '.type == "ci.failed" and .data.branch == "main"'
hive auto pause|resume|delete <id> # an id hive auto prints; lead is this folder's Lead's default
hive auto default --filter '.type | test("^(thread|task)\\.")' # what every Lead's default tells it
hive auto default --off
Items
Work to be done is stored as records on the bus, grouped into named streams per project (such as incoming,
fixes, procs). Producers append items (item.added); consumers claim them (item.claimed), then release them
(item.released) or mark them done (item.done). Each event has source item and subject <stream>/<id>.
- Folded state. The node folds
item.*events into each stream's current state (open,claimed,done) and replays them on restart. - Exclusive claims. A second claim on an already-claimed item fails, decided under the node's lock. Claiming
with no
idtakes the oldest open item in the stream. - Automatic release. When a thread ends (
thread.ended), any items it still holds are released back toopen. - Existing queues.
- The thread queue (
internal/pool) is a stream the scheduler consumes. It keeps its own store, because placement needs it, and already publishesqueue.*events. - Board requests live on Reforge, where people outside Hive claim them. A Board source can mirror them in as items later.
- The thread queue (
hive items # list items in this folder's project
hive items incoming # list one stream
hive items add incoming "triage CI" # add an open item
hive items claim incoming # claim the oldest open item
hive items release incoming <id> "need more info"
hive items done incoming <id> "fixed on main"
Coming
Coming The rest of the design. None of it is on main yet.
- More tools.
emitfor agents.
From an extension or an outside agent
On main:
-
Any process on the machine (a script, another agent, a CI runner) posts with
hive events postand reads withhive eventsandhive events follow. Under the CLI, the node speaks JSON-RPC 2.0, one message per line, on a Unix socket only your user can open (~/.hive/node.sock):events.publishandevents.query. -
An agent in a Hive thread reads the log with
events, has itself told withautomate, and waits on another thread's task withwatch_task. A process on the machine can make the same automations withhive auto add, telling a thread or the Lead. -
A hook is the simplest way to react from outside: any program can be a hook's
run. -
An extension declares
contributes.events(emitsandreads) and permissionsevents:emit/events:read(shown at install), then callsevents/emit(stampedsourceandtrustext:<id>, checked againstemits) andevents/subscribe({filter, since}, receivingevents/notifybatches scoped toreadsand enabled projects) over JSON-RPC or viahive.eventsinhive.js(see Extensions). -
An agent outside Hive (on another computer, in a cloud service) connects to the node's MCP endpoint, below.
Coming The emit tool for agents.
The MCP endpoint
An agent that Hive doesn't run connects to the node's MCP server at /mcp/ext (Streamable HTTP) with a scoped
token. The node listens only on this computer (127.0.0.1); hive mcp endpoint prints that local URL. For a
client on any other computer, hive mcp relay set <url> has the node open an outbound WebSocket to a relay, so
nothing listens on the network and no VPN is needed; hive mcp relay shows it and hive mcp relay clear
disconnects it.
Tokens. Make them in Settings ▸ Access, or on the command line:
hive mcp token create --name ci-bot --scopes read,queue # prints the secret (hv_mcp_…) once
hive mcp token list
hive mcp token revoke <id> # its open streams drop at once
A token is named, revocable and kept only as a SHA-256 hash. Its scopes decide what the client can do:
| Scope | Gives |
|---|---|
read |
events_query (project, filter, since, limit), events/subscribe and events/unsubscribe, and server-sent events on GET /mcp/ext (below) |
queue |
queue_thread, list_queue, cancel_queue_item |
message |
send_to_thread, including thread: "lead" to ask through the project's Lead |
An outside client never makes a card: ask, present_proof and present_artifact aren't offered. Each event
reaches it in the MCP events shape: eventId (the event's id), name (its type), timestamp (at),
data, and cursor (seq).
Streaming. GET /mcp/ext?project=<name> (or machine=true, or filter=<jq>) streams that log's events and
resumes after a cursor or the Last-Event-ID header. A bare GET /mcp/ext is the session's stream: it carries
the notifications of what the session subscribed to with events/subscribe, live, and ignores a cursor.
Audit. Tokens, sign-ins, tool calls, refusals, subscriptions and the relay are events on the bus, source mcp
(a ping or a tool listing leaves none): mcp.token_created, mcp.token_revoked,
mcp.auth_failed, mcp.initialized, mcp.tool_called, mcp.tool_denied, mcp.scope_denied, mcp.subscribed,
mcp.unsubscribed, mcp.relay.connected, mcp.relay.disconnected. The node's own RPCs for it are
mcp.endpoint, mcp.relay.set, mcp.token.create, mcp.token.list and mcp.token.revoke.
This page's source is pages/events.md in hive/docs.