# The agent protocol (/docs/guides/agent-protocol)



<Callout type="info" title="The normative version">
  This is the [Agent role](/docs/spec/agent-protocol) of the specification in
  practice. The bundled skill teaches it to agents; the [harness
  hooks](/docs/guides/harness) make it automatic.
</Callout>

The CLI is usable by a person, but it exists because agents need somewhere to put state
that outlives a context window. The protocol is short: one session token on every
command, enter through `mine` and `resume`, claim before working, keep `state.md`
current, and leave through `pause`, `handoff` or `done`.

## The skill [#the-skill]

`tasks init` installs an [agent skill](https://agentskills.io) into
`.claude/skills/tasks/`. It is what makes an agent reach for this CLI on its own rather
than inventing a `TODO.md`: it carries the protocol on this page, the command table, the
JSON contract, and what to do when something looks wrong.

```sh
tasks skill install [--force]
```

Add it to a project that predates it, or refresh it after upgrading the CLI, with the
command above. An existing install is **left alone** unless `--force`, so local edits
survive. Commit `.claude/skills/tasks/` so every agent working in the repository gets it;
`tasks init --no-skill` scaffolds a tree without it.

## The session token [#the-session-token]

An agent acts as the actor &#x2A;*`agent`** — the conventional name, unless the tree's
[roster](/docs/reference/configuration#actors) names it otherwise — with a **session
token** on every command. A claim taken without one has unknown liveness: nobody takes it
over without a force, and the agent's own next session can only pause it, as the same
actor, and claim it again.
Subagents act under the same name and token as the agent that spawned them.

* **With the harness hooks**, `TASKS_SESSION` and `TASKS_ACTOR` are exported for every
  shell command of the session, and the agent passes nothing.
* **Without them**, the agent generates one token at the start of the session — a UUID
  or `date +%s`, matching `^[A-Za-z0-9][A-Za-z0-9._@+-]*$` (an ISO timestamp's colons
  fail it) — and runs every command as
  `TASKS_ACTOR=agent tasks … --session <token>`. Shell state often does not survive
  between an agent's tool calls, so the prefix and the flag are safer than an `export`.
  Without `TASKS_ACTOR` the agent acts under the repository's git identity, which is the
  person's: it works, but the log cannot tell the two apart, and a task assigned to
  `agent` never reaches it.

The actor names who acted; the session names which run. Two sessions of the same agent
are the same actor, and the log, the liveness rules and `mine` tell them apart by token.

Your name comes from the environment, not from the roster: `TASKS_ACTOR` when the harness
set it, else `agent`. `tasks actors` is for choosing a person to hand a task to; a team
that named its agent otherwise (an actor of `type: agent`) tells you so. Without the hooks,
a long stretch with no `tasks` command — reading code, running tests — lets your claim go
orphaned for everyone else after `session_timeout_minutes` (30 by default), and another
agent may take it: run `tasks heartbeat --session <token>` in such a stretch, or any
command; a `state` write counts.

## Entry [#entry]

<Steps>
  <Step>
    ### Run `tasks mine` [#run-tasks-mine]

    ```sh
    tasks mine --json
    ```

    It lists your claims first — this session's, then older ones — and then the tasks merely
    assigned to you — your inbox — each with its last log entry, its last activity. What was left
    for you is in the task's files: `## Notes` of `task.md`, `design.md`, `state.md`; `resume`
    shows them.

    * **Continue** a task claimed by this session.
    * **Then the highest effective priority** among your orphaned claims (`liveness:
      "orphaned"`, from an older session of yours) and your inbox; at equal priority finish
      your orphan before starting inbox work, and a person's instruction — in the conversation
      or under `## Notes` — names what comes first. **Take over** an orphan with an ordinary
      `tasks claim <task>`, which records the takeover: one at a time, only what you will work
      on now; the others stay orphaned, which is no breakage.
    * A task held by another **live** session is not yours.
    * A claim of **unknown** liveness is reported to the person, never forced.
    * Another actor's orphaned claim is taken over only on the person's instruction.
    * **New work** comes last: `tasks claim --next`.
  </Step>

  <Step>
    ### Run `tasks resume` and read in order [#run-tasks-resume-and-read-in-order]

    ```sh
    tasks resume <task>
    ```

    Read, in this order: `task.md`, `state.md`, `design.md`, `plan.md` — then, for each
    ancestor as far as needed, its `task.md`, `design.md` and `plan.md`. An epic's design and
    plan live on the epic. `resume` lists the ancestors outermost first, with the workspace
    files each one has.

    **Do not read `log.md` on entry.** The present is fully described by the other files;
    the last entry — the last activity — is already in the `resume` output. If a person's text
    reached you only there, put it under `## Notes` with `tasks note` before you claim.
  </Step>

  <Step>
    ### Claim before working [#claim-before-working]

    ```sh
    tasks claim --next          # the first task of your ready set, claimed in one step
    tasks claim <task>          # a specific task
    ```

    The claim is what stops a second agent starting the same task, and it is only useful if
    it happens first. Claim before working, read before changing: your own orphan is claimed
    first — the takeover restores your hold — and resumed after; new work is `claim --next`
    then `resume`, or `resume` the candidates and `claim <task>` by id when you choose. A
    conflict (exit `4`) means another agent was first: move on to the next ready task. Never
    reach for `--force` to win a claim.
  </Step>

  <Step>
    ### Leave unavailable projects to the person [#leave-unavailable-projects-to-the-person]

    A listed project the commands cannot read — `not shown` on stderr, `unavailable` in the
    JSON: a v1 tree, a repository not checked out here — is a person's to migrate or check
    out. Say so once in your report and go on.
  </Step>
</Steps>

## During work [#during-work]

* **Never hand-edit frontmatter.** Every field has a command. The body below it is
  yours; edit it with ordinary file tools.

* **Never move a task directory by hand.** Its id is its path; use `tasks move`, which
  rewrites the references.

* **Write `state.md` through `tasks state`**, so the write is fenced like a transition: a
  session whose claim was taken over learns of it before it overwrites the new claimant's
  file.

  ```sh
  tasks state <task> < state.md
  ```

* **Put each input where it belongs.** A clarification of the statement changes
  `Description` or `Acceptance criteria` in place; an input received after the start
  goes to `## Notes`; a decision goes to `design.md`; a change of plan goes to `plan.md`.

* **A follow-up that is not part of the deliverable** becomes a separate `BACKLOG` task
  **outside** the parent (`tasks new <path> "<title>" --backlog`), linking to the
  context in its body.

* **A step a person must take** — a review, an approval, a deploy — is a `handoff` to
  that person when it concerns this task, and a separate task assigned to them
  (`--assign`) only when other tasks must depend on it. `tasks actors` says who they
  are and how they are named; a refused name is corrected, never added to `config.yml`
  on your own.

* **Children are parts of the deliverable, never phases.** No child for planning,
  review or verification: the plan is `plan.md`, the review is a `handoff`.

* **A task with open children is never cancelled, deferred or archived on the agent's
  own initiative.** Such a decision comes as a person's instruction, quoted in the
  message.

* **`--as` only on an explicit instruction** from that actor, given in the current
  session, and the message quotes it. Never use `--as` to satisfy an assignee rule on
  your own initiative.

* **The freshness rule:** every turn in which the work progressed ends with `state.md`
  updated. The status stays `IN_PROGRESS` between turns.

## Exit [#exit]

* **An input for whoever works next — a decision taken, a fact learned, a link — goes under
  `## Notes` of `task.md`:** `tasks note <task> "<text>"` appends it dated and attributed, and
  logs it. A message alone is history: the next entry displaces it.

* **A turn is not a session.** A turn ends with the claim kept and `state.md` fresh whenever
  you expect to continue in this conversation — waiting for the person's answer included.
  The session ends with `pause`, `handoff` or `done`: the conversation closes, the harness
  stops you, or the task passes to someone. A task that cannot move without a person's
  decision is a `handoff` to them, the question in the message and under `## Notes`. Not
  sure you will be back? `pause`: your pause frees the task; an orphan is what to avoid.

* **A deliberate end of work is `pause`, `handoff` or `done`, each with a message.** The
  message is the history line; the resume point is `state.md`. Never end a session deliberately
  with a task `IN_PROGRESS`.

  ```sh
  tasks pause <task> -m "Parser done and tested, commit 4f1c2e on parser; the CLI flag is next (see state.md)."
  tasks handoff <task> alice -m "Ready for review: design.md has the two options."
  tasks done <task> -m "Merged: commit abc123 on main; docs: engineering/auth.md updated."
  ```

* **`pause` and `handoff` are refused without a `state.md`**; `release` is only for a
  claim that produced nothing.

* **`state.md` names, under *Open*, every uncommitted file and branch** the work leaves
  behind.

* **Name your commits in the log.** Every commit made for the task goes into its log before
  the work ends: in the `pause`, `handoff` or `done` message, or earlier with
  `tasks log <task> "commit <hash> on <branch>: <what>"` when a turn produced one; add the
  repository when it is not this one. Where the project's commit convention allows it, the
  commit message names the task's id too (a `Task: <id>` trailer, or in the subject), so a
  commit leads back to its task as the task leads to its commits.

* **Promote knowledge before `done`.** What must outlive the task goes into the
  project's documentation; the task directory is working memory, not documentation.
  When `config.yml` lists [`docs`](/docs/reference/configuration#docs), `tasks resume`
  shows where that documentation lives, and before `done` the agent brings the listed
  documents that describe what the task changed up to date — within the task's scope,
  never a general revision — and says in the message what changed, or that nothing
  needed to. A location absent on this machine is named in the message instead; a change
  in another repository that has not landed is named too, and stays under *Open* in
  `state.md` with its branch while the task is open.

* **Project state lives only in the tree.** An agent's private memory keeps preferences
  and reference facts, never the state of a task.

## Approval of a plan [#approval-of-a-plan]

The hold gives an epic its approval gate without a procedural child:

```sh
tasks claim auth-rework                       # the planner takes the epic
# write design.md and plan.md, then create the parts — held by the claimed epic
tasks new auth-rework/token-schema "Design the token schema"
tasks new auth-rework/wire-refresh "Wire the refresh endpoint"
tasks state auth-rework < state.md
tasks handoff auth-rework alice -m "Plan ready for review."
```

While the epic is claimed or assigned, nothing beneath it is ready. The approver either
releases the children with `tasks unassign auth-rework -m "APPLY"`, or sends the plan back
with `tasks note auth-rework "Split the refresh work in two."` and
`tasks assign auth-rework agent`, which keeps them held until the planner reworks it and hands
it off again: the instruction sits under `## Notes`, where the planner reads it, and the
assignment is the history line.

## A task that is not being worked [#a-task-that-is-not-being-worked]

Every case maps to a stored status plus what overviews show:

| Case                                           | Stored                            | Shown                                                              |
| ---------------------------------------------- | --------------------------------- | ------------------------------------------------------------------ |
| not started, free                              | `TODO`                            | `ready`                                                            |
| not started, waits for a task                  | `TODO` + `depends_on`             | `blocked by X`                                                     |
| not started, not scheduled                     | `BACKLOG`                         | `backlog`                                                          |
| a specific person's own step (deploy, release) | `TODO` + `assignee`               | `assigned alice`                                                   |
| being worked                                   | `IN_PROGRESS`                     | `working by agent · live`                                          |
| session ended deliberately, work unfinished    | `pause` → `PAUSED`                | `ready · started`, first in `ready`                                |
| a person stops, meaning to come back           | `pause` → `PAUSED` + assignee     | `waiting for alice`; her `unassign` or `handoff` releases it       |
| session ended without `pause`, or crashed      | `IN_PROGRESS`                     | `working by agent · orphaned since T`; the next session takes over |
| started, waits for a task                      | `pause` + `dep add` → `PAUSED`    | `blocked by X · started`                                           |
| started, needs a decision or review            | `handoff alice` → `PAUSED`        | `waiting for alice`                                                |
| started, set aside                             | `pause`, then `defer` → `BACKLOG` | `parked`; `schedule` brings it back to `PAUSED`                    |
| started, decided not to do                     | `cancel`                          | `cancelled`                                                        |
| finished, awaits confirmation                  | `handoff alice` → `PAUSED`        | `waiting for alice`; her `done` confirms it                        |
| an epic whose child is being worked            | `TODO` or `PAUSED`                | `open 2/5 · active`                                                |
| an epic whose plan awaits approval             | `handoff alice` → `PAUSED`        | `waiting for alice`; children `held by` it                         |

## When something looks wrong [#when-something-looks-wrong]

* Run &#x2A;*`tasks validate --json`** before hand-repairing anything. See
  [validation](/docs/reference/validation).
* A **conflict means someone else was first** — another agent's claim, a cascade, a
  takeover of your own stale session. Re-read with `tasks resume` and move on.
* **Never `--force` on your own initiative.** It is for a person's explicit decision, and
  the log records every forced transition (a forced `state` write is not logged).
* **Never hand-edit frontmatter, never `mv` a task directory.** Both bypass the checks
  that keep the tree trustworthy.
* If `tasks` is not on `PATH`, use `npx @speekl/tasks` in its place. Exit `3` with no
  `.tasks/` found means the project is not set up: &#x2A;*ask before running `tasks init`** —
  creating a tree is a project-level decision — and ask whom to list as actors:
  `tasks init --actors <person>,agent` writes the roster at once.
