📦 Taskfile, a Makefile I can actually read
It started with a few Raspberry Pis. It ended as a homelab. Along the way, I taught myself Ansible, because I wanted a reproducible setup. Version one was me, SSH and a lot of copy-paste. That doesn’t scale, it just piles up. The service wishlist kept growing, because homelabbing is the new build-your-own-miniature-train hobby of millennials. Scripts, roles, playbooks. Soon I had more ways to run things than I could remember. Since day 1, Claude Code has helped me manage this, but I didn’t want an AI as my personal command history.
The notorious package.json scripts
In web development, it is common to set shortcuts in the package.json scripts. I had my share too: npm run dev, npm run build, npm run deploy. Oh boy, have I seen some wild things people do with these npm scripts. Curious as I am, I always looked inside the package.json of an open source project on GitHub first. It inspired me to automate every single bit of a web project too. I’ve written every webpack config from scratch since 2015 (if you were there, you know how it felt), so automation was already a hobby. The real upgrade came later. pnpm monorepos can call scripts recursively. On an enterprise project that runs a prepare step in each subpackage, that’s when you make tea. And maybe bake a cake.
Long story short, what is Taskfile?
Taskfile is a task runner written in Go. Think of it as a remote control for your project. Unlike npm scripts, it is language-agnostic. I have also seen web projects using a Makefile, and I wrote my share of them back in my C/C++ days, with CMake on top. Basically a Makefile, but readable. I still need a translator for Make sometimes.
A simple Taskfile looks like this:
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: '3'
tasks:
install:
desc: "Install project dependencies"
cmd: pnpm install --prefer-offline --frozen-lockfile --ignore-scripts
dev:
desc: "Start the dev server"
cmd: pnpm dev
build:
desc: "Build the app"
cmds:
- task: install
- pnpm build
task --list
task install
task dev
The schema comment gives completion and validation in the editor.
Each task has a name, a description and a command. Long, scary commands get a short, friendly name, and it is much more readable than a package.json script. I still use the latter for small to mid-sized web projects.
Why it clicked for me
When working with Ansible, Terraform, deployment scripts and other DevOps topics, my head felt like a browser with 40 tabs open. Specifically, I wanted to deploy a small project and didn’t want to bring the Ansible cannon to one tiny VPS. I was using some shell scripts and cloud-init, but for clarity, I started writing a Taskfile where I put all the commands I needed: provision a server, install scripts, connect via SSH, deploy the app. Four tasks. That’s it.
Here is an example:
version: '3'
vars:
SERVER_NAME: app-01
SERVER_USER: root
SERVER_HOST:
sh: hcloud server ip {{.SERVER_NAME}} 2>/dev/null || true
tasks:
server:provision:
desc: "Create the server on Hetzner Cloud with cloud-init"
status:
- hcloud server describe {{.SERVER_NAME}}
cmd: >
hcloud server create
--name {{.SERVER_NAME}}
--type cpx22
--image ubuntu-24.04
--location nbg1
--ssh-key my-key
--user-data-from-file cloud-init.yml
server:ssh:
desc: "Connect to the server"
interactive: true
cmd: ssh {{.SERVER_USER}}@{{.SERVER_HOST}}
server:setup:
desc: "Copy scripts and install everything"
cmds:
- ssh {{.SERVER_USER}}@{{.SERVER_HOST}} "mkdir -p /opt/infra"
- scp -r . {{.SERVER_USER}}@{{.SERVER_HOST}}:/opt/infra/
- ssh {{.SERVER_USER}}@{{.SERVER_HOST}} "cd /opt/infra && bash scripts/setup.sh"
app:deploy:
desc: "Pull and restart the app"
cmd: ssh {{.SERVER_USER}}@{{.SERVER_HOST}} "cd /opt/app && git pull --ff-only && docker compose up -d --build"
Orchestration
Later, what really made this Taskfile take off was its orchestration ability. In my homelab project, I have multiple hosts, but they can all run the deploy playbook or different roles/services, and I have a lot of services to run. So I wrote one Taskfile for all hosts and include it once per machine (named after fruit, because nobody remembers IPs).
task apple:ssh
task banana:ssh
task banana:playbook SERVICE=grafana ACTION=update
The root Taskfile includes the same file once per host:
# Taskfile.yml
version: '3'
includes:
apple:
taskfile: ./hosts/Taskfile.yml
vars: { HOST: apple }
banana:
taskfile: ./hosts/Taskfile.yml
vars: { HOST: banana }
Each include gets its own namespace, so apple: and banana: point to the same tasks, only with a different HOST. The shared file doesn’t know which machine it runs for. It only uses {{.HOST}}, and requires stops the task early when I forget SERVICE or ACTION. A new Pi is three more lines in the root Taskfile.
# hosts/Taskfile.yml
version: '3'
tasks:
ssh:
desc: "SSH into the host"
interactive: true
cmd: ssh {{.HOST}}
monitoring:
desc: "Manage a monitoring service (SERVICE=grafana ACTION=update)"
requires:
vars: [SERVICE, ACTION]
cmd: ansible-playbook playbooks/monitoring.yml -l {{.HOST}} -e service={{.SERVICE}} -e action={{.ACTION}}
Use cases I keep coming back to
My pnpm monorepos were next on the list. Then came a Bun monorepo. Bun has workspace filters, but I never got them to behave. Maybe it’s broken, maybe it’s me. Taskfile ran every package without complaining.
Remember the tea break? Turborepo could save it, but I’d rather skip another dependency when my task runner already caches with sources and generates.
For example, on a Nuxt project with a prepare step:
sourcesandgenerateslet Task skip a step when its inputs did not change.--ignore-scriptsstops each package’spostinstallfrom runningnuxt prepareon every install, so prepare only runs when the Nuxt config changed.
install:
desc: "Install dependencies when a lockfile or package.json changed"
sources: [package.json, pnpm-lock.yaml, "apps/*/package.json", "packages/*/package.json"]
generates: [node_modules/.modules.yaml]
cmd: pnpm install --ignore-scripts
web:prepare:
desc: "Generate the .nuxt types when the config changed"
dir: apps/web
deps: [install]
sources: [nuxt.config.ts, package.json]
generates: [.nuxt/tsconfig.json]
cmd: pnpm nuxi prepare
Need the API, the frontend and the DB GUI at once? One command:
dev:
desc: "Start API, web and DB studio in parallel"
deps: [api:dev, web:dev, db:studio]
api:dev:
dir: apps/api
cmd: pnpm dev
web:dev:
dir: apps/web
deps: [web:prepare]
cmd: pnpm dev
Everything in
depsruns in parallel, and one Ctrl+C stops all of them. A CLI with interactive hotkeys can swallow Ctrl+C for every task in the group, so turn its hotkeys off when it runs insidedeps.
You can run a precondition before you run the main script:
deploy:
desc: "Build and start the stack"
preconditions:
- sh: test -f .env
msg: "Missing .env, copy .env.example first"
- sh: docker info > /dev/null 2>&1
msg: "Docker is not running"
cmd: docker compose up -d --build
A failed precondition stops the task with your message. Use
status:when a task should be skipped instead.
And for anything future you might regret, ask first:
clean:
desc: "Remove every node_modules and build output"
prompt: "This deletes all node_modules, .nuxt and .output folders. Continue?"
cmd: pnpm dlx rimraf --glob "**/node_modules" "**/.nuxt" "**/.output"
Why I’m sticking with it
I also looked into alternatives. For example, there is just with its justfile, which is closer to a Makefile. Its syntax never clicked for me, but plenty of people love it. I’m staying with Taskfile. It automates pnpm monorepos, Ansible projects, deployments and linting. Together with fzf-tab, it is really handy. And if you write a skill for your agent, it gets a menu instead of a blank terminal. Much less freestyle.
I still forget commands. But now I only need to remember one word: task.