How to Configure Lifecycle Hooks
Automate tasks at lifecycle events with hako hooks.
This guide shows how to configure hooks that run automatically during environment lifecycle events.
Assumptions
- You have a working hako setup.
- You want to automate tasks like database migrations, seed data, or notifications.
Steps
-
Add hooks to hako.yml Define commands to run at specific lifecycle events in the
hookssection. Each hook is an array of commands.hooks: post_create: - npm install - npm run db:migrate post_start: - ./scripts/notify-slack.sh "Started {{branch}}" post_stop: - ./scripts/cleanup.sh -
Use template variables Hako provides variables you can use in your hook commands.
{{branch}}: The name of the current branch.{{port_base}}: The base port assigned to the environment.{{worktree_path}}: The absolute path to the worktree.
-
Test a hook manually Run a hook command without triggering the lifecycle event.
hako hook run post_create feature-branch -
Define custom hooks You can add any name to the
hookssection and run it manually.hooks: seed: npm run db:seedRun it with:
hako hook run seed feature-branch
Skip hooks
Use the --no-hooks flag to bypass hook execution for a specific command.
hako start feature-branch --no-hooksSee also
- Configuration Reference for the full list of template variables and hook execution details.
How to Use Hako with Monorepos
Configure hako to detect and run multiple workspace services in isolation.
How to Manage Secrets
Control how sensitive files are handled in worktrees.
ops.origin: Masakiro Corp.