<!-- llms.txt: https://workos.com/llms.txt -->
<!-- feedback.md: https://workos.com/docs/feedback.md -->

# Migrate from legacy flag events

## Overview

On **February 1, 2027**, the four legacy feature flag events stop being sent:

- `flag.created`
- `flag.updated`
- `flag.deleted`
- `flag.rule_updated`

They are replaced by the [`feature_flags.*` events](https://workos.com/docs/events#feature-flags), which carry the same information in a namespaced, more granular form. Every flag change currently sends both the legacy events and their replacements, so you can migrate at your own pace before the retirement date. If you need more time, [contact us](mailto:support@workos.com).

After February 1, 2027:

- **Webhooks** subscribed to the legacy events stop receiving them. Endpoints that are not already subscribed to a legacy event can no longer subscribe to it.
- **Events API** requests that filter on the legacy event names keep returning `200`, but no new events match. A sync that polls [`GET /events`](https://workos.com/docs/reference/events) with a legacy name goes quiet without an error, so update the `events` filter rather than waiting for a failure.

> **Using the WorkOS Slack integration for flag notifications?** There is nothing to do. The integration migrates to the new events automatically.

***

## Using a Datadog log stream?

Log streams receive every event, so no code or stream configuration change is needed. If you have monitors, dashboards, or saved searches that match the `flag.*` event names, update them to the `feature_flags.*` names. After February 1, 2027 the legacy names stop matching new events.

***

## Event mapping

| Legacy event        | Replacement                                                                                                                                                                        |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `flag.created`      | `feature_flags.flag.created`                                                                                                                                                        |
| `flag.updated`      | `feature_flags.flag.updated`                                                                                                                                                        |
| `flag.deleted`      | `feature_flags.flag.deleted`                                                                                                                                                        |
| `flag.rule_updated` | `feature_flags.flag.updated` for a flag turned on or off or a default value change, and the `feature_flags.flag_rule.*` and `feature_flags.flag_target.*` events for rule and target changes |

The three renamed events fire on the same triggers as their legacy counterparts and carry the [Feature Flag](https://workos.com/docs/reference/feature-flags) object as the payload `data`. `flag.rule_updated` has no single replacement: it is broken into granular events that describe exactly what changed. See the [Events reference](https://workos.com/docs/events#feature-flags) for every payload.

***

## Migrate with an AI agent

Most of this migration is mechanical, so a coding agent can do the code side. Webhook subscriptions stay a manual step in the WorkOS Dashboard, following the order in the next section.

Most applications only need the migration prompt. The exception: if your server keeps a local copy of flag state fed by `flag.rule_updated` and runs Node.js or Python, run the **runtime client prompt** further down this page first — it replaces the event-driven sync and removes the handlers that fed the copy, so the migration prompt only has the renames left to do.

```text title="Migration prompt"
My application consumes WorkOS feature flag events, through webhooks and/or the WorkOS Events API (GET /events). WorkOS is replacing the legacy flag event names. Update my codebase as described below. Don't change webhook subscriptions yourself: they're configured in the WorkOS Dashboard.

1. Rename these event types everywhere they appear. Payloads are identical; only the "event" field changes.
   - "flag.created" -> "feature_flags.flag.created"
   - "flag.updated" -> "feature_flags.flag.updated"
   - "flag.deleted" -> "feature_flags.flag.deleted"
   Search webhook routing (switch/if/match on the event type), event-type constants and enums, Events API filters, queue consumers, config files and tests.
   "feature_flags.flag.updated" can also fire when a flag is turned on or off or its default value changes in an environment. Make its handler read context.previous_attributes.data to see which fields changed.

2. If my code handles "flag.rule_updated": it is retired, not renamed. First find out what my code does with it, and tell me your plan before changing anything.
   The old event, sent per environment:
   - data: the flag in one environment (id, slug, name, environment_id, enabled, default_value, ...)
   - context.access_type: "none" | "some" | "all"
   - context.configured_targets: every targeted organization {id, name} and user {id, email}
   - context.previous_attributes: previous values of what changed
   Its replacements, all sent per environment:
   - "feature_flags.flag.updated": the flag was turned on or off (data.enabled), its default value changed (data.default_value), or its name, description, owner or tags changed. Previous values of the changed fields are in context.previous_attributes.data.
   - "feature_flags.flag_rule.created" / ".updated" / ".deleted": a targeting rule. data = { object: "flag_rule", id, flag_id, flag_slug, environment_id, target_type ("organization", "user", or a custom target type's slug), position (0-based evaluation order; the first rule that matches wins), value_type, value (the value the rule serves), created_at, updated_at }. ".updated" fires when a rule's value or position changes; context.previous_attributes.data.value holds the previous value.
   - "feature_flags.flag_target.created" / ".deleted": one event per organization, user or custom target added to or removed from a rule. data = { object: "flag_target", id, flag_id, flag_slug, environment_id, target_type, target_id, rule_id, created_at, updated_at }. A target receives the value of its rule (rule_id). These events don't include organization names or user emails; look them up through the WorkOS API by target_id if needed.
   Things that differ from flag.rule_updated:
   - A target can be in a rule that serves false (an exclusion). Don't assume every target has the flag on.
   - There is no access_type. default_value is what everyone not matched by a rule gets.
   - No event carries a flag's full target list, and rules that existed before the switch were never sent as "feature_flags.flag_rule.created". If my code keeps a copy of rules and targets, it needs to load every flag's current rules and targets once (for example from a one-off script) with the WorkOS runtime client. Node.js (@workos-inc/node 12.0.0 or later): const client = workos.featureFlags.createRuntimeClient(); await client.waitUntilReady({ timeoutMs: 5000 }); client.getFlag(slug) for each slug in Object.keys(client.getAllFlags()); client.close(). Python (workos 10.8.0 or later): flags = workos.create_feature_flags_runtime_client(); flags.start(); flags.wait_until_ready(timeout=5); flags.configuration.to_dict()["flags"] maps each slug to its configuration; flags.close(). A configuration lists its rules in evaluation order, each { id, kind: "conditions", value, conditions: [{ target_type, operator: "one_of", values: [target IDs] }] }, and rule IDs match rule_id in the events. Check the installed SDK's types for exact names. If my server can't run either SDK, stop and tell me instead of guessing.
   - The runtime client's configurations omit rules that have no targets yet. If an event references a rule_id that isn't in my copy, reload that flag's configuration from the runtime client instead of guessing the rule's value.
   - Webhooks can arrive out of order. Prefer reading these events from the Events API (GET /events with an "after" cursor), which returns them in order.
   - One change can send several events. For example, adding a target can also create a rule, and moving a rule updates every rule it passes.
   - Deleting a rule or a flag doesn't send separate deleted events for its targets or rules. Treat "feature_flags.flag_rule.deleted" and "feature_flags.flag.deleted" as removing those too.
   Switch in one release: load every flag's current rules and targets if my code keeps a copy, start handling the new events, and stop handling "flag.rule_updated". Don't keep both handlers: WorkOS sends "flag.rule_updated" and its replacements for the same changes until the retirement date, so handling both applies every change twice.

3. Remove handling for "flag.created", "flag.updated" and "flag.deleted" in the same change as the renames, so no change is processed twice. Don't try to pair legacy and new events by event ID; they're separate events with different IDs.

4. When you're done, summarize: what my code did with "flag.rule_updated" and how you replaced it, every file changed, every event name replaced, anything that still references a legacy event name, and the event types I need to add and remove on my webhook endpoint(s) in the WorkOS Dashboard or in any infrastructure-as-code that pins them. Remind me to add the new event types to my endpoint before this ships and to remove the legacy ones only after it has shipped, since a removed legacy event can't be added back, and until it ships not to create targeting rules that serve false.
```

### Optional: let the runtime client keep your flags

If your server keeps a local copy of flag state fed by `flag.rule_updated` and runs Node.js or Python, you can replace the event-driven sync with the [runtime client](https://workos.com/docs/feature-flags/runtime-client) instead of migrating the handlers. This is the prompt to run first, as described at the start of this section; follow it with the migration prompt to finish the renames.

```text title="Runtime client prompt"
My application keeps a local copy of WorkOS feature flag state (in memory, a cache or a database), updated from WorkOS feature flag events such as "flag.rule_updated". Replace that sync with the WorkOS runtime client, which polls WorkOS (every 30 seconds by default), keeps every flag's configuration in memory and evaluates flags locally. First find out what my code does with the copy and what language my server runs, and tell me your plan before changing anything. If my server doesn't run Node.js or Python, stop and tell me. Don't change webhook subscriptions yourself: they're configured in the WorkOS Dashboard.

Create one client per process at startup, not per request.
- Node.js: @workos-inc/node 12.0.0 or later. Runtime clients before 12.0.0 ignore rules that serve false; if the project already uses one, upgrade it and update any getFlag() and bootstrapFlags call sites, since 12.0.0 changes their shapes. const client = workos.featureFlags.createRuntimeClient(); always register client.on('error', ...); await client.waitUntilReady({ timeoutMs: 5000 }); client.isEnabled(slug, { organizationId, userId }, defaultValue); client.getFlag(slug); Object.keys(client.getAllFlags()) lists every slug; client.on('change', ({ key, previous, current }) => ...) fires after a flag changes, with current null when the flag was deleted, and doesn't fire for the first load; client.close() on shutdown.
- Python: workos 10.8.0 or later. flags = workos.create_feature_flags_runtime_client(on_change=...); flags.start(); flags.wait_until_ready(timeout=5); flags.is_enabled(slug, {"organization": org_id, "user": user_id}, default=False); flags.get_flag(slug) returns a FlagDefinition dataclass with the configuration's fields (rules and values are tuples); on_change receives one event with .previous, .current and .changed_flags, and also fires for the first load, when .previous is None; flags.close() on shutdown. Context keys are target types ("organization", "user"), not organization_id or user_id. Under gunicorn or uWSGI, create the client in each worker; uWSGI also needs --enable-threads.
A flag's configuration has slug, enabled, default_value, off_value, and rules in evaluation order, each { id, kind: "conditions", value, conditions: [{ target_type, operator: "one_of", values: [target IDs] }] }. The first rule with a matching condition decides the value, otherwise default_value applies; a disabled flag serves off_value (false). A rule can serve false. Check the installed SDK's types for exact names.

- If the copy only exists to check whether a flag is on, call isEnabled / is_enabled where it's read, and remove the copy.
- If the data itself is used (stored, displayed or sent elsewhere), write it from the runtime client: load every flag once the client is ready, then write each changed flag's full configuration from the change listener. On that first complete load, also delete stored flags that are absent from the snapshot (they were removed while the application was down), and delete a flag's row when a change event reports it as deleted (in Node, current is null; check the installed Python SDK's types for how its change event reports a deletion).
- Have one process own the writes to shared storage (a designated worker or scheduled job) and let the others only read. Every process runs its own client, and the configurations carry no version to reject a stale write, so concurrent writers can overwrite a newer configuration with an older one.
- Remove the event handlers that only fed the copy, and leave handling for other WorkOS events alone.
- Organization names and user emails aren't included. Tell me if any code needs them, or needs to react faster than the polling interval.

When you're done, summarize: every file changed, any code that still handles WorkOS feature flag events, and the event types I can remove from my webhook endpoint(s) in the WorkOS Dashboard or in any infrastructure-as-code that pins them. Remind me not to create targeting rules that serve false until this ships.
```

***

## Migrate your webhook endpoint

Migrate in this order so no event is missed and a rollback stays safe:

1. **Add the new events to your endpoint**, keeping the legacy events subscribed. Your endpoint must return a `2xx` response for event types it does not handle yet.
2. **Deploy code that handles the new events.**
3. **Remove the legacy events from your endpoint last.** Once a legacy event is removed from an endpoint, it cannot be added back.

While both sets are subscribed, each change delivers a legacy event and its replacement. Do not try to correlate the two payloads: rule and target changes do not update the flag's `updated_at`, so the payloads share no key. Instead, have your handler act on one event family at a time — keep acting on the legacy events while you build the new handling, then switch to acting on the new events and ignore the legacy ones until you remove them from the subscription. Delivery order is not guaranteed across the two families, so a change that lands exactly at the switch can be ignored by both handlers: after switching, refresh any local flag state from the API once rather than waiting for the next event. The events page in the [WorkOS Dashboard](https://dashboard.workos.com) shows both events for each change until the retirement date.

***

## Migrating from `flag.rule_updated`

The legacy event sends the flag object plus the full list of configured targets on every targeting change:

```json title="Before: flag.rule_updated"
{
  "event": "flag.rule_updated",
  "id": "event_01K43DV45EXDX2M6M903MHYHP3",
  "data": {
    "id": "flag_01K43DMGCCK0STXE0EJT2AHQN0",
    "name": "Advanced Audit Logging",
    "slug": "advanced-audit-logging",
    "object": "feature_flag"
  },
  "context": {
    "access_type": "some",
    "configured_targets": {
      "organizations": [
        { "id": "org_01K1C52WNZ2CR3A9QYHHVWXYZ1", "name": "Acme Corp" }
      ],
      "users": []
    }
  }
}
```

The replacement events describe the individual rule or target that changed, including the `value` a rule serves and the `rule_id` a target belongs to:

```json title="After: feature_flags.flag_rule.updated"
{
  "event": "feature_flags.flag_rule.updated",
  "id": "event_01K43E5H2K4M6N8P0Q2R4S6T8V",
  "data": {
    "object": "flag_rule",
    "id": "flag_rule_01K43E0P6S8T2V4W6X8Y0Z2A4B",
    "flag_id": "flag_01K43DMGCCK0STXE0EJT2AHQN0",
    "flag_slug": "advanced-audit-logging",
    "environment_id": "environment_01K43DGP2ZQ8G5TQ3R5V7XB4E1",
    "target_type": "organization",
    "position": 0,
    "value_type": "boolean",
    "value": false
  },
  "context": {
    "previous_attributes": {
      "data": { "value": true }
    }
  }
}
```

Field by field, here is where each piece of the legacy payload went:

| What `flag.rule_updated` tells you                                    | Where it is now                                                                                                                      |
| --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| On or off (`data.enabled`) and the default value (`data.default_value`) | `feature_flags.flag.updated`, with previous values in `context.previous_attributes.data`                                              |
| Targeted organizations and users (`context.configured_targets`)        | `feature_flags.flag_target.created` and `.deleted`, one per target, each with the `rule_id` of its rule                                |
| None, some or all (`context.access_type`)                              | No equivalent: derive it from `default_value` plus the `value` each rule serves                                                        |
| Organization names and user emails                                     | Not included; look them up by `target_id`                                                                                              |
| —                                                                      | New: `feature_flags.flag_rule.created`, `.updated` and `.deleted`, with each rule's target type, position in evaluation order, and the value it serves |

How to migrate depends on what your handler does with the event.

### If you use it as a change signal

If your code treats `flag.rule_updated` as "something changed, refresh", subscribe to `feature_flags.flag.updated`, the `feature_flags.flag_rule.*` events, and the `feature_flags.flag_target.*` events, and refresh on any of them. You do not need to read the payloads.

If you refresh a local cache of flag state, consider the [runtime client](https://workos.com/docs/feature-flags/runtime-client) instead: it keeps an up-to-date local snapshot without webhooks.

### If you rebuild flag state from the payload

The legacy payload's `configured_targets` list cannot express rules that serve `false`, which the flag editor supports. Rebuild state from the granular events, or re-fetch the flag's state after a change instead of deriving it from payloads.

A rule with `"value": false` excludes its targets. If your code assumes every target means the flag is enabled, those flags evaluate incorrectly as soon as an exclusion rule is added. Handle `value` explicitly, or use the runtime client, which evaluates rules for you.

> **Already using the runtime client?** Versions below `@workos-inc/node` 12.0, `@workos-inc/authkit-nextjs` 4.6.0, and `workos` (Python) 10.8.0 skip rules that serve `false`. Upgrade before adding exclusion rules to your flags.

***

## SDK support

These SDK versions parse the new events into typed models in webhook handlers:

| SDK    | Minimum version |
| ------ | --------------- |
| Node   | 12.3.0          |
| Python | 10.7.0          |
| Go     | 10.7.0          |
| .NET   | 6.7.0           |
| Kotlin | 7.6.0           |
| Ruby   | 10.8.0          |

The Rust (3.6.0), PHP (9.6.0), and iOS (0.9.0) SDKs deliver the new events without typed models. The Elixir and Android SDKs do not model the new events; match on the raw event name. On any SDK version, the new events are delivered to your endpoint as JSON regardless of typed support.

***

## Learn more

- [Events reference: feature flag events](https://workos.com/docs/events#feature-flags)
- [Feature Flags API reference](https://workos.com/docs/reference/feature-flags)
- [Webhooks](https://workos.com/docs/events/data-syncing/webhooks)
