> ## Documentation Index
> Fetch the complete documentation index at: https://errand.nuvrel.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Multiple files

> Split a playbook across several `.ern` files.

Errand loads all `.ern` files in the target directory and merges them into one playbook. You can use this to split a large playbook into focused files.

## How it works

When you run `errand run`, Errand reads every `.ern` file in the directory (non-recursively) and merges their blocks as if they were written in a single file. Variables, computed values, and tasks from different files can reference each other without any imports.

## Example

Organize a project by concern, one file per area:

<Tree>
  <Tree.Folder name="project" defaultOpen>
    <Tree.File name="variables.ern" />

    <Tree.File name="test.ern" />

    <Tree.File name="build.ern" />

    <Tree.File name="deploy.ern" />
  </Tree.Folder>
</Tree>

**variables.ern**: shared inputs and computed values used by all other files:

```hcl theme={null}
variable "app" {
  type    = string
  default = "api"
}

variable "version" {
  type = string
}

computed "image" {
  expression = "${env("CI_REGISTRY", "registry.example.com")}/${var.app}:${var.version}"
}
```

**test.ern**

```hcl theme={null}
task "test" {
  description = "Run the test suite"
  commands    = ["go test ./..."]
}
```

**build.ern**: references `task.test` from `test.ern` and `computed.image` from `variables.ern`:

```hcl theme={null}
task "build" {
  description = "Build and push the Docker image"
  depends_on  = [task.test]
  commands = [
    "docker build -t ${computed.image} .",
    "docker push ${computed.image}",
  ]
}
```

**deploy.ern**

```hcl theme={null}
task "deploy" {
  description = "Deploy to the cluster"
  depends_on  = [task.build]
  commands    = ["kubectl set image deployment/${var.app} ${var.app}=${computed.image}"]
}

task "default" {
  depends_on = [task.deploy]
  commands   = []
}
```

Run from the project directory:

```bash theme={null}
errand run --var version=1.4.2
```

## Pointing to a specific directory

By default, Errand loads from the current directory. Use `--dir` to specify another:

```bash theme={null}
errand run --dir ./ops deploy --var version=1.4.2
```

## Notes

* Block names must be unique across all files. Declaring `task "build"` in two files is an error.
* You can have at most one `errand` block across all files in the directory.
* Files in subdirectories are ignored. Only `.ern` files in the target directory are loaded.
* Errand does not sort or prioritize files by name. All files are merged before any block is evaluated.
