Specification
Harness integration (non-normative)
How harness hooks make the agent protocol automatic, including when a session crashes.
The protocol above becomes automatic when the agent's harness enforces it. With Claude Code hooks as the example:
- Environment. Export
TASKS_ACTORfor the agent (agent, the conventional name). Claude Code puts no session id in the environment by itself; every hook receives it as thesession_idfield of its JSON input, and theSessionStarthook writesexport TASKS_SESSION=<id>(andTASKS_ACTOR) to the file named byCLAUDE_ENV_FILE, which Claude Code sources for every later shell command of the session. The agent therefore passes no--session; the hooks that runheartbeat,session-checkandsession-endpass--session <id>from their own input. Whether a resumed session keeps its id does not matter:SessionStartruns on resume too and exports what it is given. - SessionStart runs
tasks mine --jsonand injects the tasks claimed by this actor with the instruction toresumethem, and the tasks merely assigned to it as its inbox. Entry needs no kickoff phrase. - PostToolUse runs
tasks heartbeat --session <id>, so liveness reflects activity. It fires only when a tool returns, so a long-running command — a ten-minute test run — produces no heartbeat while it runs; this is whysession_timeout_minutesmust stay well above the longest tool call and the default of 30 is not to be lowered. - SessionEnd runs
tasks session-end --session <id>, so a session that ends without apause— the person quit, the harness exited after an error — hands its claims to the actor's next session at once; the timeout then matters only for a hard kill that gives the hook no chance to run. - Stop fires at the end of every turn and runs
tasks session-check --json; on exit4it blocks the stop (exit2, or a JSONdecision: blockwhosereasoncarries the violations): a turn cannot end with a claimed task that has no resume point. Warnings about an ageingstate.mdare shown, not enforced, so turns without progress are not forced to touch the file. - PreCompact may warn; a hook cannot write the content of a state.
- Worktrees. A session in a linked git worktree needs nothing of the hooks: discovery starts at
the same place in the main checkout (Discovery), so the hooks'
heartbeat,session-checkandsession-endreach the tree where the claim is, not the copy committed on the worktree's branch. - Sibling repositories. A session rooted in a tracker repository edits files in the product repositories it lists; the tracker's own instructions should require reading each repository's rules before editing its files, since a harness loads instructions from the working directory only.
The crash case — a session that dies mid-turn — is covered by the combination: the Stop hook
guarantees a state.md existed at the end of the previous turn, the freshness rule keeps it
current, SessionEnd orphans the claim at once when the harness gets to run it and the timeout
does when it does not, and the orphaned-claim rule lets the next session take over.