Skip to content

Add lifecycle hooks ​

Use hooks to prepare a ticket worktree, refresh it before a run or release its resources when work ends. Use an on-demand tool when the agent needs to choose when an application starts.

You need: a working conductor, its committed project configuration, and a project setup command that is safe to repeat. Choose that command from your repository's existing scripts.

  1. Merge one hook into .bakers/project.config.js, keeping the other settings:

    js
    hooks: { after_create: 'sh .bakers/scripts/prepare.sh' },

    Supply .bakers/scripts/prepare.sh; the example does not create it. See the Node.js example for a locked dependency install, or Compose for service setup and scoped cleanup.

  2. Run the command twice in a disposable worktree. It should prepare missing resources and preserve resources that are already ready. Keep long-running servers out of blocking setup commands.

  3. Run bakers config check --scope project, then dispatch a small ticket. Check the actual files/services and .bakers/log.txt for hook failures.

Done when: the ticket worktree has the required environment and repeat setup is safe. A valid config or a started agent alone does not establish readiness.

Hooks run worktree code with the conductor user's permissions, outside the agent sandbox. Failures are logged and work continues; put required checks in WORKFLOW.md. Cleanup must affect only this worktree and preserve needed data.

When each hook runs ​

The six-hook catalog defines preparation, run, cleanup, freeze and resume timing, including retries and reuse.

Environment ​

The environment reference lists injected variables. The after_done shell command receives no injected ticket variables; use a validated worktree-local identity for cleanup.

Failure behavior ​

See failure and retry behavior before relying on setup or cleanup.

Provision on an agent's request ​

Configure provision_up when checks need a running environment. It is an explicit tool call, not an automatic lifecycle event. Your script owns reuse, readiness and the returned URL. provision_exec runs a configured command with the agent's arguments, for example in a site container.

Add a listener from an addon ​

Addon authors use the existing hook listener contract.

Clean up a preview ​

after_done: 'bakers ports down mailpit' closes a tunnel opened for that service. It does not stop the application. Ports owns service sharing and tunnel cleanup.

Protect host-executed files ​

Under an isolating runtime, the host runs only code from protected paths: .bakers/ and the project's runtime.read_only list. Every lifecycle hook and every provision_up or provision_exec command must begin with a script inside one of them: the command's first word, or the word after bash, sh or node.

js
hooks: { before_run: 'bash .bakers/provision.sh deps' },

Otherwise the config fails to load with an error naming the hook; bakers config check reports it offline, as well as a runtime.read_only path that does not exist. Only that entry point is checked.

A bare host binary such as ddev …, bash ddev … or npm run … is refused even when .ddev is protected: the binary itself may execute files the run can write, such as package.json scripts or build steps a tool reads from repository config. Call it from a wrapper script under .bakers/ that runs fixed commands. For DDEV:

sh
#!/usr/bin/env bash
# .bakers/ddev-init.sh
set -euo pipefail
cd "$BAKERS_WORKTREE_PATH"
ddev start
js
runtime: { read_only: ['.ddev'] },
hooks: { after_create: 'bash .bakers/ddev-init.sh' },

The script should call only protected code and run anything the run can write, such as dependency installs and builds, in a container. Host scripts read BAKERS_WORKTREE_PATH and BAKERS_RUNTIME_ISOLATES instead of asking Git: on the host an isolated workspace's .git is only a stub, without the run's commits; under herdr it answers as the parent repository.

A maintainer makes and delivers changes to protected files outside the isolated run. The host runtime has no such check and no such protection.