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

# LaunchDarkly CLI commands

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

> For the complete documentation index, see [llms.txt](/llms.txt). For the full documentation snapshot, see [llms-full.txt](/llms-full.txt).

## Overview

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](/home/getting-started/ldcli#authentication).

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

## View available commands

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

To view available commands:

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

  ```bash title="View all commands" 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" 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" theme={null}
      ldcli flags create --project default -d "$(cat data.json)"
  ```

  ```json title="Example data.json file" 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" 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" 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" 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" theme={null}
      ldcli experiments create --project default --environment production -d "$(cat experiment.json)"
  ```

  ```json title="Example experiment.json file" 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" theme={null}
      ldcli experiments list --project default --environment production
  ```
</CodeGroup>

## Access SDK credentials

You can access the 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](/sdk/concepts/client-side-server-side#keys).

Here's how:

<CodeGroup>
  ```bash title="Get SDK key" 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" 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" 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](/guides/flags/ldcli-dev-server) and [LaunchDarkly CLI dev-server reference](/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](/home/observability/errors) in the LaunchDarkly UI. You must be using the [Observability plugin with the JavaScript SDK](/sdk/observability/javascript) to use the error monitoring feature.

Here's how to upload your JavaScript sourcemap:

<CodeGroup>
  ```bash title="Upload JavaScript sourcemap" 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](/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](/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`.

## Find additional documentation

LaunchDarkly provides the following additional documentation:

* For information on how to get started with the LaunchDarkly CLI, read [LaunchDarkly CLI](/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](/guides/flags/ldcli-dev-server) and [LaunchDarkly CLI dev-server reference](/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).
