Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
General / UtilityintermediateNew

Feature Flag

Share

Implement feature flag system

Works with OpenClaude

You are a backend engineer implementing a feature flag system. The user wants to create a production-ready feature flag mechanism that controls feature rollout, A/B testing, and gradual deployments.

What to check first

  • Decide on storage backend: in-memory (development), Redis (production), or database (persistent)
  • Verify you have a flag evaluation engine that supports targeting rules (user ID, percentage rollout, custom attributes)
  • Confirm flag types needed: boolean, string variant, multivariate flags

Steps

  1. Define flag schema with name, enabled, rollout_percentage, targeting_rules, and variants fields
  2. Create a FeatureFlagStore abstraction to support pluggable backends (memory, Redis, database)
  3. Implement FeatureFlagEvaluator class with deterministic hashing for consistent rollout (use user ID + flag name)
  4. Add targeting rule matcher supporting conditions like user_id in [list], environment == 'production', custom_attribute matches regex
  5. Implement evaluate(flag_name, user_context) method that applies rollout percentage using consistent hash modulo 100
  6. Add flag caching with TTL to reduce evaluation latency in hot paths
  7. Create admin API endpoints: GET /flags, POST /flags, PATCH /flags/{id}, DELETE /flags/{id}
  8. Instrument flag evaluations with metrics (flag name, variant chosen, evaluation time)

Code

import hashlib
import json
from typing import Any, Dict, List, Optional
from dataclasses import dataclass, asdict
from abc import ABC, abstractmethod
from datetime import datetime, timedelta

@dataclass
class FeatureFlag:
    name: str
    enabled: bool
    rollout_percentage: int = 100
    targeting_rules: List[Dict[str, Any]] = None
    variants: Dict[str, Any] = None
    created_at: str = None
    
    def __post_init__(self):
        if self.targeting_rules is None:
            self.targeting_rules = []
        if self.variants is None:
            self.variants = {}
        if self.created_at is None:
            self.created_at = datetime.utcnow().isoformat()

class FeatureFlagStore(ABC):
    @abstractmethod
    def get_flag(self, name: str) -> Optional[FeatureFlag]: pass
    
    @abstractmethod
    def set_flag(self, flag: FeatureFlag) -> None: pass
    
    @abstractmethod
    def list_flags(self) -> List[FeatureFlag]: pass
    
    @abstractmethod
    def delete_flag(self, name: str) -> None: pass

class InMemoryFlagStore(FeatureFlagStore):
    def __init__(self):
        self.flags: Dict[str, FeatureFlag] = {}
    
    def get

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
generalfeature-flagstoggles

Install command:

curl -o ~/.claude/skills/feature-flag.md https://claude-skills-hub.vercel.app/skills/general/feature-flag.md

Related General / Utility Skills

Other Claude Code skills in the same category — free to download.

Want a General / Utility skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.