Skip to content

Hooks

Hooks let you execute shell commands before and/or after Boilerplate renders your template files. This is useful for running formatters, validators, installers, or any other setup/teardown tasks.

hooks:
before:
- command: echo
args: ["Setting up..."]
after:
- command: terraform
args: ["fmt", "-recursive"]
FieldRequiredDescription
commandYesThe command to execute
argsNoList of arguments passed to the command
envNoMap of environment variables to set
dirNoWorking directory for the command
skipNoGo template expression — if true, the hook is skipped

Hook arguments and environment variables support Go template syntax:

hooks:
after:
- command: ./setup.sh
args:
- "{{ .ProjectName }}"
- "{{ .Environment }}"
env:
APP_NAME: "{{ .ProjectName }}"
DB_HOST: "{{ .DatabaseHost }}"

Use the skip field to conditionally skip a hook:

hooks:
after:
- command: docker
args: ["build", "-t", "{{ .ProjectName }}", "."]
skip: "{{ not .IncludeDocker }}"

By default, hooks run in the output folder. Use dir to specify a different working directory:

hooks:
after:
- command: npm
args: ["install"]
dir: "{{ outputFolder }}/frontend"

In interactive mode, Boilerplate prompts for confirmation before running each hook, showing the full command and arguments. The user can respond with:

ResponseBehavior
yRun this hook
aRun this and all subsequent hooks without prompting
nSkip this hook