---
title: Environment variables
description: Variables Melos reads, and the ones it sets for `melos exec` and exec scripts.
---
> ## Documentation Index
> Fetch the complete documentation index at: https://melos.invertase.dev/llms.txt
> Use this file to discover all available pages before exploring further.

These variables are available as environment variables in the commands run by
`melos exec` and in [`exec`](/configuration/scripts#exec) scripts:

```yaml
melos:
  scripts:
    echo:vars:
      exec: echo $MELOS_PACKAGE_NAME $MELOS_PACKAGE_VERSION $MELOS_PACKAGE_PATH
```

The variables that describe a package only exist when `melos exec` runs a
command in that package. When you call `melos exec` yourself, from a terminal or
from a [`run`](/configuration/scripts#run) script, a POSIX shell expands
`$MELOS_PACKAGE_NAME` to an empty string before Melos starts. Wrap the command
in single quotes, or escape the reference as `\$MELOS_PACKAGE_NAME`, so that the
shell started by `melos exec` expands it instead:

```bash
melos exec -- 'echo $MELOS_PACKAGE_NAME'
```

A command substitution in an `exec` script still runs once, before `melos exec`
starts, so the package variables are not defined inside of it. Escape the
substitution to run it in every package instead:

```yaml
melos:
  scripts:
    echo:directory:
      exec: echo \$(basename $MELOS_PACKAGE_PATH)
```

Melos also replaces `$MELOS_PACKAGE_NAME` in the paths passed to the
`--file-exists` package filter:

```bash
melos exec --file-exists='test_driver/$MELOS_PACKAGE_NAME_e2e.dart' -- echo hello
```

## Defined by Melos

### `MELOS_ROOT_PATH`

The path to the monorepo root

### `MELOS_PACKAGE_NAME`

The name of the package that's executing a script (when using `melos exec`)

### `MELOS_PACKAGE_VERSION`

The version of the package that's executing a script (when using `melos exec`)

### `MELOS_PACKAGE_PATH`

The path of the package that's executing a script (when using `melos exec`).

### `MELOS_PARENT_PACKAGE_NAME`

The name of the parent package of the example that's being executed in a
script (when using `melos exec`).

### `MELOS_PARENT_PACKAGE_VERSION`

The version of the parent package of the example that's being executed in a
script (when using `melos exec`).

### `MELOS_PARENT_PACKAGE_PATH`

The path of the parent package of the example that's being executed in a
script (when using `melos exec`).

### `MELOS_PUBLISH_DRY_RUN`

Whether the current publish is a dry run. This variable is `true` for a dry
run, which is the default, and `false` when the publish isn't a dry run
(`--no-dry-run`, or `dryRun: false` in
[`command/publish`](/configuration/overview#dryrun)). Melos sets it only for the
`dart pub publish` command that it runs in each package. Lifecycle hooks don't
receive it.

### `MELOS_SCRIPT`

The command that Melos is running, as a single string. Melos sets it for most
commands it starts, such as scripts, `melos exec` commands, and lifecycle
hooks, and runs the command through the shell with `eval "$MELOS_SCRIPT"`
(`%MELOS_SCRIPT%` on Windows). The individual `steps` of a script don't get
it.

### `MELOS_TERMINAL_WIDTH`

The width of the terminal, in columns, that Melos uses to wrap its output.
Melos sets this variable for the scripts that it runs. A nested `melos`
command then uses the same width as the outer one. You can also set it to
override the detected width. For example, on a continuous integration server
with no terminal, Melos falls back to 80 columns.

#### What is a 'parent package'

If an example package exists in a directory that is a child of another package,
then its parent is the 'parent package'. For example, the package
`firebase_auth` has an `example` directory that is also a package. When a
`melos exec` script runs in that `example` package, the parent package is
`firebase_auth`.

Note, this 'parent package' functionality only works when the directory of the
'child package' ends with `example`.

## User defined

### `MELOS_PACKAGES`

A comma-delimited list of package names that Melos focuses on. This
list acts as the `scope` global package filter, and it overrides the `scope`
for all filtering options in the `packageFilters` section.

Melos also sets this variable itself when a script declares
[`packageFilters`](/configuration/scripts#packagefilters). Nested `melos`
commands then stay scoped to the selected packages.

### `MELOS_SDK_PATH`

The path to the Dart/Flutter SDK to use. This environment variable has
precedence over the `sdkPath` option in the root `pubspec.yaml` file, but
the `--sdk-path` command line option overrides it.

### `MELOS_QUIET`

When `true`, Melos prints only warnings, errors, and the output of failed
commands. This environment variable has precedence over the
[`quiet`](/configuration/overview#quiet) option in the root `pubspec.yaml` file,
but the `--quiet` and `--no-quiet` command line options override it.

Melos also sets this variable itself for scripts it runs in quiet mode.
Nested `melos` commands then stay quiet too.

### `MELOS_RUN_UNCHANGED`

When `true`, [`melos exec`](/reference/commands/exec#--sources) runs the
command in every package, including packages whose sources did not change.
This setting has the same effect as the command line option `--run-unchanged`.

Melos also sets this variable itself for scripts run with
[`melos run --run-unchanged`](/reference/commands/run#--run-unchanged). It then
applies to every nested `melos exec` command.

### `MELOS_IGNORE_SOURCES`

When `true`, [`melos exec`](/reference/commands/exec#--ignore-sources) ignores
command sources. Commands run in every package without calculating or storing
checksums, for example on a continuous integration server. This environment
variable has precedence over the
[`ignoreSources`](/configuration/overview#ignoresources) option in the root
`pubspec.yaml` file, but the `--ignore-sources` and `--no-ignore-sources`
command line options override it.

Melos also sets this variable itself for the scripts that it runs with
[`melos run --ignore-sources`](/reference/commands/run#--ignore-sources).

### `MELOS_ANSI_STYLES`

When `true`, Melos styles its output with colors even if it does not write to
a terminal. This is useful on a continuous integration server, for example.
When `false`, Melos never styles the output.

Melos also sets this variable itself for the scripts that it runs. Melos
captures the output of those scripts. A nested `melos` command cannot detect
the terminal on its own and otherwise loses its colors.

Other tools that a script invokes do not write to a terminal either, so most
of them turn off their colors. They usually have an option to turn colors
back on, for example `flutter --color test` or `dart test --color`. Scripts that
need a real terminal can use
[`stdio: inherit`](/configuration/scripts#stdio).
