Skip to main content

Including Other Taskfiles

Use the includes keyword to include other Taskfiles in your main Taskfile. This is useful for modularizing and reusing tasks across different projects or directories. Given this structure:
./
├── app/
│   └── Taskfile.yml
├── Taskfile.yml
└── docker-task.yml
version: '3'
tasks:
  get-app-version:
    desc: "Get the version of the app"
    cmds:
      - 'echo "App version is 1.0.0"'
Taskfile.yml
version: '3'

includes:
  app: ./app          # looks for ./app/Taskfile.yml
  docker: ./docker-task.yml
Run included tasks using <namespace>:<task>:
Demo and output
ubuntu@touted-mite:~$ task app:get-app-version
task: [app:get-app-version] echo "App version is 1.0.0"
App version is 1.0.0

ubuntu@touted-mite:~$ task docker:get-docker-version
task: [docker:get-docker-version] docker --version
Docker version 28.1.1, build 4eba377

Using Included Tasks Inside Other Tasks

You can call tasks from included Taskfiles inside your own tasks:
Taskfile.yml
version: '3'
includes:
  app: ./app
  docker: ./docker-task.yml
tasks:
  app:build:
    cmds:
      - task: docker:build-docker-image
        vars:
          SRC_DIR: "app"
          NAME: "my-app"

OS-Specific Taskfiles

Include Taskfiles based on the operating system using the {{OS}} special variable:
Taskfile.yml
version: '3'
includes:
  build: ./Taskfile_{{OS}}.yml

Run Included Taskfile in a Different Directory

By default, included Taskfiles run in the current directory. Use the dir keyword to run them in a different directory:
app/Taskfile.yml
version: '3'
tasks:
  get-app-version:
    desc: "Get the version of the app"
    cmds:
      - 'echo "App version is 1.0.0"'
      - pwd
Taskfile.yml
version: '3'
includes:
  app:
    taskfile: ./app/Taskfile.yml
    dir: ./app1 # runs the included Taskfile in ./app1
If the specified directory does not exist, Task will create it.
Demo and output
ubuntu@touted-mite:~$ task app:get-app-version
task: [app:get-app-version] echo "App version is 1.0.0"
App version is 1.0.0
task: [app:get-app-version] pwd
/home/ubuntu/app1

Optional Includes

Allow including Taskfiles that may not exist without causing an error:
Taskfile.yml
version: '3'
includes:
  missing:
    taskfile: ./missing/Taskfile.yml
    optional: true
tasks:
  test:
    cmds:
      - echo "This task runs even if the included Taskfile is missing"

Internal Includes

Mark an include as internal to hide its tasks from the public task list:
Taskfile.yml
version: '3'
includes:
  app:
    taskfile: ./app/Taskfile.yml
    internal: true
tasks:
  test:
    cmds:
      - echo "Hello World"
Demo and output
ubuntu@touted-mite:~$ task --list-all
task: Available tasks for this project:
* test:

ubuntu@touted-mite:~$ task app:get-app-version
task: Task "app:get-app-version" is internal

Flatten Includes

Make sure tasks do not share names across included Taskfiles when using flatten, otherwise an error will occur.
Use flatten: true to include tasks without requiring the namespace prefix:
Taskfile.yml
version: '3'
includes:
  app:
    taskfile: ./app/Taskfile.yml
    flatten: true
tasks:
  test:
    cmds:
      - echo "Hello World"
      - task: get-app-version # no namespace needed
Demo and output
ubuntu@touted-mite:~$ task -a
task: Available tasks for this project:
* get-app-version:    Get the version of the app
* test:

ubuntu@touted-mite:~$ task get-app-version
task: [get-app-version] echo "App version is 1.0.0"
App version is 1.0.0

Exclude Tasks from Includes

Use excludes to prevent specific tasks from being included:
Taskfile.yml
version: '3'
includes:
  app:
    taskfile: ./app/Taskfile.yml
    excludes: [get-secret]
Demo and output
ubuntu@touted-mite:~$ task -a
task: Available tasks for this project:
* app:get-app-version:    Get the version of the app

Pass Variables to Included Taskfiles

Use vars to pass variables to the included Taskfile:
Taskfile.yml
version: '3'
includes:
  app:
    taskfile: ./app/Taskfile.yml
    vars:
      NAME: "my-app"
      SRC_DIR: "app"

Namespace Aliases (Shortform)

Create short aliases for namespaces using the aliases keyword:
Taskfile.yml
version: '3'
includes:
  app:
    taskfile: ./app/Taskfile.yml
    aliases: [a]
Demo and output
ubuntu@touted-mite:~$ task a
a:get-app-version    a:get-secret    app:get-app-version    app:get-secret

Build docs developers (and LLMs) love