Skip to content

Sessions and forks

A session is one agent run for one intent. When zt start registers an intent that runs an agent now, the coordinator creates the session in the same transaction and returns a session token. zt then makes a branch and a worktree, writes the kit, and starts the agent in a detached tmux session or an OpenShell sandbox. The session ends when you run zt done, or when the coordinator stops hearing from it.

A fork is a second intent that competes with existing work on purpose. You ask for one with zt start --fork, or by picking fork when your own task matches. Dedup then skips the original’s family, so both attempts run side by side.

A session is in one of seven states. It begins in starting, and zt start sets it running once the agent is launched. done, failed, and abandoned are terminal.

From Allowed next states
starting running, failed, abandoned
running waiting_human, idle, done, failed, abandoned
waiting_human running, done, failed, abandoned
idle running, done, failed, abandoned

Setting the current state again changes nothing. Any other move fails with invalid_transition. POST /v1/sessions/{session_id}/status changes the state. The session’s own token, its owner, or an admin may call it. A status change locks the session row, so a session cannot end while one of its claim requests is in flight.

When a session reaches a terminal state, the coordinator does four things in one transaction:

  1. It releases the session’s file claims with reason session_end.
  2. It revokes the session’s tokens, audited as token.revoke.
  3. It settles the intent, when the intent is still active. done makes it done, and failed or abandoned makes it abandoned.
  4. It writes an intent_unblocked notice to the owner of each queued intent that waited on this one.

waiting_human releases the session’s claims with reason waiting_human. A claim request in that state gets 409 session_waiting, and the session must go back to running first.

With the local-dev launcher, zt start runs a hidden sidecar, zt heartbeat --session SESSION_ID, in a tmux window named zentri. With the openshell launcher, the sandbox runs it. Every minute it calls POST /v1/sessions/{session_id}/heartbeat. Each heartbeat extends the session’s live claims by 30 minutes and may set an activity line of up to 120 characters. Heartbeats are not audited.

The sidecar stops when the coordinator answers 401, 403, 404, or 409 session_ended, or when the token file is gone. It retries other errors.

The coordinator’s sweeper marks a session abandoned after 10 minutes without a heartbeat. It counts from the later of the last heartbeat and the coordinator’s own start, so a coordinator restart does not abandon every session. The same sweep expires claims past their TTL.

The coordinator returns a zt_s_... token with the session. zt writes it to <state>/sessions/<session_id>.token with mode 0600 and gives the agent only the path, in ZENTRI_SESSION_TOKEN_FILE. The zentri binary reads the token from ZENTRI_SESSION_TOKEN, or else from that file. <state> is $XDG_STATE_HOME/zentri, or ~/.local/state/zentri when that variable is unset.

A session token is scoped to its own session. It can manage its own claims, notices, and plan, post questions, propose decisions, update the PRD, post notes, and read sessions and diffs. It lasts 8 hours. When less than 2 hours remain, the heartbeat calls POST /v1/session/refresh, which keeps the same token value and moves the expiry to the earlier of 8 hours from now and 24 hours after the token was made. Each refresh is audited as token.refresh.

With the local-dev launcher, every name comes from two parts. The ID is the last 8 characters of the session ID. The slug is the intent’s ticket, or else the first 6 words of the prompt, lowercased, with every other run of characters turned into -, cut to 40 characters, and task when nothing is left.

Thing Name
Branch zentri/<slug>-<id>, created from your current HEAD
Worktree <root>/<repository name>/<slug>-<id>
Worktree root $ZENTRI_WORKTREE_ROOT, else $XDG_DATA_HOME/zentri/worktrees, else ~/.local/share/zentri/worktrees
tmux session zentri-<id>, with tmux 3.2 or later ($ZENTRI_TMUX names another binary)

The agent gets ZENTRI_SERVER, ZENTRI_PROJECT_ID, ZENTRI_SESSION_ID, ZENTRI_INTENT_ID, and ZENTRI_SESSION_TOKEN_FILE. The launcher refuses a token in the agent’s arguments, environment, prompt, or slug. If anything fails before the agent runs, zt removes the worktree and the branch, marks the session failed, and deletes the token and state files. With the openshell launcher, the sandbox clones the branch instead. See sandboxing.

