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

# Inputs and named inputs

> Reference for all Nx input types used to compute task cache hashes: filesets, environment variables, runtime commands, external dependencies, and named inputs.

When Nx computes the hash for a task, it considers the task's `inputs`. If any input changes, the cache is invalidated and the task re-runs. Inputs are defined on individual targets or in `namedInputs` for reuse across the workspace.

## Input types

Nx supports the following input types. Each can appear as an element in an `inputs` array.

### Fileset

File path globs that determine which files contribute to the cache hash. Patterns must be prefixed with `{projectRoot}` or `{workspaceRoot}`.

```json theme={null}
{
  "inputs": [
    "{projectRoot}/**/*",
    "{workspaceRoot}/.gitignore",
    "{projectRoot}/**/*.ts",
    "!{projectRoot}/**/*.spec.ts"
  ]
}
```

Or in object form using the `fileset` property:

```json theme={null}
{
  "inputs": [
    { "fileset": "{projectRoot}/**/*.ts" },
    { "fileset": "{projectRoot}/**/*.ts", "dependencies": true }
  ]
}
```

<ParamField body="fileset" type="string" required>
  A glob pattern prefixed with `{projectRoot}` or `{workspaceRoot}` that
  selects files to include in the hash.
</ParamField>

<ParamField body="dependencies" type="boolean">
  When `true`, the fileset is applied to each of the project's dependencies
  rather than the project itself.
</ParamField>

**Token behavior:**

* `{projectRoot}/**/*` — matches only files assigned to the specific project. Files in nested projects are excluded.
* `{workspaceRoot}/path/**/*` — matches all files in the workspace including nested projects.
* Prefix with `!` to exclude matching files from the hash.
* Prefix with `^` to apply the pattern to dependency projects (e.g. `"^{projectRoot}/**/*.ts"`).

<Warning>
  Directory paths used as inputs must include a trailing slash or glob pattern.
  `"{projectRoot}/src"` is treated as a file path and will match nothing.
  Use `"{projectRoot}/src/"` or `"{projectRoot}/src/**/*"` instead.

  This is different from `outputs`, which accept bare directory paths.
</Warning>

<Tip>
  Files listed in `.gitignore` are automatically excluded from inputs and never
  invalidate the cache.
</Tip>

### Environment variable

Include the value of an environment variable in the cache hash. If the variable's value changes, the task re-runs.

```json theme={null}
{
  "inputs": [
    { "env": "API_URL" },
    { "env": "NODE_ENV" }
  ]
}
```

<ParamField body="env" type="string" required>
  The name of the environment variable whose value is included in the hash.
</ParamField>

### Runtime command

Run a shell command and include its output in the cache hash. Use this to capture tool versions or other dynamic values.

```json theme={null}
{
  "inputs": [
    { "runtime": "node --version" },
    { "runtime": "go version" }
  ]
}
```

<ParamField body="runtime" type="string" required>
  A shell command whose stdout output is included in the hash. Avoid
  platform-specific scripts (`.sh`, `.bat`) — use cross-platform commands
  instead.
</ParamField>

### External dependencies

Include the resolved version of one or more npm packages in the cache hash. When a listed package is updated, the task re-runs.

```json theme={null}
{
  "inputs": [
    { "externalDependencies": ["jest", "@jest/globals"] },
    { "externalDependencies": ["eslint", "eslint-config-airbnb"] }
  ]
}
```

<ParamField body="externalDependencies" type="string[]" required>
  Package names to include in the hash. If this property is omitted from a
  target's inputs entirely, Nx hashes **all** external dependencies in the
  workspace (conservative default). Specifying at least one
  `externalDependencies` entry restricts hashing to only the listed packages.
</ParamField>

<Info>
  Nx plugins maintained by the Nx team automatically configure the correct
  `externalDependencies` for their executors. You only need to configure this
  manually for `nx:run-commands` targets and community plugins.
</Info>

### Outputs of dependent tasks

Consider files produced by dependency tasks as inputs to this task. Useful when a build task consumes type definitions generated upstream.

```json theme={null}
{
  "inputs": [
    { "dependentTasksOutputFiles": "**/*.d.ts" },
    { "dependentTasksOutputFiles": "**/*.d.ts", "transitive": true }
  ]
}
```

<ParamField body="dependentTasksOutputFiles" type="string" required>
  A glob pattern matched against output file paths (resolved from workspace
  root) of dependent tasks.
</ParamField>

<ParamField body="transitive" type="boolean">
  When `true`, also includes outputs from transitive dependencies (all tasks in
  the dependency chain), not only direct dependencies.
