Skip to main content
The moon exec (or moon x, or moonx) command is a low-level command for executing tasks in the action pipeline. It provides fine-grained control over how tasks are selected and executed through command line options, making it ideal for custom workflows and advanced use cases. The moon check, moon ci, and moon run commands are all built on top of moon exec, so be sure to check those out for more user-friendly abstractions!

Usage

# Run `lint` in project `app`
moon exec app:lint
moonx app:lint

# Run `dev` in project `client` and `server`
moon exec client:dev server:dev
moonx client:dev server:dev

# Run `test` in all projects
moon exec :test
moonx :test

# Run `test` in the closest project, relative to the current working directory
moon exec '~:test'
moonx '~:test'

# Run `test` in all projects with tag `frontend`
moon exec '#frontend:test'
moonx '#frontend:test'

# Run `format` in the default project
moon exec format
moonx format

# Run `build` in projects matching the query
moon exec :build --query "language=javascript && projectLayer=library"

How it works

When you execute moon exec, it performs the following steps:
  1. Load changed files - Determines which files have changed based on VCS (git) information. This supports both local development and CI environments, with automatic detection of base and head revisions in CI.
  2. Build action graph - Constructs an action graph that includes all tasks and their dependencies. The graph can be filtered using queries and affected checks.
  3. Track affected tasks - When --affected is enabled, identifies which tasks are impacted by the changed files.
  4. Execute action pipeline - Runs all actions in the graph in topological order, respecting dependencies and running tasks in parallel where possible.

Arguments

targets
string[]
Task targets or project relative tasks to run. Supports multiple targets.
args
string[]
Additional arguments to pass through to the underlying command. Use -- to separate from exec options.
moon exec app:test -- --coverage --verbose

Options

Core options

--ci
boolean
Force enable CI mode. When enabled, moon will:
  • Automatically sync the workspace
  • Use CI-specific VCS revision detection
  • Apply stricter task validation
--force
boolean
default:false
Force run and bypass cache, ignore changed files, and skip affected checks. Useful for ensuring a clean run.
--interactive
boolean
default:false
Run the pipeline and tasks interactively. This enables stdin for tasks that require user input.
--summary
string
Print a summary of all actions that were run in the pipeline. Accepts a log level (e.g., info, debug).

Workflow options

--ignore-ci-checks
boolean
default:false
Ignore “run in CI” task checks. By default, tasks configured with runInCI will only run in CI environments.
--on-failure
enum
default:"bail"
When a task fails, either bail the pipeline, or continue executing.Options:
  • bail - Stop execution immediately (default)
  • continue - Continue running other tasks
moon exec :test --on-failure continue
--query
string
Filter tasks based on the result of a query. Uses MQL (moon query language) syntax.
moon exec :build --query "language=typescript && taskType=build"
--no-actions
boolean
default:false
Run the pipeline without sync and setup related actions. Skips workspace sync, toolchain setup, and dependency installation.

Affected options

These options control which tasks run based on changed files:
--affected
string
Only run tasks if affected by changed files. Optionally accepts:
  • local - Compare against local changes
  • remote - Compare against remote branch
moon exec :test --affected
moon exec :build --affected=remote
--base
string
Base branch, commit, or revision to compare against. Used to determine changed files.
moon exec :test --affected --base main
--head
string
Current branch, commit, or revision to compare with. Defaults to HEAD.
moon exec :test --affected --base main --head feature-branch
--include-relations
boolean
default:false
Include graph relations for affected checks, instead of just changed files. This will mark tasks as affected if their dependencies or dependents are affected.
--status
string[]
Filter changed files based on a changed status (e.g., added, modified, deleted).
moon exec :test --affected --status modified,added
--stdin
boolean
default:false
Accept changed files from stdin for affected checks. Useful for piping file lists.
git diff --name-only | moon exec :test --affected --stdin

Graph options

These options control how task dependencies are resolved:
--downstream
enum
default:"none"
Control the depth of downstream dependents to include.Options:
  • none - Don’t include dependents (default)
  • direct - Include direct dependents only
  • deep - Include all dependents recursively
Alias: --dependents
--upstream
enum
default:"deep"
Control the depth of upstream dependencies to include.Options:
  • none - Don’t include dependencies
  • direct - Include direct dependencies only
  • deep - Include all dependencies recursively (default)
Alias: --dependencies

Parallelism options

These options enable job partitioning for CI environments:
--job
number
Index of the current job (0-based). Used for splitting tasks across multiple CI jobs.
# Job 1 of 4
moon exec :test --job 0 --job-total 4
--job-total
number
Total amount of jobs to run. Must be used with --job.

Examples

Run affected tests only

Run tests only for projects affected by changes since the main branch:
moon exec :test --affected --base main

Continue on failure

Run all tests even if some fail:
moon exec :test --on-failure continue

Query-based execution

Run builds only for TypeScript libraries:
moon exec :build --query "language=typescript && projectLayer=library"

Job partitioning for CI

Split test execution across 4 CI jobs:
# In CI job 1
moon exec :test --ci --job 0 --job-total 4

# In CI job 2
moon exec :test --ci --job 1 --job-total 4

# And so on...

Interactive mode

Run a task that requires user input:
moon exec app:setup --interactive
  • moon run - High-level command for running tasks
  • moon ci - Run tasks in CI mode
  • moon check - Check tasks without running them

Build docs developers (and LLMs) love