Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Run setup with hooks

A source can declare install hooks in mind.toml: shell commands that build or install the tooling its items rely on. A user can supply or override them with meld --install-hook <cmd>.

The full form is a [[hooks]] array-of-tables. Each entry has a required run field (the shell command), an optional name label shown in the disclosure, an optional bool (default false), and an event field ("install" for meld, "update" for upgrade, "uninstall" for unmeld; default "install"). The legacy [source].install string is shorthand for one required install hook:

# mind.toml in a source repo

[[hooks]]
run = "make build"
name = "build tooling"
event = "install"

[[hooks]]
run = "pip install -r requirements.txt"
name = "python deps"
optional = true
event = "install"

[[hooks]]
run = "make upgrade"
name = "upgrade tooling"
event = "update"

[[hooks]]
run = "make clean"
name = "cleanup"
event = "uninstall"

The install plan

On a terminal, meld, learn, upgrade, and unmeld show one plan before anything runs: the items, then every hook the run would offer, each with its event, source, commit, the directory it runs in, and the command. An item hook also names its path in the source’s clone, which is where to read the code before it is copied. The plan asks once:

install these 2 item(s) now? (2 hook(s) to run) [Y/s/r/n]

y (the default) installs and runs every listed hook, s installs and skips them, r installs and asks about each hook on its own (the safety prompt below), and n installs nothing and runs no hook. On unmeld the same replies remove instead, and the default is n ([y/s/r/N]). When there is nothing to confirm but the hooks (--yes, --register-only), the prompt is [Y/n/r]. An unrecognized reply is asked again; EOF takes the default.

The safety prompt

Because a hook is arbitrary code, mind discloses the source identity, pin, commit, clone path, and exact command before running anything. A hook the plan did not list, or every hook after an r at the plan, gets its own prompt, [Y/n/a], with three choices: run the hook (the default, a bare Enter), skip it but still install the source and its items, or abort and install nothing. In a non-TTY context (CI, scripts) the hook is skipped and a note is printed; --accept-hooks runs it unattended (--accept-hooks=install accepts only install hooks; see Scripts and CI). Overriding a source’s declared install hook with --install-hook is announced in the prompt, which shows both the declared and the overriding command. The override is kept: a later upgrade or hooks run runs it in place of the source’s declared install and update hooks.

The disclosure also shows a version-control browse URL pinned to the disclosed commit alongside the on-disk clone path, so you can read the exact code that will run either locally or in the forge before approving. The URL is produced only for GitHub-shaped https remotes; a GitLab or Bitbucket host, an SSH remote, or a local/file:// source shows the clone path alone (no correct web link exists for those).

Re-runs

A skipped hook is recorded and re-offered by mind upgrade, so you can run it later without the source needing to advance first. On an upgrade re-run the source is already installed, so abort is treated as skip. upgrade also re-runs the hook when a source advances to a new commit. sync --upgrade accepts --accept-hooks so a CI pipeline can run hook re-runs unattended. Without the flag, a non-TTY sync --upgrade skips hook re-runs (the same as upgrade). When items are also out of date, a non-TTY run of either refuses unless --yes is given.

Because the default is a re-run, write an install hook to be idempotent: safe to run again on a host it already set up.

Update hooks

An event = "update" hook runs at upgrade INSTEAD of re-running the install hooks. Declare one when a step cannot be made idempotent (a first-run migration, a one-shot registration):

[[hooks]]
run = "make install"          # runs at meld

[[hooks]]
run = "make upgrade"          # runs at upgrade, and `make install` does not
event = "update"

An update hook is also where a source removes what mind never recorded, such as files an older install script wrote. Items mind installed are removed by [source] prune = true instead (see Remove the items you drop). A hook runs while upgrade holds mind’s lock, so it cannot call mind itself (see Hook environment).

A source that declares no update hook is unaffected: its install hooks re-run as before. An update hook never runs at meld or on a re-meld, is recorded against the commit it ran at exactly as an install hook is (so it is not re-offered until the source advances again), and is disclosed and prompted the same way.

