Skip to content

CLI Commands

featsync login

Authenticate with your Featsync CLI API key.

Terminal window
featsync login

You’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.

Terminal window
featsync init

Creates a .featsync.json config file linking your local directory to a Featsync project.

Options:

OptionDescription
--project <id>Specify project ID directly

featsync list

List all feature flags in your project.

Terminal window
featsync list

Options:

OptionDescription
--staleShow only stale flags (enabled at 100% for 14+ days)
--jsonOutput as JSON

Examples:

Terminal window
# List all flags
featsync list
# Show only stale flags ready for cleanup
featsync list --stale
# Get JSON output for scripting
featsync list --json

Sample 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.

Terminal window
featsync scan

Options:

OptionDescription
--dir <path>Directory to scan (default: current directory)
--jsonOutput as JSON

Examples:

Terminal window
# Scan current directory
featsync scan
# Scan a specific directory
featsync scan --dir src
# Get JSON output
featsync scan --json

Detected Patterns

The scanner finds these flag usage patterns:

PatternExample
isEnabled()featsync.isEnabled('flag-key')
isEnabledForUser()featsync.isEnabledForUser('flag-key', userId)
useFlag()useFlag('flag-key')
useFlagForUser()useFlagForUser('flag-key', userId)
Object accessflags['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.

Terminal window
featsync cleanup <flag-key> [options]

Arguments:

ArgumentDescription
<flag-key>The flag key to clean up

Options:

OptionDescription
--dry-runPreview changes without applying
--keep-enabledKeep the enabled branch (flag was ON)
--keep-disabledKeep the disabled branch (flag was OFF)
--all-staleClean up all stale flags
--yesSkip confirmation prompts

Examples:

Terminal window
# Preview cleanup for a specific flag
featsync 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 flags
featsync cleanup --all-stale --dry-run
# Clean up all stale flags without prompts
featsync cleanup --all-stale --keep-enabled --yes

How Cleanup Works

  1. Scan - Find all usages of the flag in your code
  2. Classify - Determine which can be auto-transformed
  3. Preview - Show the diff of proposed changes
  4. Apply - Transform the code (with your confirmation)
  5. Backup - Create a backup before changes

Supported Transformations

PatternBeforeAfter (keep-enabled)
If/elseif (flag) { A } else { B }A
If onlyif (flag) { A }A
Ternaryflag ? A : BA
Logical ANDflag && doThing()doThing()
Early returnif (!flag) return(removed)
JSX conditional{flag && <Comp />}<Comp />

Classification Levels

LevelDescriptionAction
SafeSimple patterns that can be auto-transformedAutomatic cleanup
ComplexNested or compound conditionsManual review suggested
SkipDynamic keys or complex expressionsSkipped

Sample Cleanup Preview

Featsync Cleanup
Processing: new-checkout-flow
Flag is currently: ENABLED
Will 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.

Terminal window
featsync undo

Restores files from the backup created during the last cleanup.

Exit Codes

CodeMeaning
0Success
1Error (authentication, network, etc.)
2No flags found / nothing to do

Environment Variables

VariableDescription
FEATSYNC_API_KEYCLI API key (alternative to featsync login)
FEATSYNC_BASE_URLAPI base URL (for self-hosted)
Terminal window
# Use environment variable instead of login
export FEATSYNC_API_KEY=fs_cli_...
featsync list

Next Steps