</ParamField>

### Working directory

Include the current working directory in the hash. Use this when task behavior depends on which directory the command is invoked from.

```json theme={null}
{
  "inputs": [
    { "workingDirectory": "relative" }
  ]
}
```

<ParamField body="workingDirectory" type="&#x22;relative&#x22; | &#x22;absolute&#x22;">
  `"relative"` hashes the path from workspace root to the current directory.
  `"absolute"` hashes the full filesystem path, which invalidates cache entries
  when the repository is cloned to a different location.
</ParamField>

## Named inputs

Named inputs are reusable sets of inputs defined in `namedInputs`. They act as variables you can reference by name in target `inputs` arrays instead of repeating the same definition everywhere.

### Defining named inputs

**Workspace level** — available to all projects:

```json nx.json theme={null}
{
  "namedInputs": {
    "default": ["{projectRoot}/**/*", "sharedGlobals"],
    "sharedGlobals": [],
    "production": ["default", "!{projectRoot}/**/*.spec.tsx"]
  }
}
```

**Project level** — overrides the workspace definition for this project only:

<Tabs>
  <Tab title="project.json">
    ```json project.json theme={null}
    {
      "namedInputs": {
        "production": ["default", "!{projectRoot}/jest.config.ts"]
      }
    }
    ```
  </Tab>

  <Tab title="package.json">
    ```json package.json theme={null}
    {
      "nx": {
        "namedInputs": {
          "production": ["default", "!{projectRoot}/jest.config.ts"]
        }
      }
    }
    ```
  </Tab>
</Tabs>

### Referencing named inputs

Named inputs are referenced by string in any `inputs` array:

```json project.json theme={null}
{
  "targets": {
    "test": {
      "inputs": [
        "default",
        "^production",
        "{projectRoot}/jest.config.js"
      ]
    }
  }
}
```

| Reference                                        | Meaning                                                          |
| ------------------------------------------------ | ---------------------------------------------------------------- |
| `"default"`                                      | Apply the `default` named input for the current project          |
| `"^production"`                                  | Apply the `production` named input for each dependency project   |
| `{ "input": "production", "projects": "mylib" }` | Apply the `production` named input defined in a specific project |

<Note>
  The `^` prefix behaves differently depending on what follows it:

  * `"^production"` — resolves the `production` named input per dependency
  * `"^{projectRoot}/**/*.ts"` — applies the fileset to each dependency project's root
</Note>

### Built-in named input conventions

Nx workspaces are generated with these named inputs by default:

```json nx.json theme={null}
{
  "namedInputs": {
    "default": ["{projectRoot}/**/*", "sharedGlobals"],
    "sharedGlobals": [],
    "production": ["default", "!{projectRoot}/jest.config.ts"]
  }
}
```

<AccordionGroup>
  <Accordion title="default">
    All files in the project root plus shared global inputs. Using `default` for
    a target means any file change in the project invalidates the cache — the
    safest choice.
  </Accordion>

  <Accordion title="sharedGlobals">
    Inputs that apply to every task in the workspace, such as the OS type or
    Node.js version. Empty by default; populate with `{ "runtime": "node     --version" }` style entries if needed.
  </Accordion>

  <Accordion title="production">
    A subset of `default` that excludes developer-only files (test files, lint
    configs, etc.) that don't affect production output. Define `production`
    inputs on each project so that test tasks on downstream projects are not
    invalidated when test files change.
  </Accordion>
</AccordionGroup>

## Configuring inputs for build vs. test

A common pattern is to use `production` inputs for builds and `default` inputs for tests, so that changes to test files don't invalidate downstream build caches:

```json nx.json theme={null}
{
  "targetDefaults": {
    "build": {
      "inputs": ["production", "^production"],
      "cache": true
    },
    "test": {
      "inputs": ["default", "^production"],
      "cache": true
    }
  }
}
```

With this setup:

* Changing a `*.spec.ts` file invalidates `test` (because `default` includes all files) but **not** `build` (because `production` excludes spec files).
* Changing a source file in a library invalidates both the library's `build` and any application's `build` that depends on it, because `^production` propagates the library's production inputs upstream.

<CardGroup cols={2}>
  <Card title="nx.json reference" href="/reference/nx-json">
    Define `namedInputs` at the workspace level.
  </Card>

  <Card title="Project configuration reference" href="/reference/project-configuration">
    Override `namedInputs` and set `inputs` per target.
  </Card>
</CardGroup>