Update hooks supersede install hooks for the source that declares them: while a source declares any update hook, upgrade offers its pending update hooks and does not re-offer that source’s install hooks. An install hook skipped at meld (the default in a non-TTY run such as CI) is therefore not re-offered by a later upgrade. Run it explicitly: mind hooks run <source> --event install --force.

The same applies per item: an item that declares an update hook runs it in place of its install hooks when the item is re-installed over an existing install, which in practice is upgrade’s in-place swap. A learn naming an already-installed item is a no-op and runs no hook; to run an item’s update hooks on demand, use mind hooks run <source>#<item> --event update. A build hook is unaffected and always runs, since it produces the item’s content.

Uninstall hooks

Uninstall hooks (event = "uninstall") run at unmeld, in the source’s clone, before the clone is removed. Every unmeld confirms first, and the default is no. On a terminal the hooks are listed in that confirmation, [y/s/r/N] (see The install plan): y removes and runs them, s removes and skips them, r prompts each one (run / skip / abort-the-unmeld for a required hook, run / skip for an optional one), and n, Enter, or EOF removes nothing. --yes skips the confirmation and leaves a [Y/n/r] question about the hooks alone. Without a terminal, unmeld needs --yes, and then skips the hooks and notes it. unmeld --uninstall-hook <cmd> supplies or overrides the source’s declared uninstall hooks. unmeld --accept-hooks runs them unattended. A required uninstall hook that fails or is aborted leaves the source melded.

Items hooks

An event = "items" hook runs once per command that changes the source’s installed items (meld, learn, forget, prune, upgrade, curate, absorb, unmeld), after the items’ own hooks. Use it for state built from the whole set: a registry or index of the installed tools, or a resource several items share.

[[hooks]]
run = "scripts/registry.sh"
name = "tool registry"
event = "items"

The hook runs in the source’s clone. $MIND_ITEMS_FILE names a JSON document:

{
  "version": 1,
  "source": "github.com/acme/tools",
  "commit": "<sha>",
  "command": "learn",
  "added": [{"kind": "tool", "name": "fmt", "effective_name": "fmt",
             "store": "/home/me/.mind/store/tool/fmt", "profiles": []}],
  "updated": [],
  "removed": [],
  "installed": [{"kind": "tool", "name": "fmt", "effective_name": "fmt",
                 "store": "/home/me/.mind/store/tool/fmt", "profiles": []}]
}

added, updated, and removed are relative to the set the hook last ran with successfully; updated includes a content-only change. installed is the full set after the command, so write the hook to make the host match it: a re-run with the same set should change nothing.

On a terminal, a command that shows a hook plan (meld, learn, upgrade, unmeld) lists the hook in it, and the plan’s answer covers it; one that shows none, such as forget, prompts it on its own. A skipped, declined, or failed run leaves the hook pending, and the next upgrade offers it with every change since. So do auto-update runs, which do not offer it. A failure exits 3 but keeps the command’s item changes. At unmeld it runs with an empty set, before the source’s uninstall hooks; cleanup that needs a removed item’s files belongs in that item’s uninstall hook. --accept-hooks=items runs it unattended.

Running hooks on demand

Hooks normally run as a step of another verb: install hooks at meld/upgrade, uninstall hooks at unmeld, and item hooks at learn/forget/upgrade. mind hooks run runs them outside those flows, so you can run a hook you earlier skipped, re-run one whose effect was later lost (a deleted build output or side effect), or retry one that failed transiently, without a full re-meld or reinstall. Every hook it runs goes through the same disclosure and consent prompt as an automatic run.

mind hooks run <source>                     # the source's pending install hooks
mind hooks run <source> --force             # every install hook, even already-run ones
mind hooks run <source> --event uninstall   # the source's uninstall hooks
mind hooks run <source> --event items       # the source's pending items hooks
mind hooks run <source>#<item>              # an installed item's install hooks
mind hooks run <source>#<item> --event build  # rebuild the item (transactional)
mind hooks list <source>                    # list hooks in effect, run nothing

<target> is a source filter (the source’s own [[hooks]]) or an owner/repo#item ref (that item’s hooks); there is no ambiguity check, so a filter matching several sources, or a ref matching several items, runs the hook for each in turn. --event selects the lifecycle event (install, update, uninstall, build, or items); build is valid only for an item target and items only for a source target. --event update behaves as --event install does at that target: only pending hooks run, and --force runs them all.

