Skip to content

Hooks

Suggest Edits

Hooks are the integration points plugins use to share Bakin state and behavior. Reach for them when you need task context, agent details, model choices, workflow state, assets, or health checks owned by another plugin.

This reference shows the hook key to call, what it returns or changes, and the registration that owns the contract.

Asset hooks expose file, sidecar, variant, and trash helpers for plugins that need to work with Bakin-managed files.

assets.createStub Create sidecar stub.

Creates a starter sidecar for an asset file and returns the written metadata. Use it when adopting a file into Bakin-managed asset state.

Terminal window
const result = await ctx.hooks.invoke(
'assets.createStub',
{
assetPath: '~/.bakin/assets/store/task-123/image.png'
},
)
plugins/assets/index.ts:543 rpc
assets.detectVariant Detect asset variant.

Infers the asset variant represented by a filename, such as before, after, or reference. Use it to keep imported assets grouped and labeled consistently.

Terminal window
const result = await ctx.hooks.invoke(
'assets.detectVariant',
{
filename: 'task-123.after.png'
},
)
plugins/assets/index.ts:544 rpc
assets.emptyTrash Empty asset trash.

Permanently removes every asset currently in trash for the provided asset root. Use it for explicit cleanup actions where restore is no longer expected.

Terminal window
const result = await ctx.hooks.invoke(
'assets.emptyTrash',
{
assetsRoot: '~/.bakin/assets'
},
)
plugins/assets/index.ts:579 rpc
assets.getAssetTypes List asset types.

Returns the asset type definitions known to the assets plugin. Use it to build filters, upload forms, or validation messages that match Bakin asset categories.

Terminal window
const result = await ctx.hooks.invoke(
'assets.getAssetTypes',
{},
)
plugins/assets/index.ts:545 rpc
assets.getSidecarPath Get sidecar path.

Resolves the metadata sidecar path for a managed asset file. Use it when another plugin has an asset path and needs to read or write the matching metadata.

Terminal window
const result = await ctx.hooks.invoke(
'assets.getSidecarPath',
{
assetPath: '~/.bakin/assets/store/task-123/image.png'
},
)
plugins/assets/index.ts:542 rpc
assets.pathForFilename Resolve asset path.

Calculates the managed asset path for a filename. Use it when a plugin needs to place or reference a file using Bakin asset storage conventions.

Terminal window
const result = await ctx.hooks.invoke(
'assets.pathForFilename',
{
filename: 'task-123.after.png'
},
)
plugins/assets/index.ts:546 rpc
assets.purgeClipboardForTask Purge task clipboard assets.

Deletes clipboard-sourced assets associated with a completed task when that cleanup setting is enabled. Use it from task completion flows that want asset cleanup to stay centralized.

Terminal window
const result = await ctx.hooks.invoke(
'assets.purgeClipboardForTask',
{
taskId: 'task-123'
},
)
plugins/assets/index.ts:549 rpc
assets.restoreAsset Restore trashed asset.

Restores one soft-deleted asset from the trash back into managed asset storage. Use it when a plugin needs undo behavior for asset deletion.

Terminal window
const result = await ctx.hooks.invoke(
'assets.restoreAsset',
{
trashFilename: 'task-123.after.png',
assetsRoot: '~/.bakin/assets'
},
)
plugins/assets/index.ts:578 rpc
assets.trash.list List trashed assets.

Returns soft-deleted assets currently available for restore or permanent removal. Use it to power trash views without duplicating filesystem conventions.

Terminal window
const result = await ctx.hooks.invoke(
'assets.trash.list',
{
assetsRoot: '~/.bakin/assets'
},
)
plugins/assets/index.ts:577 rpc
assets.validateSidecar Validate sidecar metadata.

Checks an asset sidecar JSON file and returns validation details. Use it before trusting metadata created by imports, repairs, or external tools.

