Write an executor or a workspace
A conductor runs each ticket in its own Git worktree, and each run's agent in a terminal. Two addon kinds do that work: the workspace owns the worktree, and the executor hosts the agent's terminal. This page explains what each one must do and how to write your own. Conductor slots lists the shipped ones and how a config picks them.
What they do
| Slot | Job | Interface |
|---|---|---|
| Workspace | Create or reuse the ticket's worktree; remove it when the ticket is done | BbWorkspace: ensure, remove |
| Executor | Start the agent's terminal in that worktree, stop it, clean it up; optionally show a fresh worktree in the tool | BbExecutor: capabilities, startRun, stopRun, cleanupRun, optional openWorkspace, closeWorkspace and sweepWorkspaces |
| Conductor | Call both, and run every lifecycle hook (after_create, before_run, after_run, after_done) itself | — |
The two never call each other. The conductor hands the worktree path and the branch from the workspace to the executor, so any executor runs on any workspace's worktree. One conductor has exactly one executor and one workspace.
When the conductor calls them
A dispatch:
workspace.ensure(identifier, branch, baseRef)returns the path and whether it wascreated.- Hook
after_create, on a created worktree or one with no recorded successfulafter_create. executor.openWorkspace(path, ctx), only when the worktree was created.- Hook
before_run. executor.cleanupRun(branch, runId), to clear a leftover of the same run.executor.startRun(input).
The run ends when the server marks it done or cancelled. The conductor then calls stopRun, stores the transcript, runs after_run, and calls cleanupRun. For an executor that is not persistent, it skips stopRun and that cleanupRun.
When the ticket is done, the reaper runs after_done, then workspace.remove(branch, worktreePath). After a removed or already_absent teardown it calls executor.closeWorkspace(branch, worktreePath) for a persistent executor. Once per conductor process it also calls executor.sweepWorkspaces().
Write an executor
Import BbExecutor, ExecutorPlugin and SpawnRunInput from @bakers-build/conductor/contract. A plugin has kind: 'executor', an id, requiredModules and an async createExecutor(config, deps) factory. The factory returns an executor implementing the methods below.
The new client tutorial implements an adapter with two client CLI commands: start and close. For a shipped implementation, inspect bakers-cli/addons/herdr-core/src/index.ts. A detached process with empty cleanup methods is not a complete executor: it would leave agents running and cannot recover its terminals after restart.
The rules each method must keep:
startRun(input)runsinput.commandininput.workspacePathwithinput.envadded, and returns once the agent has started.commandis the agent command the conductor built, prompt included. Throw when the launch fails: the run is then marked failed. Keepenvout of argv and logs, since it carries tokens; the herdr executors write it to a 0600 launch script.capabilities().persistentistruewhen the agent lives on in a hosted terminal afterstartRunreturns. It decides only whether the finalising pass callsstopRunandcleanupRun.cleanupRun(branch, runId)removes only that run's terminal. Another run of the same ticket may still be open. It is also called before everystartRun, so a missing terminal is a quiet no-op. Log failures; never throw.stopRun(branch)signals the agent to stop, before the transcript is read. It must not delete the transcript. Most executors leave it empty and letcleanupRunend the terminal.openWorkspace(path, ctx)is optional. Add it when your tool has a window or layout to show for a new worktree. The worktree may come from any workspace, so find it bypath, not by your own records. Log failures; never throw.closeWorkspace(branch, worktreePath?)is optional. Add it when your tool keeps a window or workspace per branch that the workspace addon does not remove. Close only what holds nothing but your own terminals; report anything else in the log and returntrue. Returnfalsewhen closing is not safe yet, for example a focused window with nowhere to move focus: the ticket stays on the reap list and the next reap retries. A throw is logged and does not hold up the cleanup.sweepWorkspaces()is optional. It closes windows left over by earlier versions, whose tickets are already cleaned up. The conductor runs it on the first reap of each process and again while it returnsfalse. herdr closes a workspace whose checkout under.bakers-worktrees/is gone and that holds only the open-layout tab.- An executor never creates, changes or removes a worktree, and runs no hooks.
Label each terminal with the branch and run id when you start it, so cleanupRun can find it again without any state of its own; the conductor may have restarted in between. herdr-core does this with hc labels.
Write a workspace
Import BbWorkspace, EnsuredWorkspace and WorkspacePlugin from @bakers-build/conductor/contract. A workspace plugin has kind: 'worktree', an id, requiredModules and an async createWorkspace(config, deps?) factory.
Inspect bakers-cli/addons/workspace-git/src/index.ts for the shipped Git backend and reusable teardown helper. Its current branch/base limitation is not a model for implementing parent-base selection. ensure must validate reuse and branch/base selection; checking only whether a directory exists is insufficient. Never reset an existing branch just to attach a worktree.
The rules:
ensure(identifier, branch?, baseRef?)returns the same path for the same ticket on every call, and reuses an existing worktree instead of recreating it. Reportcreated: trueonly when this call made it: the conductor runsafter_createandopenWorkspaceon that. Create a new branch frombaseRefwhen it resolves, else from your default base. Returnenvfor variables the run needs from your backend.remove(branch, worktreePath?)tears the worktree down. PreferworktreePathoverbranch: the agent may have renamed the branch. Returnremovedafter a teardown,already_absentwhen nothing was there, andunverifiedwhen it may still exist on another host; the reaper retriesunverifiedlater. Throw only on a real failure.removeGitWorktreefrom@bakers-build/addon-workspace-gitis the Git teardown every shipped workspace falls back to. It refuses to remove the main checkout. Call it after your tool's own teardown, or alone.- A workspace starts no terminal and runs no hooks.
Package and select it
The following registration fragment assumes your tested myExecutor factory exists. Package it as Addon contracts describes, and export the plugin from src/preset.ts:
ts
import type { Preset } from '@bakers-build/conductor/contract';
// Your implementation must satisfy every lifecycle rule above.
import { myExecutor } from './index.js';
export const executors: Preset['executors'] = (acc, opts) => [
...acc,
myExecutor(opts as Parameters<typeof myExecutor>[0]),
];
export const scopes: Preset['scopes'] = ['machine', 'project'];A workspace exports worktrees the same way. Declare ['project'] when the addon also has hook listeners.
Then select it in .bakers/project.config.js, either by listing the addon or by naming the slot:
js
addons: ['my-executor-addon'],
// or, explicitly, with options:
executor: { use: 'my-executor-addon', with: { command: 'codex' } },
worktree: { use: '@bakers-build/addon-workspace-git' },A machine may override the executor in ~/.bakers/machine.config.js; the workspace always stays with the project. bakers config check shows which file the executor came from.
Test it
Test the executor through startRun and cleanupRun with your tool's CLI replaced by a recording function, as bakers-cli/addons/herdr-core/tests/executor.test.ts does. Test a Git workspace against a real temporary repository, as bakers-cli/addons/workspace-git/tests/ does. The conductor's own suites use @bakers-build/addon-fake as both slots.
Migrating an addon
BbExecutor.runHook, BbExecutor.removeWorktree and BbWorkspace.applyOpenLayout are retired. The conductor runs project hooks; move removal to BbWorkspace.remove and the open layout to BbExecutor.openWorkspace. herdr rejects with.hooks; move those commands to top-level hooks.