CLI Commands
featsync login
Authenticate with your Featsync CLI API key.
featsync loginYou’ll be prompted to enter your CLI API key (starts with fs_cli_). Get your key from the dashboard under API Keys.
featsync init
Initialize Featsync in your project directory.
featsync initCreates a .featsync.json config file linking your local directory to a Featsync project.
Options:
| Option | Description |
|---|---|
--project <id> | Specify project ID directly |
featsync list
List all feature flags in your project.
featsync listOptions:
| Option | Description |
|---|---|
--stale | Show only stale flags (enabled at 100% for 14+ days) |
--json | Output as JSON |
Examples:
# List all flagsfeatsync list
# Show only stale flags ready for cleanupfeatsync list --stale
# Get JSON output for scriptingfeatsync list --jsonSample Output:
Flags in project "my-app":
new-checkout boolean ON production dark-mode boolean OFF production new-pricing percentage 25% production old-feature boolean ON production [STALE: 45 days]
Total: 4 flags (1 stale)featsync scan
Scan your codebase for feature flag usage.
featsync scanOptions:
| Option | Description |
|---|---|
--dir <path> | Directory to scan (default: current directory) |
--json | Output as JSON |
Examples:
# Scan current directoryfeatsync scan
# Scan a specific directoryfeatsync scan --dir src
# Get JSON outputfeatsync scan --jsonDetected Patterns
The scanner finds these flag usage patterns:
| Pattern | Example |
|---|---|
isEnabled() | featsync.isEnabled('flag-key') |
isEnabledForUser() | featsync.isEnabledForUser('flag-key', userId) |
useFlag() | useFlag('flag-key') |
useFlagForUser() | useFlagForUser('flag-key', userId) |
| Object access | flags['flag-key'] |
Sample Output
Scanning for feature flags...
Scanned 42 files
Found 7 references to 3 flag(s)
By File:
src/pages/checkout.tsx Line 45: new-checkout [safe: if-else] Line 89: new-checkout [safe: jsx-conditional]
src/components/Cart.tsx Line 23: new-pricing [safe: ternary]
src/lib/features.ts Line 12: dark-mode [complex: nested-condition]
Classification Summary:
Safe: 5 (can be auto-cleaned) Complex: 1 (needs manual review) Skip: 1 (dynamic/complex)featsync cleanup
Remove stale feature flag code from your codebase.
featsync cleanup <flag-key> [options]Arguments:
| Argument | Description |
|---|---|
<flag-key> | The flag key to clean up |
Options:
| Option | Description |
|---|---|
--dry-run | Preview changes without applying |
--keep-enabled | Keep the enabled branch (flag was ON) |
--keep-disabled | Keep the disabled branch (flag was OFF) |
--all-stale | Clean up all stale flags |
--yes | Skip confirmation prompts |
Examples:
# Preview cleanup for a specific flagfeatsync cleanup my-old-flag --dry-run
# Clean up a flag that was enabled (keep the ON branch)featsync cleanup my-old-flag --keep-enabled
# Clean up a flag that was disabled (keep the OFF branch)featsync cleanup my-old-flag --keep-disabled
# Preview cleanup of all stale flagsfeatsync cleanup --all-stale --dry-run
# Clean up all stale flags without promptsfeatsync cleanup --all-stale --keep-enabled --yesHow Cleanup Works
- Scan - Find all usages of the flag in your code
- Classify - Determine which can be auto-transformed
- Preview - Show the diff of proposed changes
- Apply - Transform the code (with your confirmation)
- Backup - Create a backup before changes
Supported Transformations
| Pattern | Before | After (keep-enabled) |
|---|---|---|
| If/else | if (flag) { A } else { B } | A |
| If only | if (flag) { A } | A |
| Ternary | flag ? A : B | A |
| Logical AND | flag && doThing() | doThing() |
| Early return | if (!flag) return | (removed) |
| JSX conditional | {flag && <Comp />} | <Comp /> |
Classification Levels
| Level | Description | Action |
|---|---|---|
| Safe | Simple patterns that can be auto-transformed | Automatic cleanup |
| Complex | Nested or compound conditions | Manual review suggested |
| Skip | Dynamic keys or complex expressions | Skipped |
Sample Cleanup Preview
Featsync Cleanup
Processing: new-checkout-flow
Flag is currently: ENABLEDWill keep the enabled branch (flag was ON)
Found 3 references:
src/pages/checkout.tsx Line 45: if (await featsync.isEnabled('new-checkout-flow'))... [safe: if-else] Line 89: {flag && <NewBadge />} [safe: jsx-conditional]
src/components/Header.tsx Line 23: const showNew = flag && isReady [complex: compound]
Diff preview:
src/pages/checkout.tsx- if (await featsync.isEnabled('new-checkout-flow')) {- return <NewCheckout />;- } else {- return <OldCheckout />;- }+ return <NewCheckout />;
- {newCheckoutFlag && <NewBadge />}+ <NewBadge />
1 reference marked as complex - manual review recommended.
Apply these changes? [y/N]featsync undo
Undo the last cleanup operation.
featsync undoRestores files from the backup created during the last cleanup.
Exit Codes
| Code | Meaning |
|---|---|
0 | Success |
1 | Error (authentication, network, etc.) |
2 | No flags found / nothing to do |
Environment Variables
| Variable | Description |
|---|---|
FEATSYNC_API_KEY | CLI API key (alternative to featsync login) |
FEATSYNC_BASE_URL | API base URL (for self-hosted) |
# Use environment variable instead of loginexport FEATSYNC_API_KEY=fs_cli_...featsync listNext Steps
- CLI Overview - Installation and setup
- Pricing - CLI is included with Pro