All skills
launchdarkly avatar

/launchdarkly-flag-create

@3039201 official

Create and configure LaunchDarkly feature flags in a way that fits the existing codebase. Use when the user wants to create a new flag, wrap code in a flag, add a feature toggle, or set up an experiment. Guides exploration of existing patterns before creating.

Use this Skill: https://skilld.dev/gh/launchdarkly/agent-skills/launchdarkly-flag-create

This session only. Nothing lands on disk.

referencessdk-evaluation-patterns.md

≈1.7k tokens on demand. Your agent reads this file only when SKILL.md points to it.

SDK Evaluation Patterns

How to evaluate feature flags in each LaunchDarkly SDK. Use this reference to match the patterns already in use in the codebase.

JavaScript/TypeScript (Node.js Server SDK)

// Standard boolean evaluation
const enabled = await ldClient.boolVariation('flag-key', context, false);

// Standard string evaluation
const variant = await ldClient.stringVariation('flag-key', context, 'default');

// Standard number evaluation
const limit = await ldClient.numberVariation('flag-key', context, 10);

// JSON evaluation
const config = await ldClient.jsonVariation('flag-key', context, {});

// Generic evaluation (returns any type)
const value = await ldClient.variation('flag-key', context, defaultValue);

// With evaluation details (includes reason for the variation served)
const detail = await ldClient.boolVariationDetail('flag-key', context, false);
// detail.value, detail.variationIndex, detail.reason

// All flags at once
const allFlags = await ldClient.allFlagsState(context);

JavaScript/TypeScript (React SDK)

// Hook-based (most common in React)
import { useFlags, useLDClient } from 'launchdarkly-react-client-sdk';

function MyComponent() {
  const { flagKey } = useFlags();         // camelCase access
  const flags = useFlags();
  const value = flags['flag-key'];        // bracket access for kebab-case keys

  // Direct client access when needed
  const ldClient = useLDClient();
  const variant = ldClient?.variation('flag-key', 'default');
}

// HOC pattern (older codebases)
import { withLDConsumer } from 'launchdarkly-react-client-sdk';

class MyComponent extends React.Component {
  render() {
    const enabled = this.props.flags['flag-key'];
    return enabled ? <NewFeature /> : <OldFeature />;
  }
}
export default withLDConsumer()(MyComponent);

Python

# Standard evaluation
enabled = ld_client.variation('flag-key', context, False)

# Typed evaluations
enabled = ld_client.bool_variation('flag-key', context, False)
variant = ld_client.string_variation('flag-key', context, 'default')
limit = ld_client.int_variation('flag-key', context, 10)
ratio = ld_client.float_variation('flag-key', context, 0.0)
config = ld_client.json_variation('flag-key', context, {})

# With details
detail = ld_client.variation_detail('flag-key', context, False)
# detail.value, detail.variation_index, detail.reason

# All flags
all_flags = ld_client.all_flags_state(context)

Go

// Typed evaluations
enabled, err := ldClient.BoolVariation("flag-key", context, false)
variant, err := ldClient.StringVariation("flag-key", context, "default")
limit, err := ldClient.IntVariation("flag-key", context, 10)
ratio, err := ldClient.Float64Variation("flag-key", context, 0.0)
config, err := ldClient.JSONVariation("flag-key", context, ldvalue.Null())

// With details
detail, err := ldClient.BoolVariationDetail("flag-key", context, false)
// detail.Value, detail.VariationIndex, detail.Reason

// All flags
allFlags := ldClient.AllFlagsState(context)

Java/Kotlin

// Typed evaluations
boolean enabled = ldClient.boolVariation("flag-key", context, false);
String variant = ldClient.stringVariation("flag-key", context, "default");
int limit = ldClient.intVariation("flag-key", context, 10);
double ratio = ldClient.doubleVariation("flag-key", context, 0.0);
LDValue config = ldClient.jsonValueVariation("flag-key", context, LDValue.ofNull());

// With details
EvaluationDetail<Boolean> detail = ldClient.boolVariationDetail("flag-key", context, false);
// detail.getValue(), detail.getVariationIndex(), detail.getReason()

// All flags
FeatureFlagsState allFlags = ldClient.allFlagsState(context);

Ruby

# Standard evaluation
enabled = ld_client.variation('flag-key', context, false)

# Typed evaluations
enabled = ld_client.bool_variation('flag-key', context, false)
variant = ld_client.string_variation('flag-key', context, 'default')
limit = ld_client.number_variation('flag-key', context, 10)
config = ld_client.json_variation('flag-key', context, {})

# With details
detail = ld_client.variation_detail('flag-key', context, false)
# detail.value, detail.variation_index, detail.reason

