# Feature Flags

> Feature flag strategies, rollout patterns, kill switches and flag lifecycle management

- **Type:** Skill
- **Install:** `agentstack add skill-camilooscargbaptista-cto-toolkit-feature-flags`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [camilooscargbaptista](https://agentstack.voostack.com/s/camilooscargbaptista)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [camilooscargbaptista](https://github.com/camilooscargbaptista)
- **Source:** https://github.com/camilooscargbaptista/cto-toolkit/tree/main/feature-flags

## Install

```sh
agentstack add skill-camilooscargbaptista-cto-toolkit-feature-flags
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Feature Flags

## When to Use
- Gradual rollout of new features (canary, percentage)
- A/B testing
- Kill switch for risky features in production
- Trunk-based development (merge without releasing)
- Customer-specific feature enablement

## Flag Types

| Type | Purpose | Lifespan | Example |
|------|---------|----------|---------|
| **Release** | Control feature rollout | Short (days-weeks) | `ENABLE_NEW_BILLING_UI` |
| **Experiment** | A/B testing | Medium (weeks) | `EXPERIMENT_CHECKOUT_V2` |
| **Ops** | Kill switch | Permanent | `ENABLE_EXTERNAL_PAYMENTS` |
| **Permission** | Per-customer features | Permanent | `PREMIUM_ANALYTICS` |

## Implementation

### Simple (Config-based)
```typescript
// Feature flags from environment/config
const FLAGS = {
  ENABLE_NEW_BILLING: process.env.FF_NEW_BILLING === 'true',
  ENABLE_DARK_MODE: process.env.FF_DARK_MODE === 'true',
};

// Usage
if (FLAGS.ENABLE_NEW_BILLING) {
  return this.newBillingService.process(order);
} else {
  return this.legacyBillingService.process(order);
}
```

### Advanced (Database-backed)
```typescript
@Entity('feature_flags')
class FeatureFlag {
  @PrimaryColumn()
  key: string;                    // 'ENABLE_NEW_BILLING'

  @Column({ default: false })
  enabled: boolean;               // Global toggle

  @Column({ type: 'int', default: 0 })
  rollout_percentage: number;     // 0-100

  @Column({ type: 'simple-array', nullable: true })
  allowed_tenants: string[];      // Specific tenants

  @Column({ type: 'simple-array', nullable: true })
  allowed_users: string[];        // Specific users

  @Column({ type: 'timestamp', nullable: true })
  expires_at: Date;               // Auto-disable date
}

@Injectable()
export class FeatureFlagService {
  constructor(
    @InjectRepository(FeatureFlag) private repo: Repository,
    private cache: CacheManager,
  ) {}

  async isEnabled(
    key: string,
    context: { userId?: string; tenantId?: string },
  ): Promise {
    const flag = await this.getFlag(key);
    if (!flag || !flag.enabled) return false;

    // Check expiration
    if (flag.expires_at && flag.expires_at  0 && context.userId) {
      const hash = this.hashUserId(context.userId);
      return (hash % 100)  3 months old)
- ❌ Testing only with flags ON (also test OFF)
- ❌ Using flags for permanent business logic (use permissions)
- ❌ Too many flags (> 20 active = confusion)

## Quality Gates

- [ ] Every flag has an owner and expiration date
- [ ] Cleanup task created when flag reaches 100%
- [ ] Dashboard showing all active flags and their rollout %
- [ ] Alert if flag is > 90 days old without cleanup
- [ ] Both flag-on and flag-off paths tested

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [camilooscargbaptista](https://github.com/camilooscargbaptista)
- **Source:** [camilooscargbaptista/cto-toolkit](https://github.com/camilooscargbaptista/cto-toolkit)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** yes
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-camilooscargbaptista-cto-toolkit-feature-flags
- Seller: https://agentstack.voostack.com/s/camilooscargbaptista
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
