> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# LaunchDarkly CLI commands

<View title="Developer" />

<View title="Federal docs" />

<View title="EU docs" />

This topic describes common commands and configuration options in the LaunchDarkly CLI.

The commands included here require you to authenticate yourself, either by logging in to LaunchDarkly or by setting or passing in an access token. To learn how, read [Authentication](/docs/home/getting-started/ldcli#authentication).

The CLI supports all LaunchDarkly resources, including [feature flags](/docs/home/flags/create), [experiments](/docs/home/experimentation), [metrics](/docs/home/metrics), and [environments](/docs/home/account/environment).

## View available commands

The majority of the LaunchDarkly CLI commands are resource commands. These commands provide direct access to [LaunchDarkly APIs](/docs/api).

To view available commands:

<CodeGroup>
  ```bash title="View common commands" lines wrap theme={null}
  ldcli
  ```

  ```bash title="View all commands" lines wrap theme={null}
  ldcli resources
  ```
</CodeGroup>

## Set input and output formats

For each LaunchDarkly CLI resource command, you can use command line arguments, or use your shell to provide an input file.

For example, here's how to create a flag using data from the command line:

<CodeGroup>
  ```bash title="Create a new flag using data from the command line" lines wrap theme={null}
  ldcli flags create --project default -d '{"name": "Example flag", "key": "example-flag"}'
  ```
</CodeGroup>

Here's how to create the same flag using data from a file:

<CodeGroup>
  ```bash title="Create a new flag using data from a file" lines wrap theme={null}
  ldcli flags create --project default -d "$(cat data.json)"
  ```

  ```json title="Example data.json file" lines wrap theme={null}
  {
    "name": "Example flag",
    "key": "example-flag"
  }
  ```
</CodeGroup>

By default, resource commands return a simplified plaintext output. For example, the default output message for creating the new flag in the example above is `Successfully created Example flag (example-flag)`.

To view the full JSON response from any resource command, use the `--output json` flag. Optionally, pipe the result through `jq` for improved formatting. Here's how:

<CodeGroup>
  ```bash title="Create a new flag and display extended, formatted output" lines wrap theme={null}
  ldcli flags create --project default -d '{"name": "Example flag", "key": "example-flag"}' --output json | jq
  ```
</CodeGroup>

If you prefer a particular output format, you can use the `config` command to set that preference:

<CodeGroup>
  ```bash title="Configure output format" lines wrap theme={null}
  ldcli config --set output json  # or plaintext
  ```
</CodeGroup>

You can also use the CLI to manage other resources, such as experiments.

### Example: create and manage experiments

You can use the CLI to create and manage experiments. For example, here's how to create an experiment using data from the command line:

<CodeGroup>
  ```bash title="Create a new experiment using data from the command line" lines wrap theme={null}
  ldcli experiments create --project default --environment production -d '{
    "name": "Checkout flow test",
    "key": "checkout-flow-test",
    "description": "Experiment comparing new and old checkout flow"
  }'
  ```
</CodeGroup>

Here's how to create the same experiment using data from a file:

<CodeGroup>
  ```bash title="Create a new experiment using data from a file" lines wrap theme={null}
  ldcli experiments create --project default --environment production -d "$(cat experiment.json)"
  ```

  ```json title="Example experiment.json file" lines wrap theme={null}
  {
    "name": "Checkout flow test",
    "key": "checkout-flow-test",
    "description": "Experiment comparing new and old checkout flow"
  }
  ```
</CodeGroup>

To view existing experiments, use:

<CodeGroup>
  ```bash title="View existing experiments" lines wrap theme={null}
  ldcli experiments list --project default --environment production
  ```
</CodeGroup>

## Access SDK credentials

You can access the default SDK credentials for a specific project and environment using the `environments` resource. You need different SDK credentials depending on which SDK you're working with. To learn more about SDK credentials, read [Keys and credentials](/docs/sdk/concepts/client-side-server-side#keys-and-credentials).

Here's how:

<CodeGroup>
  ```bash title="Get SDK key" lines wrap theme={null}
  # use the SDK key for authorization in server-side SDKs

  ldcli environments get --project <your project> --environment <your environment> | jq '.apiKey'
  ```

  ```bash title="Get mobile key" lines wrap theme={null}
  # use the mobile key for authorization in mobile SDKs

  ldcli environments get --project <your project> --environment <your environment> | jq '.mobileKey'
  ```

  ```bash title="Get client-side ID" lines wrap theme={null}
  # use the client-side ID for authorization in some client-side SDKs,
  # and to associate LaunchDarkly environments with CDN integrations in edge SDKs

  ldcli environments get --project <your project> --environment <your environment> | jq '._id'

  ```
</CodeGroup>

## Use `ldcli` for local development

The LaunchDarkly CLI includes a `dev-server` command that you can use to start a local server, retrieve flag values from a LaunchDarkly source environment, and update those flag values locally. This means you can test your code locally, without having to coordinate with other developers in your organization who are using the same LaunchDarkly source environment.

To learn more, use `ldcli dev-server --help` or read our guides, [Using the LaunchDarkly CLI for local testing](/docs/guides/flags/ldcli-dev-server) and [LaunchDarkly CLI dev-server reference](/docs/guides/flags/ldcli-dev-server-reference).

## Use `ldcli` for uploading sourcemaps

The LaunchDarkly CLI includes a `sourcemaps` command that you can use to upload JavaScript sourcemaps to LaunchDarkly. This means your sourcemaps are available when you access [error monitoring](/docs/home/observability/errors) in the LaunchDarkly UI. You must be using the [Observability plugin with the JavaScript SDK](/docs/sdk/observability/javascript) to use the error monitoring feature.

Here's how to upload your JavaScript sourcemap:

<CodeGroup>
  ```bash title="Upload JavaScript sourcemap" lines wrap theme={null}
  ldcli sourcemaps upload \
  --app-version <the current version of your deploy> \
  --path <directory where sourcemaps are located locally> \
  --base-path <directory where application code runs> \
  --project <project key>
  ```
</CodeGroup>

The `sourcemaps upload` command uploads a local version of your sourcemap to LaunchDarkly. To use the command, you must have generated [sourcemaps](https://developer.chrome.com/blog/sourcemaps/) for your project. Exactly how to do this depends on your target environment and JavaScript configuration. Bundlers such as [babel](https://babeljs.io/docs/en/options#source-map-options), [webpack](https://webpack.js.org/configuration/devtool/), [esbuild](https://esbuild.github.io/api/#sourcemap), and [rollup](https://rollupjs.org/guide/en/#outputoptions-object) all provide different ways to enable sourcemap generation. Refer to the documentation for your specific bundler to generate production-ready sourcemaps.

The `app-version` option takes a string that should match the [version](/docs/sdk/features/observability-config-client-side#versioning-sessions-and-errors) you include in the observability plugin options.

The `path` option defaults to `./build`. The command uploads any `.map` files in the directory specified here.

The `base-path` option ensures that LaunchDarkly stores the sourcemaps at an appropriate location corresponding to your application's deployment. For example, suppose your sourcemap file is in `./build/myApp` and that when you deploy your app, your code runs from `./dist/myApp`. You should provide `--path ./build/myApp --basePath ./dist/myApp`.

The `project` option is the LaunchDarkly [project key](/docs/home/account/project#project-keys).

If your sourcemap is inline, meaning it's already shipped as part of your application, then you do not need to upload anything to LaunchDarkly.

To learn more, use `ldcli sourcemaps --help`.

## Use `ldcli` for uploading symbols

The LaunchDarkly CLI includes a `symbols` command that you can use to upload mobile application symbol files to LaunchDarkly. When symbol files are available, LaunchDarkly can display readable stack traces on the [Errors](/docs/home/observability/errors) page for obfuscated, minified, or compiled builds. This feature requires that you use an [observability plugin](/docs/sdk/observability) for a supported mobile SDK.

<Note>
  **Comparing symbols to sourcemaps**

  The `symbols upload` command is distinct from `sourcemaps upload`, although both commands provide similar functionality. `symbols upload` uses a dedicated upload path built for large, multi-segment symbol files. It also keys each upload by a deterministic symbols ID rather than an application version. Always use `symbols upload` for mobile applications and `sourcemaps upload` for JavaScript web applications.
</Note>

Each platform requires a build configuration before you can upload symbols. To learn how to set up your build and generate symbol files, read [Symbolication for stack traces](/docs/sdk/features/observability-symbolication).

Here's how to upload symbols:

<CodeGroup>
  ```bash title="Upload mobile symbols" lines wrap theme={null}
  ldcli symbols upload \
  --type <platform> \
  --path <directory where symbol files are stored locally> \
  --project <project key>
  ```
</CodeGroup>

The `type` option identifies the mobile platform for which you are uploading symbols. LaunchDarkly supports `react-native`, `android`, `ios`, and `flutter`.

The `path` option points to the directory that contains your symbol files. For Android build environments, you can omit the `path` option if you run the `symbols upload` command from your project root.

`ldcli` automatically reads the symbols ID from your build environment, either from a `*.symbolsid` sidecar file (React Native) or from other files in the build directory. If the CLI cannot determine the symbols ID, use the `--symbols-id` option to provide it.

The `project` option is the LaunchDarkly [project key](/docs/home/account/project#project-keys).

To learn more, use `ldcli symbols --help`.

## Find additional documentation

LaunchDarkly provides the following additional documentation:

* For information on how to get started with the LaunchDarkly CLI, read [LaunchDarkly CLI](/docs/home/getting-started/ldcli).
* For details on how to use the LaunchDarkly CLI to perform local testing and development, read [Using the LaunchDarkly CLI for local testing](/docs/guides/flags/ldcli-dev-server) and [LaunchDarkly CLI dev-server reference](/docs/guides/flags/ldcli-dev-server-reference).

You can also use the `ldcli [command] --help` command to view usage information for all commands for the LaunchDarkly CLI.

To view and contribute to the LaunchDarkly CLI source code, or to file issues for our team, visit the [LaunchDarkly CLI GitHub repository](https://github.com/launchdarkly/ldcli).
