# molted segments

Source: https://molted.email/docs/cli/segments

Manage audience segments

| Command | Description |
| - | - |
| [`molted segments create`](#molted-segments-create) | Create a new segment |
| [`molted segments list`](#molted-segments-list) | List all segments |
| [`molted segments get`](#molted-segments-get) | Get a segment by ID |
| [`molted segments update`](#molted-segments-update) | Update a segment |
| [`molted segments archive`](#molted-segments-archive) | Archive a segment (soft delete: status becomes archived) |
| [`molted segments compute`](#molted-segments-compute) | Compute segment membership |
| [`molted segments members`](#molted-segments-members) | List members of a segment |
| [`molted segments contact`](#molted-segments-contact) | List segments a contact belongs to |

## Agent context

Segments define dynamic groups of contacts based on filter criteria. Use them to scope an experiment (experiments create `--segment`), to check a contact before sending (analytics segment-check), and in journey impact breakdowns.

### Create a segment with filters

```bash
molted segments create --name "Active Users" --filters '{
  "logic": "and",
  "filters": [
    {"type": "metadata", "field": "plan", "operator": "eq", "value": "pro"},
    {"type": "contact_field", "field": "lifecycleStage", "operator": "eq", "value": "lead"}
  ]
}'
# → { "id": "<uuid>", "name": "Active Users", "filterGroup": {...}, "status": "active", ... }
```

- **Filter types:** contact\_field, metadata, account\_field, firmographic, behavioral
- **Operators:** eq, neq, gt, gte, lt, lte, contains, not\_contains, in, not\_in, exists, not\_exists, between

The abbreviated CLI shape is also accepted and normalized at create time so stored segments always use the canonical format above:

```bash
{ "operator": "and", "conditions": [
    { "field": "email", "op": "contains", "value": "test.local" } ] }
```

Missing "type" is inferred from the field name (known contact columns → contact\_field; else → metadata).

### Compute membership (re-evaluates all contacts against the filters)

```bash
molted segments compute <segmentId>
# → { "queued": true, "segmentId": "<uuid>" }: recomputation runs async,
#   results available shortly after
```

### List segment members

```bash
molted segments members <segmentId> --limit 50 --offset 0
# → [{ "id": "<uuid>", "email": "...", "name": ..., "lifecycleStage": ..., "dealStage": ... }]
```

### Check a specific contact's segments

```bash
molted segments contact <contactId>
# → [{ "id": ..., "name": ..., "status": "active" }]: the active segments
#   this contact belongs to
```

### Check segment membership for a contact (useful before sending)

```bash
molted analytics segment-check --contact alice@example.com --segment <segmentId>
# → { "isMember": true, "evaluatedLive": true }
```

### Update or archive

```bash
molted segments update <id> --name "New Name" --filters '<json>'
molted segments archive <id>    # status becomes "archived": it drops out
                                # of segments list and segments contact
```

### Key behaviors

- Segments are dynamic: membership is recomputed on `compute`, and every active segment is queued for recompute after `contacts sync`
- Filters use contact fields and metadata (synced via `contacts sync`)

Related: [`molted contacts`](https://molted.email/docs/cli/contacts.md), [`molted analytics segment-check`](https://molted.email/docs/cli/analytics.md), [`molted journeys`](https://molted.email/docs/cli/journeys.md)

## Commands

### molted segments create

Create a new segment

```bash
molted segments create [options]
```

| Option | Description | Default |
| - | - | - |
| `--name <name>` | Segment name (required) (required) | |
| `--filters <json>` | Filter group as JSON (required) (required) | |

### molted segments list

List all segments

```bash
molted segments list
```

### molted segments get

Get a segment by ID

```bash
molted segments get <id>
```

| Argument | Description | Required |
| - | - | - |
| `<id>` | Segment ID | yes |

### molted segments update

Update a segment

```bash
molted segments update [options] <id>
```

| Argument | Description | Required |
| - | - | - |
| `<id>` | Segment ID | yes |

| Option | Description | Default |
| - | - | - |
| `--name <name>` | Segment name | |
| `--filters <json>` | Filter group as JSON | |

### molted segments archive

Archive a segment (soft delete: status becomes archived)

```bash
molted segments archive <id>
```

| Argument | Description | Required |
| - | - | - |
| `<id>` | Segment ID | yes |

### molted segments compute

Compute segment membership

```bash
molted segments compute <id>
```

| Argument | Description | Required |
| - | - | - |
| `<id>` | Segment ID | yes |

### molted segments members

List members of a segment

```bash
molted segments members [options] <id>
```

| Argument | Description | Required |
| - | - | - |
| `<id>` | Segment ID | yes |

| Option | Description | Default |
| - | - | - |
| `--limit <n>` | Max results (default 50) | |
| `--offset <n>` | Offset for pagination (default 0) | |

### molted segments contact

List segments a contact belongs to

```bash
molted segments contact <contactId>
```

| Argument | Description | Required |
| - | - | - |
| `<contactId>` | Contact ID | yes |

See [CLI overview](https://molted.email/docs/cli.md) for global options, credentials and output format.