An item-link instance’s own identity is owner/repo#<path> (see Item links), which is spelled the same way as “item <path> in source owner/repo”. When a target matches both a registered source and an installed item, mind refuses it rather than picking one, and names both disambiguated forms. Force either reading:

mind hooks run source:<target>              # the source's own hooks
mind hooks run <source>#<kind>:<name>       # that item's hooks

For a source install run, only pending install hooks run by default (a hook that never ran, was skipped, or whose recorded commit is behind the source’s current commit); --force re-runs every install hook regardless. An item target runs the item’s hooks in place against its installed store copy and requires the item to be installed. --event build rebuilds the item through the normal transactional install path, so a failed rebuild leaves the existing copy untouched.

--accept-hooks applies exactly as it does to the automatic flows: without it a non-TTY run skips the hooks, and a required hook’s failure or abort is a non-zero exit.

mind hooks list <target> reports the hooks in effect for a source and its installed items – each hook’s event, required/optional flag, and command, and for a recorded source install or update hook whether it is pending and the commit it last ran at – without running any. It is the read-only companion to hooks run. Under each hook it also shows the hook’s last result from the hook history, when there is one.

Hook results and logs

Every hook mind considers gets a result: ok, failed (with its exit code or signal), skipped (no terminal to ask on), declined, aborted, or interrupted (see below). The closing frame line shows how a hook that ran exited:

====== (hook: setup) ======
...
====== (end hook: setup, exit 0, 2.1s) ======

Under --json the results are the document’s hooks array, and a failed run puts them on the error envelope; see Scripts and CI. A run that stops on a failed hook exits 3.

mind keeps the newest 100 results in ~/.mind/hooks/history.jsonl, skipped and declined hooks included. mind hooks history shows them:

mind hooks history                        # every recorded result, oldest first
mind hooks history owner/repo --failed    # one source's failures
mind hooks history 'owner/repo#skill:scan' --limit 5
mind hooks history --event update --outcome skipped,declined --since 7d
mind hooks history owner/repo --failed --limit 1 --show   # with its saved output

--since takes a duration (30m, 2h, 7d) or a UTC date or time (2026-10-28, 2026-10-28T14:00). --show prints each result’s saved log after it. Set hook-history in config.toml to keep more or fewer results; 0 turns the history off.

hooks list shows each hook’s last result under it. When you melded with --install-hook, the declared hook’s line shows the result of the command that ran in its place.

To keep each hook’s output as well, pass --hook-log (or set hook-log = true in config.toml). The output still shows as it runs and is also saved to a log file, which the result names (hooks history prints it as log:). Each line is tagged out | or err | , and the file is readable only by you. A bare --hook-log writes under ~/.mind/hooks/logs and deletes a log when its result drops off the history. --hook-log=DIR (or hook-log = "DIR") writes to DIR and never deletes anything there, unless DIR is inside ~/.mind/hooks/logs. A relative DIR in config.toml is relative to ~/.mind; on the command line, to the working directory. --no-hook-log turns logging off for one run when the config turns it on.

To keep only the output of hooks that went wrong, pass --hook-log-keep failed (or set hook-log-keep = "failed"): a hook that exits 0 has its log deleted as soon as it finishes. The flag turns logging on by itself; the config key applies only when logging is on.

Note that a logged hook’s output goes through a pipe rather than straight to the terminal, so a tool that colors its output or draws progress bars only on a terminal stops doing so, and a background process the hook starts without redirecting its output loses that pipe when mind exits. That is why logging is off by default. Note also that with hook-history = 0 no result is kept to drop off, so a logging run deletes the logs in ~/.mind/hooks/logs older than 30 days instead.

A Ctrl-C while a hook runs reaches the hook as usual. mind waits for the hook to exit, records it as interrupted, and then stops with exit 130, even if the hook caught the signal and finished. A second Ctrl-C while the hook still runs ends mind at once, without a record, and leaves the hook to exit on its own.

Hook environment

mind sets these variables for every hook it runs:

