Skip to content

How Herd works

tonialmagro-tomtom edited this page Nov 28, 2026 · 4 revisions

How Herd works

Most agent workflows ask people to write long requirement lists, then trust the agent when it says "done". Herd flips that:

You provide The agent provides
A goal, and optionally criteria with a check for each Plan, code, tests, attacks planned before the build, and evidence

You review evidence (command output, commit SHA, timestamps), not process. The short version, with when to use Herd and when to think twice: Why Herd. What happens to everything a request leaves out: How Herd fills the gaps.

Why use it

  • Done means proven. A Stop hook blocks the agent from finishing until every check passes, with evidence newer than the last edit. It blocks only the session that owns the task, so a parent session that started a headless Herd session can stop.
  • Your words stay yours. Criteria you write are quoted verbatim and never weakened: herd done refuses one that is not a quote of your request. Gaps are filled by the agent and marked agent-proposed.
  • Caveats surface early. The agent must say what each check does not prove, try to break its own work, and log what it finds, so problems appear during the run, not after it.
  • Checks that test nothing are caught. A check that exits 0 but ran zero tests is flagged instead of counted as proof.
  • The pull request is the evidence (opt-in). herd pr opens a PR whose description shows what is proven and by which check, what is not, and how to reproduce it. It never merges.
  • Short by default. Commands print a line or two, the agent ends with a six-line report, and the pull request collapses its details. The full detail is one flag or one file away.
  • Several tasks at once (opt-in). herd init --worktree gives each task its own branch and git worktree, so several agents can work in one repository without touching each other.
  • Light. A small Python CLI on the standard library, no dependencies, plain-text task files. It uses Superpowers when it is installed.

The steps

flowchart LR
    A[Goal] --> B[Intake and risk floor<br/>branch herd/slug<br/>opt-in: own worktree]
    B -->|standard| C[Criteria with checks]
    B -->|trivial: quick route| Q[One criterion, one check]
    C --> K[Second look and 6 attacks<br/>on the design model]
    K --> R[Red first<br/>checks fail before the work]
    Q --> R
    R --> D[Build on the build model:<br/>plan, tests first, code]
    D --> X[Break it<br/>generated cases, scale<br/>6 attacks, each with a command]
    D -->|quick route| F
    X --> F[herd verify<br/>criteria and attack commands]
    F -->|failing| D
    F -->|passing| G[herd done<br/>evidence report]
    S[Stop hook] -.->|blocks finishing until the conditions hold| G
    G -->|opt-in| P[herd pr<br/>PR with the evidence]