Terminal window
const result = await ctx.hooks.invoke(
'assets.validateSidecar',
{
metaPath: '~/.bakin/assets/store/task-123/image.json'
},
)
plugins/assets/index.ts:541 rpc

Health hooks expose registered readiness and diagnostic checks so other surfaces can list or inspect them.

health.getCheck Get a health check.

Returns metadata for one registered health check by id, without running the check. Use it when a plugin needs the check name, owner, and autofix capability before deciding what to show or run.

Terminal window
const result = await ctx.hooks.invoke(
'health.getCheck',
{
id: 'runtime'
},
)
plugins/health/index.ts:476 rpc
health.list List health checks.

Returns the health checks registered by core and plugins without executing them. Use it when another surface needs to show the available diagnostics or autofix support.

Terminal window
const result = await ctx.hooks.invoke(
'health.list',
{},
)
plugins/health/index.ts:475 rpc

Model hooks expose the effective model configuration and notify dependent surfaces when runtime model state changes.

models.configChanged Model config changed.

Notifies listeners after an agent model assignment changes. Use it to refresh dependent state, update UI, or invalidate plugin caches that depend on model routing.

Terminal window
await ctx.hooks.callAll(
'models.configChanged',
{
agentId: 'patch',
oldModel: 'gpt-5.4',
newModel: 'gpt-5.5'
},
)
plugins/models/index.ts:700 event
models.getAvailableModels List available models.

Returns the model catalog available from the currently configured providers. Use it to populate pickers, validate assignments, or compare model options before saving config.

Terminal window
const result = await ctx.hooks.invoke(
'models.getAvailableModels',
{},
)
plugins/models/index.ts:716 rpc
models.getEffectiveModel Get effective model.

Resolves the model an agent will actually use after defaults, overrides, and provider settings are applied. Use it when a plugin needs runtime-ready model information for one agent.

Terminal window
const result = await ctx.hooks.invoke(
'models.getEffectiveModel',
{
agentId: 'patch'
},
)
plugins/models/index.ts:704 rpc
models.markConfigDirty Mark config dirty.

Marks model configuration as changed so the runtime knows a refresh is needed. Use it after writing model settings that should not be treated as live yet.

Terminal window
await ctx.hooks.callAll(
'models.markConfigDirty',
{},
)
plugins/models/index.ts:712 event
models.markRuntimeRestarted Mark runtime refreshed.

Records that the runtime has picked up the latest model configuration. Use it after restart or reload flows so stale dirty-state warnings can clear.

Terminal window
await ctx.hooks.callAll(
'models.markRuntimeRestarted',
{},
)
plugins/models/index.ts:714 event

Hooks discovered from source registration audit.

schedule.ensureBakinJob Ensure Bakin schedule

Create or update a Bakin-managed runtime cron job and return the provider job id.

Terminal window
const result = await ctx.hooks.invoke(
'schedule.ensureBakinJob',
{},
)
plugins/schedule/index.ts:1066 rpc

Task hooks let plugins enrich task details and react to task lifecycle changes.

tasks.enrichDetails Add project task context.

Adds project title, status, progress, and excerpt data to task detail payloads. Use it when a task surface wants project context without depending on project storage.

Terminal window
const next = await ctx.hooks.call(
'tasks.enrichDetails',
{
task: {
id: 'task-123',
projectId: 'launch-docs'
}
},
)
bakin-bits-official/plugins/projects/index.ts:222 waterfall
tasks.statusChanged Sync project task state.

Updates linked project checklist items when a task moves into a completed state. Use it to keep project progress in sync with task lifecycle events.

Terminal window
await ctx.hooks.callAll(
'tasks.statusChanged',
{
taskId: 'task-123',
from: 'doing',
to: 'done'
},
)
bakin-bits-official/plugins/projects/index.ts:211 event

Team hooks expose runtime agent and team metadata for plugins that need agent-aware behavior.

team.getAgent Get an agent.

Returns one runtime agent by id, including team-aware metadata when available. Use it when a plugin already has an agent id and needs the full display record.

