> For the complete documentation index, see [llms.txt](https://docs.reflag.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.reflag.com/api/cli.md). Agents can also search and read this documentation through its [MCP server](https://docs.reflag.com/~gitbook/mcp).

# CLI

Command-line interface for interacting with Reflag services. The CLI allows you to manage apps, flags, authentication, and generate TypeScript types for your Reflag flags. With this tool, you can streamline your flagging workflow directly from your terminal.

## SDK v2 generation <a href="#sdk-v2-generation" id="sdk-v2-generation"></a>

CLI v2 generates types for the **Node, React, and Vue v2 SDKs**. If you use SDK v1, stay on CLI 1.x for legacy type generation.

`reflag flags types` reads Boolean flag headers and current multivariate variants in the app's production environment. Generated `Flags` entries are direct value types, not `.config.payload` wrappers. Regenerate old declarations when migrating. Formats are `node`, `react`, and `vue`; you can configure multiple outputs.

Registered non-null defaults are checked against the generated value type, including required and nested fields. Singular return types still widen from the supplied default. Bare/`undefined` reads remain Boolean; explicit `null` requests arbitrary JSON. Generated schemas reflect current authored variants and do not add nested runtime validation; regenerate when values change. Unconfigured multivariate flags and empty shapes retain JSON-capable types rather than silently becoming Boolean or `any`.

## Installation <a href="#installation" id="installation"></a>

Install the CLI as a development dependency in your project:

```bash
# npm
npm install --save-dev @reflag/cli

# yarn
yarn add --dev @reflag/cli
```

Run the `new` command from your project's root directory to initialize the CLI, create a flag, and generate TypeScript types in one step:

```bash
# npm
npx reflag new

# yarn
yarn reflag new
```

## Migrating from Bucket SDK <a href="#migrating-from-bucket-sdk" id="migrating-from-bucket-sdk"></a>

If you're migrating from the Bucket CLI, here are the key changes to be aware of:

* **Command name**: Changed from `bucket` to `reflag`
* **Type definitions file**: Renamed from `features.d.ts` to `flags.d.ts` (manually remove the old file if it was committed)
* **Authentication file**: Changed from `.bucket-auth` to `.reflag-auth` (rename or remove the old file)
* **Configuration file**: Changed from `bucket.config.json` to `reflag.config.json` (rename or remove the old file)
* **Command**: `features` command is now `flags`
* **Environment variable**: Use `REFLAG_API_KEY` instead of `BUCKET_API_KEY`

**Important**: Update your scripts, build steps, and `.gitignore` patterns to reflect these changes.

### Individual Commands <a href="#individual-commands" id="individual-commands"></a>

For more control, you can run each command individually:

```bash
# Initialize Reflag in your project (if not already setup)
npx reflag init

# Create a new flag
npx reflag flags create "My Flag"

# Generate TypeScript types for your flags
npx reflag flags types
```

## Configuration <a href="#configuration" id="configuration"></a>

The CLI creates a `reflag.config.json` file in your project directory when you run `reflag init`. This file contains all the necessary settings for your Reflag integration.

### Configuration File Structure <a href="#configuration-file-structure" id="configuration-file-structure"></a>

Here are all the configuration options available in the `reflag.config.json` file:

```json
{
  "$schema": "https://unpkg.com/@reflag/cli@latest/schema.json",
  "baseUrl": "https://app.reflag.com",
  "apiUrl": "https://app.reflag.com/api",
  "appId": "ap123456789012",
  "orgId": "or123456789012",
  "typesOutput": [
    {
      "path": "gen/flags.d.ts",
      "format": "react"
    }
  ]
}
```

| Option        | Description                                                                                                                                                                  | Default                                              |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| `$schema`     | Autocompletion for the config. `latest` can be replaced with a specific version.                                                                                             | "<https://unpkg.com/@reflag/cli@latest/schema.json>" |
| `baseUrl`     | Base URL for Reflag services.                                                                                                                                                | "<https://app.reflag.com>"                           |
| `apiUrl`      | API URL for Reflag services (overrides baseUrl for API calls).                                                                                                               | "<https://app.reflag.com/api>"                       |
| `appId`       | Your Reflag application ID.                                                                                                                                                  | Required                                             |
| `orgId`       | Restrict the CLI to one organization. Find the ID with `reflag apps list`.                                                                                                   | Optional                                             |
| `typesOutput` | Path(s) where TypeScript types will be generated. Can be a string or an array of objects with `path` and `format` properties. Available formats: `react`, `node`, and `vue`. | "gen/flags.ts" with format "react"                   |

You can override these settings using command-line options. With a personal login and no `orgId`, the CLI finds your configured `appId` across all organizations you can access. With `orgId` set, the CLI rejects apps outside that organization instead of switching to another one. This setting does not scope remote MCP connections.

## Commands <a href="#commands" id="commands"></a>

### `reflag init` <a href="#reflag-init" id="reflag-init"></a>

Initialize a new `reflag.config.json`. If you can access multiple organizations, the CLI asks you to choose an organization and then an app. Pass `--org-id` to pin an organization in the new config, or `--appId` to choose the app directly.

```bash
npx reflag init [--overwrite] [--org-id <org-id>] [--appId <app-id>]
```

Use `--overwrite` to replace an existing configuration.

### `reflag new [flagName]` <a href="#reflag-new-flagname" id="reflag-new-flagname"></a>

All-in-one command to get started quickly. This command combines `init`, flag creation, and type generation in a single step. Use this for the fastest way to get up and running with Reflag.

```bash
npx reflag new "My Flag" [--appId <app-id>] [--key my-flag] [--out gen/flags.ts] [--format react]
```

Options:

* `--key`: Specific key for the flag.
* `--appId`: App ID to use.
* `--out`: Path to generate TypeScript types.
* `--format`: Format of the generated types (react, node, or vue).

If you prefer more control over each step, you can use the individual commands (`init`, `flags create`, `flags types`) instead.

### `reflag login` <a href="#reflag-login" id="reflag-login"></a>

Authenticate with your Reflag account. This stores your credentials securely for subsequent operations.

```bash
npx reflag login
```

### `reflag logout` <a href="#reflag-logout" id="reflag-logout"></a>

Sign out from your Reflag account and remove stored credentials.

```bash
npx reflag logout
```

### `reflag flags` <a href="#reflag-flags" id="reflag-flags"></a>

Manage your Reflag flags with these subcommands:

#### `reflag flags create [flagName]` <a href="#reflag-flags-create-flagname" id="reflag-flags-create-flagname"></a>

Create a new flag in your Reflag app. The command guides you through the flag creation process with interactive prompts if options are not provided.

```bash
npx reflag flags create "My Flag" [--appId <app-id>] [--key my-flag]
```

Options:

* `--key`: Specific key for the flag.
* `--appId`: App ID to use. The app's organization determines the key format.

#### `reflag flags list` <a href="#reflag-flags-list" id="reflag-flags-list"></a>

List all flags for the current app. This helps you visualize what flags are available and their current configurations.

```bash
npx reflag flags list [--appId <app-id>]
```

Options:

* `--appId`: App ID to use.

#### `reflag flags types` <a href="#reflag-flags-types" id="reflag-flags-types"></a>

Generate TypeScript types for your flags. This ensures type safety when using Reflag flags in your TypeScript/JavaScript applications.

```bash
npx reflag flags types [--appId <app-id>] [--out gen/flags.ts] [--format react]
```

Options:

* `--appId`: App ID to use.
* `--out`: Path to generate TypeScript types.
* `--format`: Format of the generated types (react, node, or vue).

### `reflag apps list` <a href="#reflag-apps-list" id="reflag-apps-list"></a>

List available apps with their organization names and IDs. Without an organization filter, a personal login lists apps across all your organizations. An API key still lists only its own app.

```bash
npx reflag apps list [--org-id <org-id>]
```

## Global Options <a href="#global-options" id="global-options"></a>

These options can be used with any command:

* `--debug`: Enable debug mode for verbose output.
* `--base-url <url>`: Set the base URL for Reflag API.
* `--api-url <url>`: Set the API URL directly (overrides base URL).
* `--api-key <key>`: Reflag API key for non-interactive authentication.
* `--org-id <org-id>`: Restrict app discovery and commands to one organization. Overrides `orgId` in `reflag.config.json`.
* `--help`: Display help information for a command.

## AI-Assisted Development <a href="#ai-assisted-development" id="ai-assisted-development"></a>

Reflag provides powerful AI-assisted development capabilities through rules and Model Context Protocol (MCP). These features help your AI development tools better understand your flags and provide more accurate assistance.

### Reflag Rules (Recommended) <a href="#reflag-rules-recommended" id="reflag-rules-recommended"></a>

The `rules` command helps you set up AI-specific rules for your project. These rules enable AI tools to better understand how to work with Reflag flags and how they should be used in your codebase.

```bash
npx reflag rules [--format <cursor|copilot>] [--yes]
```

Options:

* `--format`: Format to add rules in:
  * `cursor`: Adds rules to `.cursor/rules/reflag.mdc` for Cursor IDE integration.
  * `copilot`: Adds rules to `.github/copilot-instructions.md` for GitHub Copilot integration.
* `--yes`: Skip confirmation prompts and overwrite existing files without asking.

This command adds rules to your project that provide AI tools with context about how to set up and use Reflag flags. For the copilot format, the rules are added to a dedicated section in the file, allowing you to maintain other copilot instructions alongside Reflag's rules.

## Model Context Protocol <a href="#model-context-protocol" id="model-context-protocol"></a>

Reflag hosts an MCP server at `https://app.reflag.com/api/mcp`. Connect your coding agent to it to create and manage flags from your editor or terminal. You sign in with your Reflag account, so you don't need an API key.

To add it to Claude Code, run:

```bash
claude mcp add --transport http Reflag https://app.reflag.com/api/mcp
```

Then start `claude` and run `/mcp` to sign in. For other clients, see the [MCP docs](https://docs.reflag.com/api/mcp).

### Setting up MCP with the CLI <a href="#setting-up-mcp-with-the-cli" id="setting-up-mcp-with-the-cli"></a>

The `mcp` command adds the Reflag MCP server to your editor's MCP configuration file.

```bash
npx reflag mcp [--editor <cursor|vscode>] [--scope <local|global>]
```

Options:

* `--editor`: The editor to configure: `cursor` ([Cursor](https://www.cursor.com/)) or `vscode` ([Visual Studio Code](https://code.visualstudio.com/)). Leave it out to choose interactively.
* `--scope`: `local` adds the server to your project (`.cursor/mcp.json` or `.vscode/mcp.json`). `global` adds it to your user configuration.

The command asks which Reflag app to connect to, then writes the configuration. Restart your editor to load the server.

## Using in CI/CD Pipelines <a href="#using-in-cicd-pipelines" id="using-in-cicd-pipelines"></a>

The Reflag CLI is designed to work seamlessly in CI/CD pipelines. For automated environments where interactive login is not possible, use the `--api-key` option or specify the API key in the `REFLAG_API_KEY` environment variable.

```bash
# Generate types in CI/CD
npx reflag apps list --api-key $REFLAG_API_KEY
```

**Important restrictions:**

* When using `--api-key`, the `login` and `logout` commands are disabled
* API keys bypass all interactive authentication flows
* API keys are bound to one app only. Commands such as `apps list` will only return the bound app
* Store API keys securely using your CI/CD platform's secret management

Example CI workflow:

```yaml
# GitHub Actions example
- name: Generate types
  run: npx reflag flags types --api-key ${{ secrets.REFLAG_API_KEY }}

# GitHub Actions example (using environment):
- name: Generate types (environment)
  run: npx reflag flags types
  env:
    REFLAG_API_KEY: ${{ secrets.REFLAG_CI_API_KEY }}
```

## Development <a href="#development" id="development"></a>

```bash
# Build the CLI
yarn build

# Test generated declarations against the built Node, React, and Vue SDKs
yarn test:generated-types

# Run the CLI locally
yarn reflag [command]

# Lint and format code
yarn lint
yarn format
```

## Requirements <a href="#requirements" id="requirements"></a>

* Node.js >=18.0.0

## License <a href="#license" id="license"></a>

> MIT License Copyright (c) 2025 Bucket ApS


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.reflag.com/api/cli.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
