# Derived tags

How `mt` tags each task with its root and the folders that contain it, without writing the tags to the file.

If your folder names already describe what a task is about, you don’t have to repeat it in tags. `mt` can tag each task from its file’s location: the name of its [task root](https://mlavrinenko.github.io/mindtape/concepts/index.md#a-task-is-a-file) and the folders between the root and the file. File a task under `api/tasks/auth/` and it matches `has_tag("auth")` with no tag written in it.

The examples below come from `examples/derived-tags/`, a repo with one task root per service.

## Turn it on

Derived tags are off by default. Set `enabled = true` under `[tasks.derive-tags]` to turn them on for every root:

```toml
# examples/derived-tags/.mindtape/config.toml: two roots, both deriving tags
[[tasks.roots]]
path = "api/tasks"
name = "api"

[[tasks.roots]]
path = "web/tasks"
name = "web"

[tasks.derive-tags]
enabled = true
collect = ["segments", "breadcrumbs"]
```

To turn them on for one root, set `derive-tags` on that root’s `[[tasks.roots]]` entry instead. It takes `true`, `false`, a glob or a list of globs. A glob limits derivation to the files whose path under the root matches it. A root without its own `derive-tags` follows `enabled`.

## Tags per task

These are the tags `mt` derives for each task in the example:

| File | Derived tags |
| --- | --- |
| `api/tasks/auth/sessions/reject-expired-sessions-on-refresh.typ` | `api`, `auth`, `sessions`, `auth:sessions` |
| `api/tasks/auth/throttle-failed-logins-per-ip.typ` | `api`, `auth` |
| `api/tasks/billing/retry-failed-invoice-payments.typ` | `api`, `billing` |
| `web/tasks/fix-contrast-in-dark-mode.typ` | `web` |

Every task gets its root’s tag: the root’s `name`, or the last folder of its `path` if it has no name. `collect` picks what the folders add:

- `segments`, the default, adds each folder as a tag: `auth`, `sessions`.
- `breadcrumbs` adds the path to each folder, joined with `separator` (`:` by default): `auth`, `auth:sessions`. With `breadcrumb-root = true`, each breadcrumb starts with the root’s tag: `api:auth`.

`mt` lowercases folder names and turns spaces and punctuation into `-`, so a folder named `Auth Flow` gives `auth-flow`. Set `slugify = false` to keep names as they are.

## Filter on them

A filter treats derived tags as tags:

```
$ mt ls 'has_tag("auth")'
SLUG#  STATUS  TITLE
2q0    todo    Throttle failed logins per IP
f1a    wip     Reject expired sessions on token refresh

2 of 4 tasks · your filter
```

`mt ls --json` lists them under `derived_tags`, separate from the tags written in the file. [Filters](https://mlavrinenko.github.io/mindtape/filters/index.md) covers `has_tag` and the rest of the language.

## How they behave

`mt` derives the tags each time it loads the tasks and never writes them to the file. Move a file to another folder and its tags change with it.

If `[tasks.tags] allowed` lists the permitted tags, `mt check` refuses an open task with a derived tag that isn’t on the list. Closed tasks aren’t checked, so you can drop a tag from the list without editing every closed task that has it. That’s `values-when = "!terminal"`, the default for tags. Set your own filter there to change which tasks the list applies to.