A queued intent runs no agent. It waits on the intent it matched. When that intent ends, the coordinator writes one intent_unblocked notice to the queued intent’s owner. An intent ends when its session ends, or when POST /v1/intents/{intent_id}/status sets it done or abandoned. A requester or a Slack user never starts an agent, so their work that would run is registered as queued.

Nothing starts a queued intent by itself. zt ls lists the queued work you can start now, each with its command. zt start --queued calls POST /v1/intents/{intent_id}/start, which starts a session without matching again. The agent gets the prompt you pass, or else the intent’s summary. zt warns when the awaited intent has not ended, and starts anyway. The intent’s owner may start it with the engineer role or above. A lead may start any queued intent in the project, and then owns the session.

A fork sets fork_of on the new intent to the root of the family, which is the original intent, or that intent’s own fork_of when it is itself a fork. Matching skips every intent in the family, so a fork is never a duplicate of the work it competes with. It still matches all other work.

There are two ways in. zt start --fork ID "prompt" takes the full ID of an intent, or of a session whose intent you want to compete with. Picking fork when your own intent is an active_duplicate sets fork_of from the match. A requester is never offered fork, and the dedup window removes it from the choices. A requester’s fork through --fork registers as queued, like all of a requester’s work.

Picking join_as_watcher on another user’s work creates a watching intent with no session. The owner and the owner’s live session get an intent_watcher notice. zt ls shows watching intents by default, next to active and queued.

Terminal window
zt start "ENG-101: add CSV export to the reports page"
zt attach 8d918b06 # full session ID, or its last 4 or more characters
zt status # who you are, your live sessions here, your notices
zt done 8d918b06 # end the session, keep the branch and worktree
zt done --push 8d918b06 # also push the branch to origin
zt done --pr 8d918b06 # also open a pull request on github.com
zt start --queued 01900000-0000-7000-8000-00000000cc01
zt start --fork 01900000-0000-7000-8000-00000000aa01 "try the export with streaming"

zt start prints the session, branch, and worktree. This output is from the README:

Terminal window
$ zt start "ENG-101: add CSV export to the reports page"
INSECURE: local-dev runs the agent directly on this machine with your user's permissions. There is no sandbox and no egress policy, ...
Started session 8d918b06 for intent f4414369 (new).
branch zentri/eng-101-8d918b06
worktree ~/.local/share/zentri/worktrees/myapp/eng-101-8d918b06
Attach with: zt attach 8d918b06

zt attach, zt status, and zt done take an optional SESSION. Without one, zt attach and zt done pick the only live session on this machine. When there are several, they list them and exit 1, and you rerun with one named. zt status without SESSION shows every live session on this machine. zt attach runs tmux attach-session, or switch-client when you are already inside tmux. Detach with tmux’s own key, and the agent keeps running. Run zt attach again to resume.

zt done refuses while the worktree or sandbox holds modified, staged, or untracked files that .gitignore does not ignore. It lists up to 50 of them, changes nothing, and exits 3. Commit or remove them, then rerun. Otherwise it sets the session done, stops the agent, deletes the token, and keeps the branch and worktree. It pushes nothing unless you pass --push or --pr, and it never forces a push. --pr opens the pull request into the branch the session started from, or the default branch. For a sandbox whose agent has exited, --discard drops the uncommitted work after zt brings the branch’s commits home. It asks first, and --yes skips the question.

Exit code Constant Meaning
0 ExitOK The command did what you asked.
1 ExitError Any error.
2 ExitDecision zt start needs a resolution it could not choose.
3 ExitUncommitted zt done refused, because no commit holds some of the work.

CLI reference lists every flag.

  • zt attach, zt status, and zt done see only sessions started on this machine. Their records live in <state>/sessions/.
  • A session token stops 24 hours after it was made, and no refresh extends it. The heartbeat then stops, and the sweeper abandons the session about 10 minutes later.
  • With local-dev, the heartbeat window keeps the tmux session alive after the agent exits. The session stays running until you run zt done.
  • Nothing in zt or the coordinator sets waiting_human or idle on its own. Only a call to POST /v1/sessions/{session_id}/status does.
  • Nothing starts a queued intent by itself, and no zt command ends an intent directly.
  • A watcher gets no notice when the watched work ends.
  • --pr supports github.com only.
  • local-dev runs the agent on your machine with your permissions, with no sandbox and no egress policy.