---
title: Targets
---

import VersionLabel from '@site/src/components/Docs/VersionLabel';

A target is a compound identifier that pairs a [scope](#common-scopes) to a [task](./task),
separated by a `:`, in the format of `scope:task`.

Targets are used by terminal commands...

```shell
$ moon run designSystem:build
```

And configurations for declaring cross-project or cross-task dependencies.

```yaml
tasks:
  build:
    command: 'webpack'
    deps:
      - 'designSystem:build'
```

## Common scopes

These scopes are available for both running targets and configuring them.

### By project

The most common scope is the project scope, which requires the name of a project, as defined in
[`.moon/workspace.*`](../config/workspace). When paired with a task name, it will run a specific
task from that project.

```shell
# Run `lint` in project `app`
$ moon run app:lint
```

### By project tag<VersionLabel version="1.4.0" />

Another way to target projects is with the tag scope, which requires the name of a tag prefixed with
`#`, and will run a specific task in all projects with that tag.

```shell
# Run `lint` in projects with the tag `frontend`
$ moon run '#frontend:lint'
```

:::caution

Because `#` is a special character in the terminal (is considered a comment), you'll need to wrap
the target in quotes, or escape it like so `\#`.

:::

### By task tag<VersionLabel version="2.3.0" />

Targets can also be scoped by task tags, which is similar to the project tag scope, but instead of
targeting projects with a specific tag, it targets tasks with a specific tag, regardless of the
project. This allows you to run specific tasks across different projects based on their tags.

```shell
# Run `#quality` tagged tasks in the app project
$ moon run app:#quality
```

## Run scopes

These scopes are only available on the command line when running tasks with `moon run` or `moon ci`.

### All projects

For situations where you want to run a specific target in _all_ projects, for example `lint`ing, you
can utilize the all projects scope by omitting the project name from the target: `:lint`.

```shell
# Run `lint` in all projects
$ moon run :lint
```

### Closest project `~`<VersionLabel version="1.33.0" />

If you are within a project folder, or an arbitrarily nested folder, and want to run a task in the
closest project (traversing upwards), the `~` scope can be used.

```shell
# Run `lint` in the closest project
$ moon run '~:lint'
```

:::caution

Because `~` is a special character in the terminal (tilde expansion), you'll need to wrap the target
in quotes, or escape it like so `\~`.

:::

## Config scopes

These scopes are only available when configuring a task.

### Dependencies `^`

When you want to include a reference for each project [that's depended on](./project#dependencies),
you can utilize the `^` scope. This will be expanded to _all_ depended on projects. If you do not
want all projects, then you'll need to explicitly define them.

```yaml title="moon.yml"
dependsOn:
  - 'apiClients'
  - 'designSystem'

# Configured as
tasks:
  build:
    command: 'webpack'
    deps:
      - '^:build'

# Resolves to
tasks:
  build:
    command: 'webpack'
    deps:
      - 'apiClients:build'
      - 'designSystem:build'
```

### Owning project `~`

When referring to another task within the current project, you can utilize the `~` scope, or omit
the `~:` prefix altogether, which will be expanded to the current project's name. This is useful for
situations where the name is unknown, for example, when configuring
[`.moon/tasks/**/*`](../config/tasks), or if you just want a shortcut!

```yaml title=".moon/tasks/all.yml"
# Configured as
tasks:
  lint:
    command: 'eslint'
    deps:
      - '~:typecheck'
      # OR
      - 'typecheck'
  typecheck:
    command: 'tsc'

# Resolves to (assuming project is "foo")
tasks:
  lint:
    command: 'eslint'
    deps:
      - 'foo:typecheck'
  typecheck:
    command: 'tsc'
```
