Hako
How-to Guides

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

  1. Add hooks to hako.yml Define commands to run at specific lifecycle events in the hooks section. 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
  2. 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.
  3. Test a hook manually Run a hook command without triggering the lifecycle event.

    hako hook run post_create feature-branch
  4. Define custom hooks You can add any name to the hooks section and run it manually.

    hooks:
      seed: npm run db:seed

    Run 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-hooks

See also

ops.origin: Masakiro Corp.

On this page