variablevalue
MIND_IN_HOOK1
MIND_PROFILESthe profiles enabled for the hook’s source (see below)
MIND_ITEM_PROFILESfor an item or build hook, the profiles the item is installed for; empty for a source hook
MIND_ITEMS_FILEfor an items hook, a JSON document of what changed and the installed set; empty for every other hook

A hook cannot run mind. The mind command running the hook holds its lock until the hook exits, so a mind the hook starts would wait forever. With MIND_IN_HOOK=1 set and the lock held, mind fails at once with nested-in-hook, which fails the hook. Read what the hook needs from these variables, the source’s clone, or the item’s store copy instead. A process the hook leaves running in the background can run mind once the parent mind exits.

Profile variables

Every hook runs with two environment variables describing the source’s install profiles. Each holds a sorted, comma-separated list, or is empty when there is nothing to report:

  • MIND_PROFILES: the profiles enabled for the hook’s source.
  • MIND_ITEM_PROFILES: for an item hook or build hook, the profiles the item is installed for. Always empty for a source hook.
# skills/deploy/setup.sh, run by `install: sh setup.sh`
case ",$MIND_PROFILES," in
  *,full,*) ./setup-full.sh ;;
  *) ./setup-basic.sh ;;
esac

The values are the state the command leaves behind. During meld, learn <source> --profile, and upgrade, they include the profiles being enabled. During forget <source> --profile <name>, MIND_PROFILES is the set that stays enabled.

A source’s install hooks see the selection the meld is about to apply, so on a terminal meld asks which profiles to enable before it runs them. Enabling or disabling a profile later does not run the source’s install hooks again. Put setup that depends on the profile set in an item hook, which runs when its item is installed or removed.

Visibility

recall --sources marks a source that carries hooks with a count-aware token in its status bracket (e.g. 1 hook or 3 hooks). mind review <repo> lists every declared hook (source and item, whichever event), showing each hook’s command, event, and whether it is required or optional. mind hooks list <target> shows the same detail plus the pending/last-ran state of recorded install and update hooks.

Where an item declares its hooks

An item’s own lifecycle hooks (install / update / uninstall) can be declared in three places. They do not merge: the first one that declares anything supplies the item’s hooks. A tool’s build hook is not one of the three: it is declared only as the [[items]].build field in the source’s root mind.toml or as the build: key in a tool’s TOOL.md frontmatter, and a scoped item mind.toml rejects event = "build".

  1. The source’s root mind.toml, in the item’s [[items]] entry (scalar install/update/uninstall, or an [[items.hooks]] array).
  2. A scoped mind.toml in the item’s own directory, for a skill or a tool. Its only table is [[hooks]], with the same fields as a source’s; any other key is an error.
  3. The item’s frontmatter, in whatever file describes it (SKILL.md, TOOL.md, or an agent’s or rule’s .md): the scalar install:, update:, and uninstall: keys, one required hook each.
# skills/scanner/mind.toml
[[hooks]]
run = "./setup.sh"
name = "Set up"

[[hooks]]
run = "./migrate.sh"
event = "update"
<!-- skills/scanner/SKILL.md -->
---
description: scanner
install: ./setup.sh
update: ./migrate.sh
---

An item hook runs in the item’s store directory when the item is directory-backed (a skill or a tool), so a relative ./setup.sh resolves against the item’s own files. A single-file kind (an agent, a rule, or a command) has no directory of its own: its hook runs in the shared kind directory (~/.mind/store/agent/, ~/.mind/store/rule/, ~/.mind/store/command/), and the item ships no scripts, so its hook must be a command on PATH or an absolute path. A relative script there fails the install with a HookFailed hard stop that rolls the install back.

An item manifest is part of the item’s content: it is copied into the store and hashed like any other file, so editing it upstream is drift upgrade picks up. No agent harness reads it; only mind does. These keys are mind’s, not the harness’s. An agent harness reads the same frontmatter block, and mind does not control how a given harness treats keys it does not define, so use the scoped item mind.toml if you would rather keep the item’s frontmatter to what the harness itself defines.

[source].install is deprecated in favor of the [[hooks]] form. See The mind.toml file for the schema and spec/install-hooks.md for the full behavior.