Terminal window
const result = await ctx.hooks.invoke(
'team.getAgent',
{
id: 'patch'
},
)
plugins/team/index.ts:1748 rpc
team.getAgentIds List agent ids.

Returns the ids of agents currently known to the runtime. Use it for lightweight validation, assignment pickers, or loops that do not need full agent metadata.

Terminal window
const result = await ctx.hooks.invoke(
'team.getAgentIds',
{},
)
plugins/team/index.ts:1753 rpc
team.getAgentTeam Get agent team.

Returns the team currently assigned to an agent, or null when the agent is unassigned. Use it to add team context to task, workflow, or activity views.

Terminal window
const result = await ctx.hooks.invoke(
'team.getAgentTeam',
{
id: 'patch'
},
)
plugins/team/index.ts:1760 rpc
team.getOrgStructure Get org structure.

Returns the current organization structure for teams and agents. Use it when a plugin needs the full hierarchy instead of individual team or agent records.

Terminal window
const result = await ctx.hooks.invoke(
'team.getOrgStructure',
{},
)
plugins/team/index.ts:1766 rpc
team.getTeamMembers List team members.

Returns the agents assigned to one team. Use it for team dashboards, routing rules, or workflow logic that needs team membership.

Terminal window
const result = await ctx.hooks.invoke(
'team.getTeamMembers',
{
teamId: 'docs'
},
)
plugins/team/index.ts:1757 rpc
team.list List agents.

Returns runtime agents with their display and team metadata attached. Use it when another plugin needs the agent roster as Bakin presents it.

Terminal window
const result = await ctx.hooks.invoke(
'team.list',
{},
)
plugins/team/index.ts:1747 rpc
team.resolveProfile Resolve agent profile.

Returns the runtime profile for an agent id. Use it when a plugin needs the lower-level profile data behind an agent display record.

Terminal window
const result = await ctx.hooks.invoke(
'team.resolveProfile',
{
id: 'patch'
},
)
plugins/team/index.ts:1754 rpc

Workflow hooks expose workflow definitions, instances, steps, gates, and notification helpers for task automation.

workflows.approveGate Approve workflow gate.

Approves a pending workflow gate and advances the instance. Use it from plugins that own an external review surface for workflow-backed tasks.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.approveGate',
{},
)
plugins/workflows/index.ts:1588 rpc
workflows.authorizeToolUse Authorize workflow tool use.

Checks whether an agent may perform a workflow-scoped tool action for a task. Use it before executing workflow-sensitive automation.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.authorizeToolUse',
{},
)
plugins/workflows/index.ts:1614 rpc
workflows.cancelInstance Cancel workflow instance.

Cancels the workflow instance attached to a task. Use it when task state changes make the workflow no longer relevant or safe to continue.

Terminal window
await ctx.hooks.callAll(
'workflows.cancelInstance',
{
taskId: 'task-123'
},
)
plugins/workflows/index.ts:1618 event
workflows.completeStep Complete workflow step.

Submits output for a workflow step and advances the instance when validation passes. Use it from agents or tools that finish a workflow action.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.completeStep',
{
taskId: 'task-123',
stepId: 'review',
output: {
ok: true
}
},
)
plugins/workflows/index.ts:1606 rpc
workflows.createInstance Create workflow instance.

Creates a workflow instance for a task and optional assignee context. Use it when task creation or routing should immediately attach a workflow.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.createInstance',
{
taskId: 'task-123',
workflowId: 'docs-review',
assignee: 'patch'
},
)
plugins/workflows/index.ts:1587 rpc
workflows.definitions.list List workflow definitions.

Returns available workflow definitions from the configured content directory. Use it to populate workflow selectors or validate workflow ids before creating instances.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.definitions.list',
{},
)
plugins/workflows/index.ts:1608 rpc
workflows.getActiveAgents List active workflow agents.

