← ClaudeAtlas

use-feature-flagslisted

Use when gating a code path behind a feature flag or rolling something out gradually — evaluating a flag from a central flag service (scoped by service + flag name + user/session + targeting properties), failing safe (unknown/error/timeout = off), caching the lookup, and choosing a flag over a NODE_ENV/env branch. Covers flag lifecycle (name, owner, removal) and its tie to safe releases. NestJS/TS reference, framework-flexible.
kennguyen887/agent-foundation · ★ 1 · Web & Frontend · score 77
Install: claude install-skill kennguyen887/agent-foundation
# Use feature flags Gate behaviour behind a runtime flag instead of a redeploy or an environment branch. Examples NestJS/TS, neutral domain. principle → **▸ Example** → **▸ Other stacks**. Pairs with `release-safety` (flags are how you ramp + roll back a release) and restates the global *Feature Flags & Observability* rule. ## Core principle **Gate rollouts on an explicit flag evaluated at runtime, never on `NODE_ENV` or a redeploy — and fail safe.** A flag turns a feature on/off (or picks a variant) for a user/cohort *without shipping code*; if the flag service is unreachable or the flag is unknown, the code must fall back to a **safe default (usually OFF)**, never crash. ## 1. Evaluate against a central flag service (with targeting context) - A small shared client asks a **central flag/config service** to evaluate a flag, passing the **targeting context** — which service is asking, the flag name, and who for (user/session) plus optional properties — so the service can do **% rollouts and cohort targeting** centrally. ```ts // query → central service (message pattern / SDK); response is the decision const { isEnabled } = await this.flags.get({ service: SERVICE_NAME, flagName: 'new-checkout', userId, sessionId, properties: { country, plan }, // targeting context for gradual rollout }); if (isEnabled) { /* new path */ } else { /* current path */ } ``` - Keep flag **names as constants**, not inline strings; the service owns the rollout %/rules, the