# All flags
all_flags = ld_client.all_flags_state(context)

.NET (C#)

// Typed evaluations
bool enabled = ldClient.BoolVariation("flag-key", context, false);
string variant = ldClient.StringVariation("flag-key", context, "default");
int limit = ldClient.IntVariation("flag-key", context, 10);
float ratio = ldClient.FloatVariation("flag-key", context, 0.0f);
double precise = ldClient.DoubleVariation("flag-key", context, 0.0);
LdValue config = ldClient.JsonVariation("flag-key", context, LdValue.Null);

// With details
EvaluationDetail<bool> detail = ldClient.BoolVariationDetail("flag-key", context, false);
// detail.Value, detail.VariationIndex, detail.Reason

// All flags
FeatureFlagsState allFlags = ldClient.AllFlagsState(context);

Common Wrapper Patterns

Many teams build abstraction layers over the SDK. Search for these in addition to direct SDK calls:

// Service/utility wrappers
featureFlagService.isEnabled('flag-key');
featureFlagService.getValue('flag-key');
FeatureFlags.isEnabled('flag-key');
flagsClient.check('flag-key');

// Constants/enums for flag keys
FLAGS.NEW_CHECKOUT_FLOW
FeatureFlag.NEW_CHECKOUT_FLOW
FEATURE_FLAGS['flag-key']
const FLAG_KEY = 'flag-key';

// Decorator patterns (Python/Java)
@feature_flag('flag-key')
@FeatureFlag("flag-key")

// React context/provider patterns
<FeatureFlagProvider flags={['flag-key']}>
  <ConditionalFeature flag="flag-key">
    <NewFeature />
  </ConditionalFeature>
</FeatureFlagProvider>

// Configuration files (YAML, JSON)
feature_flags:
  flag-key: true

Adding a New Flag Evaluation

When adding flag evaluation code, follow this pattern:

  1. Import/access the client the same way existing code does
  2. Define the flag key following the project's convention (constants file, inline, etc.)
  3. Choose the right evaluation method based on the flag type
  4. Set a safe default value: the behavior when LaunchDarkly is unreachable
  5. Add the conditional logic for each variation

Example: Adding a boolean flag (Node.js)

// If the codebase uses constants:
// In flags.ts / constants.ts
export const NEW_CHECKOUT_FLOW = 'new-checkout-flow';

// In the feature code:
import { NEW_CHECKOUT_FLOW } from '../flags';

const showNewCheckout = await ldClient.boolVariation(
  NEW_CHECKOUT_FLOW,
  context,
  false  // default: keep old behavior if LD is unreachable
);

if (showNewCheckout) {
  return renderNewCheckout();
} else {
  return renderOldCheckout();
}

Example: Adding a boolean flag (React)

import { useFlags } from 'launchdarkly-react-client-sdk';

function CheckoutPage() {
  const { newCheckoutFlow } = useFlags();

  if (newCheckoutFlow) {
    return <NewCheckout />;
  }
  return <OldCheckout />;
}

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill provides guidelines and instruction on creating and managing LaunchDarkly feature flags, relying entirely on the official LaunchDarkly MCP server tools and following standard developer practices.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    2/5 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 3039201. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated 2 months ago
compatibility
Requires the remotely hosted LaunchDarkly MCP server
metadata
{
  "author": "launchdarkly",
  "version": "1.1.0-experimental"
}

README badge

README badge for launchdarkly/agent-skills/launchdarkly-flag-create

Creates and configures LaunchDarkly feature flags by first exploring the codebase for existing flag patterns, then applying those conventions to create the flag and add evaluation code. Works with the LaunchDarkly MCP server to handle flag creation and metadata updates.

Generated from the current SKILL.md.

Does this skill handle flag targeting and rollouts?
No. This skill creates and configures flags. To toggle flags on, set up rollout rules, or target specific users, use the flag targeting skill.
What happens if LaunchDarkly is unreachable when my code evaluates a flag?
The SDK falls back to the default value you specify in code. That's why the skill guides you to use the existing/safe behavior as the default—it ensures the feature stays off if LaunchDarkly is down.
Can I change a flag's key after creating it?
No. Flag keys are immutable once created, so the skill helps you choose the right key upfront by examining your codebase's naming conventions.
Do I need the LaunchDarkly MCP server to use this skill?
Yes. The skill requires the remotely hosted LaunchDarkly MCP server to be configured in your environment to create and verify flags.
Does this skill work with all LaunchDarkly SDKs?
The skill guides flag creation for any SDK and helps you match existing patterns in your codebase, whether you're using the Node, React, Python, Go, Java, or other LaunchDarkly SDK.

Generated from the current SKILL.md. These answers refresh after source changes.