﻿---
title: Agents keep the goal
description: heed goal: the goal a session is on, from its shell. Agents keep their goal with it, told how by heed's heed-goal skill.
url: https://docs-v3-preview.elastic.dev/goals/cli
---

# Agents keep the goal
The goal a session is on is not only Heed's to keep. From the session's own shell, `heed goal` reads the goal and
writes to it: an agent records the decisions it takes and the questions it hits, adds the work it finds, checks a
criterion when it has the evidence, and proposes a change to the goal instead of quietly doing more. Every change goes
through the same rules as the Goals view, so an agent can do no more from the shell than heed would do on its own.
```sh
heed goal show                                  
heed goal decision add "Cache keys hash the lockfile"
heed goal item add "Measure cold builds" --parent cache-the-toolchain --by-subagent explorer
heed goal criterion check 2 --evidence "CI run 81: 48s cold"
heed goal propose not-the-goal "Remote execution"
```


## Which goal

The goal is the one the calling session is on: `heed goal` reads `HEED_SESSION_ID`, which every Heed pane sets.
`--goal <id>` (or the goal's title) works on another one. A session on no goal gets exit code 4 and the words to fix
it: `heed goal attach <goal>` puts it on one, `heed goal list` shows them.

## Records apply, scope waits

What only records what happened applies at once, as a new `GOAL.md` version or a new item, attributed to the session
(or to the subagent named with `--by-subagent`), and undoable in Heed like any change heed makes on its own:

| Command                                                   |                                                                                                            |
|-----------------------------------------------------------|------------------------------------------------------------------------------------------------------------|
| `attach [<goal>]`                                         | Put this session on a goal; with no goal, say which one it is on                                           |
| `item add <title> [--parent <id>] [--by-subagent <name>]` | New work on the goal; `--parent` splits an item, `--by-subagent` names who does the part                   |
| `item done <id> [--evidence <text>]`                      | The item's card to Done, with what shows it                                                                |
| `item move <id> <column>`                                 | The card to `explore`, `planned`, `working`, `verify` or `done`                                            |
| `decision add <text>`                                     | A decision, into **Decisions**                                                                             |
| `question add <text>`                                     | A question, as a card in To explore                                                                        |
| `question answer <id or question> <text>`                 | The answer becomes a decision and the question closes: the card to Done, an open question out of `GOAL.md` |
| `criterion check <n or text> --evidence <text>`           | A **Done when** criterion met. The evidence is required: without it, it would change the goal's scope      |
| `link pr <url, org/repo#n or #n> [--item <id>]`           | A PR on the goal, and on an item; `#n` is in the session's repo                                            |

What changes the goal itself waits for you: `propose <section> <text>` makes a proposal, listed under the goal's
`GOAL.md` and in Attention like the ones the work suggests ([What the work suggests](/goals/items#what-the-work-suggests)).
The section is `goal`, `not-the-goal`, `done-when` or `question` (an open question in `GOAL.md`). Whether an edit
applies or waits is decided by what it does, never by the command: `propose decision …` records, since a decision only
records.

## Sources

A goal that is a set of PRs or issues on GitHub gets its items from a query ([Item sources](https://docs-v3-preview.elastic.dev/goals/sources)):

| Command                                                       |                                                                                                                                                                                                                                                    |
|---------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `source add <query> [--rule merged\|closed\|reviewed\|green]` | A source: `prs <org/repo>`, `issues <org/repo>`, `label <name> [org/repo]`, `reviews [org/repo]`, `milestone <title> <org/repo>`, or a GitHub search. Words with no repo take the session's. `--rule` says when each item is done (issues: closed) |
| `source list`                                                 | The goal's sources: id, what it finds, its rule, how many of its items are done                                                                                                                                                                    |
| `source remove <id>`                                          | Take a source off; its items stay, marked as having left it                                                                                                                                                                                        |


## Work and reviews


| Command                                           |                                                                                                                                                                                                                                                                                                       |
|---------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `item spawn <id> [--agent <name>] [--background]` | Start work on the item: a session, as Start work would make it, on the goal and the item and told about the goal; or, with `--background`, a background run                                                                                                                                           |
| `review request <kind>`                           | The goal's reviewer of that kind (`implementation`, `security`, `docs-reader`, …) looks again, within the day's reviewer budget                                                                                                                                                                       |
| `handoff [--file <path\|->]`                      | The [handoff](/goals#the-handoff) heed asked this session's agent for when you made it a goal: markdown on stdin with `## Work`, `Done`, `Decisions`, `Open`, `Risks` and `Next` headings. Only while heed is waiting for it; the goal need not exist yet. Exit 1 says why a handoff was not readable |
| `list`                                            | Every goal: id, status, criteria met, items, score, title; `*` marks the session's                                                                                                                                                                                                                    |
| `show`                                            | `GOAL.md`, the items with their stages and columns, the quality bars and scores, what waits for you                                                                                                                                                                                                   |

A swarm's lead keeps the plan with `plan show`, `plan propose --file <path|->` and `ask <question> --option …`;
`plan approve` is yours, in heed: `A` in the plan pane ([A swarm's lead](#a-swarms-lead)). From a terminal it says so
and exits 5. `ask` waits for its
answer and prints it (exit 6 when none came before its timeout); `heed swarm send`, `note` and `answer` carry
messages, progress notes and answers between a swarm's agents ([Steering](https://docs-v3-preview.elastic.dev/goals/swarms/steering)).
A spawned session works in a new worktree of the asking session's repos (or of the newest session on the goal) and
starts off screen. A background run is the agent without a pane (`claude -p`, `codex exec`) in a worktree of its own on
`heed/spawn/<goal>/<item>`, kept when it ends so the work can be opened, pushed or thrown away; it may edit files there,
and its shell is limited to `heed goal` and reading git. How it ended is evidence on the item.
A spawn on a PR or issue someone else opened (a card a source found, not authored by you) always runs as a background
run, in the agent's sandbox as [reviewers](/goals/reviewers#how-a-reviewer-runs) do: its shell writes only to its worktree,
reaches no network and has no GitHub, ssh or cloud login, so `heed goal` cannot reach heed from it either; its work
stays on its branch. Only claude and codex have that sandbox: with another agent, such a spawn is refused.
Spawning is capped per goal: `spawn_concurrent` going at once (2) and `spawn_per_day` a day (6). Past either, the spawn
waits for you as one Attention item per goal: `y` starts what waits, `n` drops it, `↩` opens the goal's board. The
command says so with exit code 5.
```toml
[goals]
spawn_concurrent = 2
spawn_per_day = 6
```


## A swarm's lead

New goals go through the [wizard](https://docs-v3-preview.elastic.dev/goals/first-goal), whose [Go](https://docs-v3-preview.elastic.dev/goals/go) step starts their swarm; this section is the reference for the swarm machinery Go runs.
A swarm's lead keeps the plan with the same `heed goal` command every agent on a goal has (above),
taught by the **Leading a swarm** section of the `heed-goal` skill. Codex and other agents without the plugin get the
same rules in their first prompt.

| Command                                                                               | What it does                                                                                                                                                                                     |
|---------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `heed goal plan show`                                                                 | The plan: tasks by phase with their ids, the questions and their answers, your re-plan feedback, a change waiting for you or one you said no to                                                  |
| `heed goal plan propose --file <path\|-> [--note <text>]`                             | A plan as JSON; `-` reads it on stdin                                                                                                                                                            |
| `heed goal ask <question> [--option <a> [--effect <text>]]… [--to lead\|you\|<task>]` | A question, and wait for its answer (9 minutes by default; exit 6 when none came). Who may answer is by what it is about ([Steering](https://docs-v3-preview.elastic.dev/goals/swarms/steering)) |
| `heed swarm answer <n> <text>`                                                        | Answer a worker's scope question heed typed into the lead's pane                                                                                                                                 |
| `heed swarm send <to> <text>`                                                         | A message to a task, or `@all`                                                                                                                                                                   |
| `heed swarm summary [--outcome <text>] [--decision <text>]… [--follow-up <text>]…`    | The end-of-build summary, once the swarm is done ([The summary](https://docs-v3-preview.elastic.dev/goals/swarms/summary))                                                                       |
| `heed goal plan approve`                                                              | The plan is yours to approve, in heed's plan pane (`A`): from a terminal outside heed it says so and exits 5, and a pane or a background run is refused. A command line cannot show it is you    |

Before you approve a plan, every proposal is the new draft. After, a small change applies and a structural one waits
for you ([Approving](/goals/swarms/plan#approving)). `--json` on any of them answers as JSON.

### The plan's JSON

```json
{
  "note": "first draft",
  "tasks": [
    {"id": "offsets", "title": "Arrowhead offsets per zoom level", "phase": "Measure", "owner": "claude",
     "estimate": "20m", "doneWhen": ["a table of offsets from 50% to 400% zoom"]},
    {"id": "snap", "title": "Snap arrowheads to the lifeline", "phase": "Fix", "owner": "codex:o4",
     "estimate": "45m", "after": ["offsets"], "doneWhen": ["arrowheads meet the lifeline at every zoom"],
     "host": "devbox"}
  ],
  "scope": [{"section": "not-the-goal", "text": "new diagram types"}]
}
```

- `id` names a task in `after`. An id of an item already on the goal takes that item into the plan. Without an id a
  task keeps the id of the current plan's task with the same title, or gets one from its title.
- `phase` is the phase it is in; without one, the phase of the task before it.
- `owner` is an agent, `agent:model`, or `{"agent": …, "model": …, "effort": …}`.
- `estimate` is minutes, or `15m`, `1h 30m`, `1.5h`.
- `doneWhen` is one check or a list: what evidence must show for the task to be done.
- `host` is where its worker runs when not where the swarm does: a host's name (`devbox`), or `local` for your Mac
  ([On a host](/goals/swarms/running#on-a-host)). A host you do not have stalls the task when it would start, saying so.
- `scope` lists changes the goal would need (sections `goal`, `not-the-goal`, `done-when`, `question`, `decision`):
  each becomes a `GOAL.md` proposal that waits for you, never an edit.

A plan is refused, with why, when a task has no title, two tasks have one id, a task waits for something that is
neither a task nor an item, or tasks wait for each other in a circle.

## For agents and scripts

Every command takes `--json` and then prints one JSON object, also when it fails: `outcome` (`applied`, `proposed`,
`moot`, `added`, `moved`, `attached`, `linked`, `started`, `held`, `read`, `refused`, and for a swarm `asked`,
`answered`, `timeout`, `sent`, `noted`), `exit`, `message`, and what it is about (`goal`, `item`, `edit`, `version`,
`session`, and `goals` for `list`, `view` for `show`, `question` and `answer` for `ask`).

| Exit |                                                                                       |
|------|---------------------------------------------------------------------------------------|
| 0    | Done, proposed, or answered                                                           |
| 1    | Refused: no such goal, item, column or reviewer; nothing changed                      |
| 2    | Wrong usage; the usage is printed                                                     |
| 3    | Heed is not running, or not reachable from here                                       |
| 4    | No goal: the session is on none and no `--goal` was given                             |
| 5    | Held for you in Attention (a spawn past the cap, a review past the budget)            |
| 6    | `ask` waited and no answer came; the question stays open (`ask --id <n>` waits again) |

`heed goal --help` prints all of it. The command talks to Heed over the [control socket](/reference/cli#the-control-socket)
(method `goal`); it never opens the goals database itself. A background run has no session, so heed sets `HEED_GOAL`
for it, which `heed goal` uses when there is no session and no `--goal`.

### On a host

A host has no control socket to reach, so heed puts its own `heed` there, in `~/.heed/bin` next to the hook, and puts
that folder first on the PATH of the agents it starts there. It is a few lines of POSIX sh: `heed goal …` and `heed swarm …` write one line to the host's event log (with the file `--file` names, read there, or stdin for `-`), heed
reads it over the host's shared ssh connection and answers it as it answers the `heed goal` on this Mac, and the answer
comes back as a file in `~/.heed/replies` that `heed` prints, exiting as `heed goal` would. A swarm's lead and workers
on a host keep the plan, ask and send this way ([On a host](/goals/swarms/running#on-a-host)).

|                   |                                                                                                                                           |
|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
| Who may call      | heed's own panes there (they carry its session and token); a shell heed did not start is refused, and `plan approve` stays yours, in heed |
| How long it waits | A minute; `heed goal ask` as long as a question can wait                                                                                  |
| When heed is away | `heed` gives up and exits 3; a call heed finds later than its caller waits is not answered                                                |


## The heed-goal skill

Agents learn all this from heed. When a session or chat on a goal starts or resumes (and `tell_agents` is on):
- **claude** loads heed's plugin for that session only, with `--plugin-dir`. The plugin is a folder heed writes in
  `~/Library/Application Support/Heed/plugin/`, rewritten when heed updates; nothing is installed, and nothing is
  written into your repos or `~/.claude`. Its one skill, `heed-goal`, tells the agent to read the goal first with
  `heed goal show`, keep to **Not the goal**, record decisions and questions, add the work it finds and split it for
  subagents (registering their parts with `--by-subagent`), check criteria only with evidence, propose scope changes
  instead of doing them, spawn only separate work, and finish with a short summary.
- **codex** takes no plugin per session (its plugins are installed), so it gets the goal's pointer and the same
  guidance, from the same source, in its developer instructions.
- Other agents get neither; `heed goal` still works from their panes.

```text
~/Library/Application Support/Heed/plugin/
├── .claude-plugin/
│   └── plugin.json          name "heed", heed's version
└── skills/
    └── heed-goal/
        └── SKILL.md
```

A claude session on a host does not have the plugin, and gets the pointer as before.