Returns agents currently active in a workflow task. Use it for coordination, notification, or assignment views that need live workflow participants.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.getActiveAgents',
{
taskId: 'task-123'
},
)
plugins/workflows/index.ts:1613 rpc
workflows.getCurrentStep Get current step.

Returns the current workflow step for a task, optionally scoped to an agent. Use it when a plugin needs to know what work is currently actionable.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.getCurrentStep',
{
taskId: 'task-123',
agentId: 'patch'
},
)
plugins/workflows/index.ts:1605 rpc
workflows.getNotificationChannel Get notification channel.

Returns one workflow notification channel by id. Use it before sending or configuring alerts that depend on a specific channel implementation.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.getNotificationChannel',
{
id: 'slack'
},
)
plugins/workflows/index.ts:1624 rpc
workflows.instances.list List workflow instances.

Returns workflow instances, optionally filtered by status. Use it for dashboards, queues, and maintenance flows that need a broad view of active workflow state.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.instances.list',
{
statusFilter: 'in_progress'
},
)
plugins/workflows/index.ts:1604 rpc
workflows.isGateNotified Check gate notification.

Checks whether a workflow gate notification has already been sent. Use it to avoid duplicate alerts for the same task and gate step.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.isGateNotified',
{
taskId: 'task-123',
stepId: 'approval'
},
)
plugins/workflows/index.ts:1615 rpc
workflows.loadDefinition Load workflow definition.

Loads one workflow definition by name. Use it when a plugin needs the template shape, steps, or metadata behind a workflow id.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.loadDefinition',
{
name: 'docs-review'
},
)
plugins/workflows/index.ts:1609 rpc
workflows.loadInstance Load workflow instance.

Loads the workflow instance attached to a task. Use it when a plugin needs current workflow state without reading workflow files directly.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.loadInstance',
{
taskId: 'task-123'
},
)
plugins/workflows/index.ts:1585 rpc
workflows.markGateNotified Mark gate notified.

Records that a workflow gate notification was sent. Use it immediately after notifying a reviewer or channel so future checks can suppress duplicates.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.markGateNotified',
{
taskId: 'task-123',
stepId: 'approval'
},
)
plugins/workflows/index.ts:1616 rpc
workflows.matchWorkflow Match workflow.

Suggests a workflow based on a task title and description. Use it when creating tasks that should automatically pick the most relevant workflow template.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.matchWorkflow',
{
title: 'Improve hook docs',
description: 'Add generated examples'
},
)
plugins/workflows/index.ts:1607 rpc
workflows.notificationChannels.list List notification channels.

Returns workflow notification channels registered by core or plugins. Use it to show available delivery targets for gate and workflow alerts.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.notificationChannels.list',
{},
)
plugins/workflows/index.ts:1623 rpc
workflows.rejectGate Reject workflow gate.

Rejects a pending workflow gate, records the reason, and rewinds the instance per the workflow gate policy. Use it from plugins that own an external review surface for workflow-backed tasks.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.rejectGate',
{},
)
plugins/workflows/index.ts:1592 rpc
workflows.reopenFromStep Reopen workflow from step.

Reopens an existing workflow instance at a prior actionable step. Use it when a plugin needs explicit user recovery without creating a replacement workflow task.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.reopenFromStep',
{},
)
plugins/workflows/index.ts:1597 rpc
workflows.saveInstance Save workflow instance.

Persists a workflow instance after a plugin has changed its state. Use it to keep workflow updates routed through the workflow plugin storage layer.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.saveInstance',
{
instance: {
taskId: 'task-123',
workflowId: 'docs-review'
}
},
)
plugins/workflows/index.ts:1586 rpc
workflows.validateStepOutput Validate step output.

Validates workflow step output against the step schema. Use it before accepting agent or tool output that should advance a workflow.

Terminal window
const result = await ctx.hooks.invoke(
'workflows.validateStepOutput',
{
schema: {
type: 'object'
},
output: {
approved: true
}
},
)
plugins/workflows/index.ts:1617 rpc