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

# LaunchDarkly Feature Flags

> Evaluate LaunchDarkly flags through the shared Refract feature flag contract.

**LaunchDarkly feature flags** target teams that already standardize on LaunchDarkly for rollout control and user targeting.

<details>
  <summary>🤖 Agent context</summary>

  Implementation: `apps/tools/featureFlags/launchDarkly/src/index.ts` — bulk via `allFlagsState`, per-flag fall-through via `boolVariation` / `variation`.

  ❌ Do not import LaunchDarkly SDKs outside `apps/tools/featureFlags/launchDarkly/`.
  ❌ Do not call `allFlagsState` from GraphQL resolvers — use `tools.featureFlags`.
  ❌ Do not expose operational flags through `exposedFlags`.

  Verify with: `make test module=tooling-feature-flags-launch-darkly` and `make test module=backend path=apps/backend/src/tools/featureFlags`
</details>

## Why

LaunchDarkly provides mature targeting, audit trails, and SDK ergonomics for larger teams. Refract keeps that power behind the same `FeatureFlagTool` contract used by PostHog and LOCAL providers.

## Setup

1. Add `tooling-feature-flags-launch-darkly` to `apps/backend/package.json`.
2. Run `make deps-install`.
3. Configure the environment:

```ts theme={null}
featureFlags: {
  client: FeatureFlagClientType.LAUNCH_DARKLY,
  cacheMs: 30_000,
  sdkKey: process.env.LAUNCHDARKLY_SDK_KEY,
  exposedFlags: ['new-dashboard'],
},
```

4. Set `LAUNCHDARKLY_SDK_KEY` in the deployment environment.

## Evaluation context

LaunchDarkly contexts are built from `FeatureFlagContext`:

* `userId` → context key (defaults to `anonymous`)
* `organizationId`, `environment`, and `attributes` → context attributes

## Gotchas

* The SDK initializes during `buildFeatureFlags()` — allow a few seconds on cold start.
* String flag values surface as `variant` with `enabled: true`.
* Use `cacheMs` to reduce SDK chatter; request caching still applies per HTTP request.

## What's next?

* [Feature flags overview](/tooling/feature-flags/overview)
* [PostHog provider](/tooling/feature-flags/posthog)
* [Configuration system](/architecture/configuration-system)
