> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackshift.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Events from the CLI and stackshift.yaml

> List the catalog, tail live events, add a webhook and replay deliveries from the CLI, and declare rules in stackshift.yaml under spec.events.rules.

> [!TIP]
>
> **Live.** This area is documented as current, user-reliable behavior.

## Goal

Work with events from a terminal and keep rules in your repository.

## Prerequisites

* The StackShift CLI, signed in with stackshift auth login.
* For config as code, a stackshift.yaml v2 file.

## Workflow

**Step 1**

Run stackshift events catalog --product hosting to find event types.

**Step 2**

Run stackshift events tail --type "deploy.\*" to watch events live.

**Step 3**

Run stackshift events subscribe --url [https://example.com/hooks/stackshift](https://example.com/hooks/stackshift) --type deploy.failed to add a webhook. Copy the signing secret it prints; it is shown once.

**Step 4**

Add rules under spec.events.rules in stackshift.yaml and deploy.

## CLI commands

* tail prints time, type, subject and actor for each event. --type repeats.
* \--team takes a team name or id, or personal.
* Rules, destinations and deliveries are managed in the dashboard, the API or stackshift.yaml.

```bash stackshift events theme={null}
stackshift events catalog [--product PRODUCT] [--json]
stackshift events tail [--type PATTERN]... [--project PROJECT] [--team TEAM] [--json]
stackshift events subscribe --url URL --type PATTERN [--type PATTERN]...
stackshift events replay DELIVERY
```

## stackshift.yaml

* name is required and unique; it identifies the rule between deploys.
* on takes one or more event patterns.
* where takes conditions on data. Each sets exactly one of is, is\_one\_of, starts\_with or has\_value: true.
* to sets exactly one target: function (a function path in this project), webhook (a URL), queue (\{ queue, job }), job\_event (\{ name, correlation\_path }), agent (an agent id, or stackie) or notify (a list of in\_app, email, slack).
* service names the service when the application has more than one.
* On deploy, StackShift creates and updates rules by name and removes rules you deleted from the file. Rules from the file cannot be edited in the dashboard. A webhook destination created from the file gets a signing secret nobody has seen: use Make a new secret in Destinations to read one.

```yaml spec.events.rules theme={null}
apiVersion: stackshift.com/v1
kind: Application
metadata:
  name: shop
spec:
  services:
    web:
      type: web
  events:
    rules:
      - name: Resize new uploads
        on: [storage.object.created]
        where:
          - { field: bucket, is: uploads }
          - { field: content_type, starts_with: "image/" }
        to:
          function: api/resize.ts
      - name: Page on failed deploys
        on: ["deploy.failed"]
        to:
          notify: [email, slack]
```

## Expected result

> [!TIP]
>
> Rules from the file show in Events, Rules and stay in step with the file on every deploy.

## Related guides

> [card] [Rules and filters](https://docs.stackshift.cloud/events/rules-and-filters.md)
>
> A rule matches events by type pattern, project, subject and data conditions, then sends each match to one target.

> [card] [Config as code (stackshift.yaml)](https://docs.stackshift.cloud/applications/config-as-code.md)
>
> Describe an application in one file in your repository. Every push applies it, every pull request shows a plan, and risky changes wait for you.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.