Feature flag implementation for Google Antigravity IDE
# Feature Flags Guide for Google Antigravity
Master feature flags in Google Antigravity IDE. This guide covers flag management, gradual rollouts, and A/B testing.
## Basic Feature Flag System
```typescript
interface FeatureFlag {
name: string;
enabled: boolean;
percentage?: number;
userIds?: string[];
}
const flags: Record<string, FeatureFlag> = {
newDashboard: { name: "newDashboard", enabled: false, percentage: 10 },
darkMode: { name: "darkMode", enabled: true }
};
function isFeatureEnabled(flagName: string, userId?: string): boolean {
const flag = flags[flagName];
if (!flag || !flag.enabled) return false;
if (flag.userIds && userId && flag.userIds.includes(userId)) {
return true;
}
if (flag.percentage !== undefined) {
const hash = hashUserId(userId || "anonymous");
return hash % 100 < flag.percentage;
}
return flag.enabled;
}
```
## React Hook
```typescript
export function useFeatureFlag(flagName: string): boolean {
const context = useContext(FlagsContext);
return context?.isEnabled(flagName) ?? false;
}
export function FeatureGate({ flag, children, fallback }: {
flag: string;
children: ReactNode;
fallback?: ReactNode;
}) {
const isEnabled = useFeatureFlag(flag);
return isEnabled ? <>{children}</> : <>{fallback}</>;
}
```
## Best Practices
1. **Default to off** - New flags should be disabled
2. **Clean up old flags** - Remove after rollout
Google Antigravity IDE provides feature flag scaffolding.This Feature Flags prompt is ideal for developers working on:
By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their feature flags implementations.
Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.
This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.
You can modify the prompt by adding specific requirements, constraints, or preferences. For Feature Flags projects, consider mentioning your framework version, coding style, and any specific libraries you're using.