Loading
  1. Intake. The task gets a folder, .herd/tasks/<slug>/task.toml, and a risk floor computed from path rules in herd.toml (migrations, auth, billing, and so on). The agent can raise the risk, never lower it. A trivial change takes the quick route: one criterion and one check, no criteria interview, no approval question. It is refused at a high risk floor and still ends in fresh passing evidence. With --worktree (opt-in) the task starts on its own branch in its own git worktree: see Several tasks at once.

  2. Criteria. Every criterion has a check: a shell command where exit 0 means pass. Criteria you write are authoritative: the agent quotes your words, adds a coverage note saying what the check proves and what it does not. herd done and the Stop gate refuse a human criterion that is not a verbatim quote of the request Herd recorded at herd init: your latest /herd:run message, read from the session log (--request counts only when there is none). Case, spacing, line wraps, quote marks, dashes, sentence punctuation and Markdown are ignored; words, numbers and operators are not. Your own rewording, recorded with herd note --human-change "C1: <your words>", counts as a source. With no recorded request it is only a warning. At medium and high risk on the standard route they also refuse while test_budget, known_limits or a human criterion's coverage is empty, or while inputs is missing, incomplete or written inside a [[criteria]] table instead of as top-level [[inputs]] tables (each input as you described it, human, and as the program receives it, program; inputs = [] for none), and say what to write: only absence and structure are checked, the words are the agent's. The task.toml that herd init writes shows the [[inputs]] table. A criterion with no check is unchecked and is never counted as met. herd detect proposes the project's real test command. Before any work, herd verify runs the checks once: they should fail (red first), and the report shows how many did.

    Design on a stronger model. On the standard route the criteria, the inputs, a "be specific" second look and the six attacks are the design, made on the design model (default Sonnet); the code is built on the build model (default Haiku). herd status says which step runs in your session and which in the herd-designer or herd-builder subagent. The second look is the fixed message herd design-brief, answered in the task's ANSWERS.md before the attacks: the first herd verify refuses without it, and herd done refuses without a design on the design model. A hook records the designer's model in design.json, and the report and the PR name it. Settings: [models] in Settings.

  3. Build. Tests first, small steps, on a branch. Superpowers is used for planning, TDD and subagents when installed. herd init records the starting commit, the stash list and any files already uncommitted (those are yours, not the agent's, until the agent changes them; in Claude Code a hook moves the ones this session already edited back to the agent), so the first herd verify knows whether code was written before the checks, including code moved aside or stashed for that run (a check by file times and the stash list, not proof): if it was, the report says "red first not proven" and herd done waits for the agent's reason (herd note --late-red). The guard hook runs while the task is active.

  4. Break it. The six standard attacks are planned before the build: on the standard route all of them are logged, each with a command or an n/a: reason, before the first herd verify, so they shape the design. After the build the agent tries to break the result. See Attacks. There is no review step: it was removed in 0.13.0 (Review).

  5. Verify. herd verify runs every check and stores evidence: status, exit code, output tail, commit SHA, a content id of the work done since the task started and a fingerprint of the workspace, a timestamp, how many checks failed on the first run (a check that was green before any work is visible), and the wall-clock time since herd init. A check that exits 0 but whose output says it ran zero tests (Ran 0 tests, no tests ran, [no test files] and the like) is marked in the evidence and the report warns about it. The warning is advisory: the Stop gate does not change. It also runs the herd check warnings every time, freezes the human criteria at the first run (changing or removing one later blocks herd done until the human's own words are recorded with herd note --human-change "C1: ...", quoting the new text or saying it was dropped; the same holds for a changed check on a human criterion, and a changed check on an agent's criterion is shown; a change that only moves the human criteria toward your request needs no note: when every human criterion now quotes the request and every earlier human quote is still inside one of them, the changed ones are re-frozen with their checks, and the report and the PR list them for you to confirm), and counts failures in a row: after 3 on one criterion it says to escalate. The command prints one summary line plus only what needs attention. Each check records how long it took; the summary line ends with (checks took N s) and names each check over 60 s, as evidence only. When the work, task.toml and the attack notes are unchanged since the last full run, herd verify runs no check and keeps that evidence; --fresh runs every check.

  6. Stop gate. See Hooks and guard.

  7. Pull request (opt-in). When the request asks for a PR, or herd.toml has [pr] open = true, herd pr pushes the task's herd/<slug> branch and opens a pull request whose description is the evidence: the result, what is proven and by which check, what is not proven (failing or unchecked criteria, coverage gaps, known limits, open caveats), then, collapsed, the run details, the caveat log and the commands to reproduce. Ask for a draft or a milestone and the agent adds --draft or --milestone NAME. Once the PR exists, every herd verify rewrites its description from the latest evidence, and herd done replaces it with the final evidence (run herd pr again any time; it shows stale evidence as stale). Lines after Herd's footer line, such as Closes #N, are kept; text above it is replaced. It needs a clean working tree, so the PR holds exactly the verified code. It leaves check output out of the description (it can hold secrets) but publishes the check commands, the criteria and the notes as written, so never put a secret in them. It pushes no other branch and never merges: you review the evidence and merge.

Several tasks at once

Herd keeps a task's state in the checkout it runs in, so a plain herd init refuses while another task there is still active. To run several tasks in one repository, start each in its own worktree:

$ herd init export-json "Add a --json flag to the export command" --worktree
created worktree <repo>/.claude/worktrees/herd-export-json on branch herd/export-json, cut from feature/reports. Work from there: in Claude Code, EnterWorktree with that path; otherwise cd into it. Run every herd command from it.
  • Its own branch, cut from where you are. herd/<slug> starts at the current local branch, which is recorded as the task's base; herd pr opens the pull request against it. A plain herd init does the same in the current checkout, without a new folder.
  • Its own state. The task's files and Stop gate live in the worktree. Other agents can start other tasks from the same branch at the same time; each gate sees only its own task, and a duplicate task name fails without touching the first.
  • A forgotten move fails loudly. herd commands run from the starting checkout for a task that lives in a worktree refuse and name the worktree.
  • Clean main checkout. Herd adds /.claude/worktrees/ and .herd/ to the repository's own .git/info/exclude (never committed), so other tasks never show up in git status or a git add -A.
  • Make it the rule. With [worktree] required = true in herd.toml, a plain herd init refuses outside a matching worktree.
  • Clean up after the merge with git worktree remove .claude/worktrees/herd-<slug>. Uncommitted changes in the starting checkout are not carried over; Herd warns when there are some.

Architecture

flowchart LR
    subgraph Plugin
        S["Skills<br/>run, criteria, evidence"]
        H["Hooks<br/>Stop gate, pre-init, guard,<br/>design hook, lint"]
        A["Subagents<br/>herd-designer, herd-builder"]
    end
    CLI["herd CLI<br/>plugin/scripts/herd.py"]
    T["herd_triage<br/>risk floor"]
    D["herd_detect<br/>test command"]
    G["git and gh<br/>task branch, worktrees, herd pr"]
    subgraph State[".herd/tasks/&lt;slug&gt;/"]
        TT["task.toml and request.md<br/>goal, criteria, checks;<br/>the human's message"]
        NO["notes.jsonl<br/>caveats, attacks with commands"]
        EV["evidence.json<br/>criteria and attack results,<br/>SHA, content id, fingerprint"]
        RP["evidence.md<br/>the report"]
        RR["start, red, frozen, green, fails .json<br/>run-rule state"]
        DS["design.json<br/>the designer's model"]
        SR["stopped.json<br/>why it stopped, what next"]
    end
    S -->|instruct the agent to run| CLI
    H -->|gate, preinit, guard, design-hook, lint| CLI
    A -->|run| CLI
    CLI --> T
    CLI --> D
    CLI --> G
    CLI -->|reads| TT
    CLI -->|appends| NO
    CLI -->|runs checks and attack commands, writes| EV
    CLI -->|herd done writes| RP
    CLI -->|init and verify write| RR
    CLI -->|gate and cancel write| SR
    CLI -->|design hook writes| DS
Loading
  • Short skills, details on demand, quality first. The run skill holds the steps; the quick route, the worktree start, the adversarial pass and the PR step are separate files the agent must read in full when that step applies. Where skipping a step would cost quality, the CLI enforces it itself at herd done and the Stop gate: the adversarial attacks, red first, the frozen human criteria, the design model and the commit. Budget tests keep the skills and the command output from growing back.
  • The skills are the method; the CLI is the referee. The skills tell the agent what to do in each step. The CLI only records and checks: it runs the commands in task.toml and decides from their exit codes, never from what the agent says.
  • The Stop hook enforces it. It asks the CLI whether the stored evidence is passing, meets the run rules and still matches the workspace: a content id (a SHA-1 over every file that differs from the task's start commit, with its content, the same before and after a commit) plus a hash of task.toml. Any edit after herd verify makes the evidence stale; a commit alone does not, so herd done after a commit needs no second verify. herd done and herd pr then record the final commit as head (the verified one stays as verified_head). Outside git, and for evidence without a content id, the older fingerprint over HEAD and the diff decides. The hook finds the task from any subdirectory: the root is the nearest folder with .herd/ or herd.toml, so a project in a subfolder of a repository keeps its own tasks.
  • State is plain files in the project, one folder per task (in the task's own worktree when it has one), so a human can read, diff or delete it.
  • GitHub only when you opt in. herd pr uses the gh CLI to push the task's branch and open its pull request. Nothing else talks to a service.
  • Two modules are not wired in yet. herd_arbiter.py (rules on findings) and herd_escalation.py (one GitHub issue to pause and ask a human) are tested building blocks for the GitHub automation on the roadmap.

Autonomy rules

  • Gaps never block. Missing criteria or checks are filled in by the agent, marked agent-proposed, and listed for you.
  • Evidence over claims. passing and failing come from commands. unchecked is listed and never counted as met.
  • Ask rarely, ask once. The agent stops for an irreversible action, a real trade-off, or when stuck after 3 failed attempts on a criterion. It asks one question with numbered options.
  • Decisions are reported in at most three lines: decision, reason, how to override.
  • Checks run as shell commands from task.toml, in your repository, with your permissions. Treat a task file like code: read it, especially in a repository you do not trust.
  • Push only its own branch, never merge. herd pr pushes only the task's herd/<slug> branch from a clean working tree and opens or updates its pull request. The merge is yours. During a task the guard hook denies git push, gh pr merge and the other irreversible commands the agent might type.

Clone this wiki locally