query
Run GraphQL queries against your monorepo.
To quickly get the GraphQL schema, use the --schema flag.
When no arguments are passed, the command will open a GraphiQL playground to run queries.
When passed a query string, the command will run the query and output the results.
When passed a file path, the command will read the file and run the query.
Affected packages
By default, affectedPackages follows the Package Graph. An explicit package#task dependency does not create a package dependency.
With futureFlags.affectedUsingTaskInputs enabled, affectedPackages instead returns the unique packages that own affected tasks. It matches changed files against task inputs and follows the Task Graph to dependent tasks, including across enabled toolchains. Packages with no affected tasks are omitted. Unchanged prerequisites are not included merely because an affected task needs them.
This also applies to turbo query affected --packages. Use affectedTasks when you need the individual tasks rather than their package names, and withDependencies when you need their execution prerequisites.
Task planning
Select task metadata without collecting a full turbo run --dry=json summary:
You can also save the query as ci-plan.gql and run turbo query ci-plan.gql.
withDependencies
affectedTasks.withDependencies returns the tasks in the collection and their
transitive dependencies, deduplicated by task ID and sorted by package name, then
task name. length counts the unique tasks. An empty selection returns an empty
collection.
Each task appears once, even when several tasks share the same dependency. Select
only fullName beneath directDependencies to represent edges without repeating
each task's dependency tree. Unlike nesting allDependencies beneath every task,
this keeps the graph output proportional to its nodes and direct edges.
The collection includes non-executable transit and leaf dependencies, as well as
implicit native tasks and command overrides. command is null for tasks without
a command. The internal graph root is excluded; configured root tasks such as
//#lint are included when required.
This does not change affectedTasks.items: that collection retains its existing
affected-task selection and runnable dependency behavior. withDependencies
provides the complete dependency graph, including non-executable leaf nodes.
Environment patterns
globalEnvironment exposes globalEnv and globalPassThroughEnv as env and
passThroughEnv. Each task's environment exposes its configured env and
passThroughEnv after resolving Package Configurations, inheritance, and
$TURBO_EXTENDS$. These fields are also available on tasks outside an affected
query, such as package(name: "web") { tasks { items { environment { env } } } }.
Both fields return arrays, using [] when no patterns are configured. Global
patterns remain separate from task patterns. Wildcards and exclusions are
preserved: these are configuration patterns, not environment variable values,
expanded names, framework-inferred variables, or a complete process environment.
The query does not execute tasks or report cache hits. Unlike dry-run summaries, this selection does not include file-hash inventories.
Log files
Each task's logFile is the path to the log the task writes, relative to the
repository root, and matches the logFile that turbo run --dry=json reports
for that task. It is null when the task sets cache: false, because a task
that does not cache writes no log file.
Task hashes
Each task's hash is the hash the task contributes to cache lookups, and it
matches the hash that turbo run --dry=json reports for that task. Both read
the same inputs Turbo hashes before a run, so they agree for the same repository
state, environment, and configuration.
The hash is null when it cannot be known before the task runs, such as when a
task's inputs include files that its dependencies produce. hashReason then
explains why, matching the dry run's hashReason; it is null when the hash is
known up front.
Package task catalogue
package.tasks lists the package's native scripts and resolved Task Graph entries,
including configured tasks without a script and tasks with an explicit command.
Scriptless tasks can be entrypoints that depend on runnable tasks. Their script
is null, and their command is null unless a command is configured. Inherited
and shared configurations are resolved before listing tasks; scriptless tasks
excluded by extends: false are not included. Task names are deduplicated and sorted.
Task filters apply to this full catalogue, not only tasks with native scripts.
Tags
Packages and tasks expose a tags array, returning [] when no labels are configured. Package tags come from the package's loaded turbo.json and do not include task labels or inherit root package labels.
A task's tags contains its resolved task labels only, after configuration inheritance and $TURBO_EXTENDS$ composition. Order and duplicate labels are preserved, and the inheritance marker is not exposed. Select package { tags } to read its package labels separately.
Use has: { field: TAG, value: "label" } to filter by exact, case-sensitive membership. Package predicates match package labels only. Task predicates match either resolved task labels or package labels.
Task predicates support and, or, and not, as well as equal and notEqual on NAME, FULL_NAME, and EXPERIMENTAL_CI. EXPERIMENTAL_CI compares the resolved experimentalCI metadata as JSON: a boolean, an object, or null when unset. Objects use structural equality, not partial matching. An omitted predicate value is equivalent to explicit null. NAME and FULL_NAME equality still only matches strings, and TAG membership still only matches string labels. To select configured values other than false, combine notEqual: {field: EXPERIMENTAL_CI, value: null} and notEqual: {field: EXPERIMENTAL_CI, value: false} with and. This comparison does not interpret metadata contents or assign meaning to tags. The optional task filter is available on package task lists, task dependency/dependent lists, and withDependencies.
For affected tasks, pass taskFilter alongside the existing package filter or task-name tasks arguments:
Affected-task filters intersect before required prerequisites are added, so prerequisites may not carry the selected tag. Filters on dependency/dependent lists and withDependencies apply after traversal; they narrow the returned list without pruning traversal through non-matching tasks.
Shorthands
Shorthands generate GraphQL queries for common operations so you don't need to write them by hand. The JSON output is identical to what you'd get from a raw query.
ls
List packages in your monorepo. This is a shorthand for a packages query, equivalent to turbo ls.
With no arguments, lists all packages:
When passed package names, returns detailed information including tasks, dependencies, and dependents:
--filter (-F)
Use pnpm-style package selectors to narrow the package list. Same syntax as turbo run --filter.
--affected
Show only packages affected by changes between the current branch and main.
When combined with --filter, returns the intersection: only packages that are both affected and match the filter.
--output Experimental
Control the output format. Defaults to pretty (human-readable).
affected
Check which packages or tasks are affected by changes between two git refs.
The comparison requires everything between base and head to exist in the checkout. If the checkout is too shallow, then all packages will be considered changed.
For example, a blobless clone with full history (git clone --filter=blob:none, without --depth) gives turbo query affected the history it needs. With actions/checkout, set filter: blob:none and fetch-depth: 0.
With no flags, returns all affected tasks:
Task-level detection is more precise than package-level. A task is only reported as affected if its configured inputs match a changed file, or if an upstream task dependency is affected.
--tasks
Filter to specific task names. With no values, returns all affected tasks (same as bare turbo query affected).
--packages
Without --tasks, returns affected packages instead of tasks. With no values, returns all affected packages. With values, filters to the named packages.
When combined with --tasks, both filters apply (intersection) — only tasks matching the task name and belonging to the named packages are returned. This lets you check whether a specific task in a specific package changed:
Understanding affected-package reasons
The reason object explains why a package is included. Its __typename is
diagnostic output, not a turbo.json configuration value.
Most results are package-specific: a source file or a package's resolved dependencies changed. Some changes must be handled repository-wide because they change a shared input or Turborepo cannot safely determine a narrower scope. A repository-wide reason includes every package in the result.
This is related to, but distinct from, cache behavior. For example,
RootInternalDepChanged means that a workspace package used by the root
package changed. It selects every package when comparing Git revisions and
also changes the global hash, so every cacheable task misses cache. For the
complete cache model, see Caching.
Use the reason to diagnose why a package was selected:
Change-detection reason types
reason.__typename | Meaning |
|---|---|
FileChanged | A file in this package changed. |
LockfileChanged | The lockfile comparison found added or removed external dependencies for this package. |
ConservativeRootLockfileChanged | The root package is included after a lockfile change because it may depend on a workspace package. |
RootInternalDepChanged | A direct or transitive internal workspace dependency of the root package changed. All packages are selected and the global hash changes. |
GlobalDepsChanged | A file configured in globalDependencies changed. All packages are selected. |
DefaultGlobalFileChanged | turbo.json, turbo.jsonc, or the root .gitattributes changed. All packages are selected. |
LockfileChangeDetectionFailed | Turborepo could not safely compare the lockfile versions, so all packages are selected. |
LockfileChangedWithoutDetails | The lockfile changed but its previous content was unavailable, so all packages are selected. |
GitRefNotFound | The requested Git range could not be resolved, so all packages are selected. |
ScmError | Source-control change detection failed, so all packages are selected. |
Package-selection reason types
These types describe graph or filter expansion rather than a direct cache invalidation:
reason.__typename | Meaning |
|---|---|
DependencyChanged | This package was included because one of its dependencies changed. |
DependentChanged | This package was included because an included package depends on it. |
InFilteredDirectory | The package was selected by a directory filter. |
IncludedByFilter | The package was selected explicitly by a filter or package-qualified task. |
RootTask | A root task was included in the run. |
Run turbo query --schema to inspect the exact GraphQL schema supported by
your installed Turborepo version.
--base
Base git ref for comparison. Defaults to the auto-detected base (e.g. GITHUB_BASE_REF on GitHub Actions, or the merge-base with main).
Can also be set with the TURBO_SCM_BASE environment variable. When both are provided, --base takes precedence.
--head
Head git ref for comparison. Defaults to HEAD.
Can also be set with the TURBO_SCM_HEAD environment variable. When both are provided, --head takes precedence.
--exit-code
Exit with code 1 when affected packages or tasks are found, 0 when none are found, or 2 on errors. JSON output is still printed to stdout.
We recommend parsing the JSON output directly for most use cases since it gives you the reason for each change and lets you make more nuanced decisions. --exit-code is available as a shorthand for simple cases.
| Condition | Exit code |
|---|---|
| Nothing affected | 0 |
| Affected packages or tasks found | 1 |
| Query error | 2 |
Migrating from turbo-ignore
turbo-ignore is deprecated. turbo query affected is its replacement, with more precise task-level change detection that respects your inputs configuration.
Flag mapping
turbo-ignore | turbo query affected |
|---|---|
npx turbo-ignore my-app | turbo query affected --packages my-app |
--task build | --tasks build |
--fallback main | --base main |
Key differences
- More precise detection:
turbo-ignoreoperates at the package level.turbo query affectedoperates at the task input level, so a.mdchange won't trigger a rebuild if your task excludes*.mdfiles viainputs. - Structured output: The JSON output includes the reason each package or task is affected, which is useful for debugging and automation.
CI example
Flags
--schema
Output the GraphQL introspection schema. Cannot be used with a query argument.
--variables (-V)
Path to a JSON file containing query variables. Requires a query argument.