# Lifecycle hooks

> Run your own commands before and after Kanbus operations, with a stable JSON payload, so validations, notifications and integrations plug into the CLI without forking it.

Canonical: https://kanb.us/features/lifecycle-hooks.html

Lifecycle hooks make Kanbus command boundaries programmable. A hook is an external command that Kanbus runs before or after an operation, such as creating, updating or listing issues. The engine behaves the same in the Python and Rust CLIs, and in both native and Beads compatibility modes.

::video{src="https://dmhqusv90xmye.cloudfront.net/kanbus-feature-videos/lifecycle-hooks.mp4" poster="https://dmhqusv90xmye.cloudfront.net/kanbus-feature-videos/lifecycle-hooks.jpg" title="Lifecycle Hooks"}

## Events and phases

:::two-up
:::column
**Mutating events:** `issue.create`, `issue.update`, `issue.close`, `issue.delete`, `issue.comment`, `issue.dependency`, `issue.promote`, `issue.localize`.

**Read events:** `issue.show`, `issue.list`, `issue.ready`.
:::
:::column
**Before hooks** on mutating events fail closed by default: if the hook fails or times out, the command does not run.

**After hooks** are observers. A failure prints a warning and does not undo a command that already succeeded.
:::
:::

These are Kanbus CLI hooks. They are separate from coding-agent hooks such as the ones that reinject context after compaction.

## Configure hooks

Hooks live in a `hooks` block in `.kanbus.yml`. Each entry needs an `id` and a `command` argument list, and can set `blocking`, `timeout_ms`, `cwd` and `env`.

```yaml
hooks:
  enabled: true
  run_in_beads_mode: true
  default_timeout_ms: 5000
  before:
    issue.update:
      - id: validate-update
        command: ["./hooks/validate-update.sh"]
        timeout_ms: 1200
  after:
    issue.create:
      - id: notify-created
        command: ["./hooks/notify-created.sh"]
        env:
          WEBHOOK_URL: "https://example.invalid/hooks"
```

Every hook receives the same JSON envelope on stdin, with the schema version, phase, event, timestamp, actor, mode details (project root, working directory, runtime) and an `operation` object with event-specific context such as identifiers and before and after issue snapshots when available.

```json
{
  "schema_version": "kanbus.hooks.v1",
  "phase": "after",
  "event": "issue.create",
  "actor": "dev@example.com",
  "operation": { "issue": { "identifier": "kanbus-a1b2c3", "title": "..." } }
}
```

## Inspect, validate and disable

```bash
kbs hooks list
kbs hooks validate
kbs --no-hooks list
KANBUS_NO_HOOKS=1 kbs list
```

`kbs hooks validate` rejects unknown events, empty hook lists and duplicate IDs, and checks command and `cwd` paths. [Policy as code](/features/policy-as-code.html) guidance runs in the same engine as a built-in provider: `--no-guidance` turns off only that guidance, while `--no-hooks` turns off everything.

## Learn more

- [Lifecycle hooks](https://github.com/AnthusAI/Kanbus/blob/main/docs/LIFECYCLE_HOOKS.md) for the full event catalog, payload contract and validation rules.
- [Agent compaction and right-now elicitation](https://github.com/AnthusAI/Kanbus/blob/main/docs/AGENT_COMPACTION_RIGHT_NOW.md) for coding-agent hooks, which are a different mechanism.
- Related features: [Policy as code](/features/policy-as-code.html), [Command line](/features/core-management.html), [Beads compatibility](/features/beads-compatibility.html).
