* fix(server): keep a restarted plugin's agent tools on live sessions
A plugin restart (reload, update) gives the plugin a new instance id.
Tools attached to an open session are stamped with the old one, so
getPluginTools filters them out and the agent MCP neither lists nor
serves them ("Tool ... not found"). They came back only when the session
reopened, which happens before a prompt to an idle agent; messages to a
busy agent are steered or replace the run on the stale session, so a
busy agent could go without its plugin tools for as long as it stayed
busy.
The agent MCP now reattaches them before it builds a request's catalog:
AgentManager remembers the request a session opened with, and for
plugins whose instance changed it replays agent.open.before to those
plugins only and keeps only the tools they return. Env and MCP server
changes still wait for the reopen, which is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(server): keep stopped plugins eligible and guard tool replays
- A plugin that is stopped or mid-restart during an MCP request keeps its old
attachment, so a later request retries it instead of losing its tools.
- A reopen waits for an in-flight replay, so the replay cannot overwrite the
reopen's tool definitions inside the plugin process.
- Refreshed tools that collide with a Paseo tool or another plugin's tool are
dropped for that plugin instead of breaking the agent's whole catalog.
* fix(server): retry a plugin whose tool replay failed
A failed replay is left out of the result like a stopped plugin, so the
agent's next MCP request retries it instead of dropping its tools until the
session reopens. The reopen race test now waits for the replay to reach its
gate before it starts the reopen.
* fix(server): replay a restarted plugin's open once per instance, as refresh
A replay whose hook threw or timed out ran again on every agent MCP
request, so each Paseo tool call waited on the broken plugin. The
runtime now remembers the instance that failed and replays it only
after the next restart.
The replay now arrives with reason "refresh", like the idle reopen the
same restart causes, so plugins no longer see "create" again.
An open waits until no replay is pending before it detaches, and a
replay that outlives its session detaches only the plugins it replayed.
Co-authored-by: Tom Gringauz <17593920+tomgrin10@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(server): keep no replay failure record for a closed agent
The replay takes the agent's record when it starts and writes a failure
into that record. Closing the agent drops it, so a replay that fails
afterwards no longer leaves an entry behind.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(plugins): say native-tool agents keep launch-time tools until the reopen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(server): reserve provider-disabled Paseo tool names in a tool replay
A replayed plugin tool named after a Paseo tool that the agent's provider
disables was accepted, and every later agent MCP request then failed on
the plugin collision check. The replay now builds its reserved names with
an all-enabled policy, the same names that check reserves.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(server): reopen only sessions a plugin change affects
A plugin reload bumped one global session-open generation, so every live
agent reopened at its next idle prompt. The reopen closes the provider
session, cancels its subagents and clears background work, even for agents
the plugin never touched.
SessionAttachments now owns what each agent.open.before plugin contributed
to each live session. A refresh reruns only the plugins whose instance
changed, swaps their tools in place, and marks the session stale only when
its launch would differ. This replaces the AgentManager maps, the runtime's
failed-replay record, and the global generation. Native-tool providers
resolve plugin tools by name at call time, so their calls reach the new
instance.
* fix(server): compare plugin refreshes with the running launch
A plugin refresh decided staleness against the last refresh with a sticky
flag, so reverting a tool edit still reopened the session. A failed reopen
also deleted the session's plugin record while the old provider session kept
running, which left it without any plugin tools.
SessionAttachments now keeps the contributions the session launched with as
the baseline and works out staleness against it on every refresh. A failed
rerun or collision is kept on that plugin's contribution. A failed open keeps
the running session's record and marks its plugins for reattach on the next
refresh.
A launch-time native catalog entry now resolves the tool by plugin id and
name, so a different plugin that took the name is never called.
* fix(server): make a plugin open the baseline only once its launch takes over
A reopen whose plugin hooks succeed can still fail launch validation: a
plugin tool that takes a Paseo tool name, or an MCP server on a provider
without MCP support. The open had already replaced the session's record, so
the session lost its plugin tools, or kept a record for a launch that never
ran, and the next idle prompt did not retry.
An interactive open now stays pending until registerSession reports that the
provider launch took over. A launch that fails before then discards the
pending open, and the still-running session keeps its record. Its plugins
attach their tools again on the next refresh, and each idle prompt retries
the reopen.
* fix(server): discard a reload's plugin open on every pre-takeover rejection
resolveProviderLaunchConfig rejects a plugin MCP server that takes a saved
server name after the open is staged, and nothing discarded the staged open.
The reload now resolves and validates its launch config in one scope that
discards the staged open on any rejection, so the running session keeps its
plugin tools and the next idle prompt retries the reopen.
* fix(server): keep a tool name with its owner when a refresh replays every plugin
After a rejected reopen, every plugin replays on the next refresh, and the
collision check gave a contested name to whichever plugin sorted first. A name
now stays with the plugin that has it in the session's record, as long as that
plugin still returns the tool.
* fix(server): rerun a refreshed plugin callback with the agent's current metadata
A plugin reload used to reopen every session, so its callback saw the agent's
current title, workspace, labels, and metadata. A refresh now replays the
recorded open request instead, so a hook that filters on metadata set after
launch kept returning nothing. The refresh now overlays those agent fields,
which plugins cannot change, on the recorded request.
* fix(server): replay the plugin chain in order, hold refreshes over a plugin restart, and roll back every failed launch's plugin open
- A cached plugin contribution is reused only when its instance and the env and instructions it received still match; otherwise the plugin reruns in open order and the composed launch is compared with the running one.
- A plugin reload or source update publishes one settled change: a session refresh waits for the restart instead of reading the stop as removal.
- Create, resume, import, and reopen share one launch boundary: the pending plugin open commits when registerSession admits the agent and is discarded when the launch throws before that.
* fix(server): decide a plugin reopen from the same launch the open builds
The open and the refresh now compose the launch with one function. The staleness check compares which plugin provides each tool, so a native-tool catalog bound to a removed plugin reopens, and a proposed launch with an MCP server name collision counts as changed, so the reopen reports it.
* fix(server): reserve only Paseo's own tool names when a plugin refresh checks collisions
The agent's catalog also lists its plugin tools, so a later plugin rerun by an earlier plugin's edit saw its own tool as taken and lost it. The session owner settles names between plugins from its record. The hooks reference now says an MCP server name collision fails the reopen without hiding tools.
* fix(plugins): let a refreshed plugin's running tool calls finish
The plugin process detached the session's tools at the start of every agent.open.before, which aborted calls already running. Attaching replaces the definitions for later calls; the daemon still detaches before an open that replaces the provider session.
---------
Co-authored-by: Tom Gringauz <17593920+tomgrin10@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: paseo-bot[bot] <paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
43 KiB
title, description, nav, order, category
| title | description | nav | order | category |
|---|---|---|---|---|
| Plugin hooks | Register hooks to change requests or observe agent and workspace operations. | Hooks | 49 | Plugins |
Plugin hooks
Use server.addHook(name, handler) in index.server.ts. Hooks run while the plugin is enabled, even with no app connected. addHook is available from Paseo 0.14; set requirements.paseo to the release you build against.
import type { PluginServerContext } from "@getpaseo/plugin/server";
export default function contribute(server: PluginServerContext) {
const remove = server.addHook("agent.open.before", async ({ request }) => ({
...request,
env: { ...request.env, REGION: "eu" },
}));
return remove;
}
Naming and timing
Names follow subject.operation.position: the subject, the operation, then before or after. The name identifies a lifecycle position. Whether Paseo waits is a per-hook property shown in the table below. workspace covers every workspace; worktree covers only git worktrees.
- Waiting hooks finish before Paseo continues. Throwing, returning invalid data, or exceeding 30 seconds fails the operation with
Plugin <id> <hook> failed: …. Request-changing hooks receive{ request }and may return a complete replacement request orundefined. - Notifications receive the event object and return
Promise<void>. Paseo does not wait; errors are logged against the plugin and the operation continues.agent.turn.beforeandagent.permission.beforeare notifications fired when a turn starts or a permission becomes pending.
All handlers must be async. Turn completion includes success, failure, and cancellation; inspect outcome. Permission completion includes every resolution; inspect resolution.
Creating an agent happens once, and agent.create.before changes its saved configuration. Opening starts the provider process: the first run, resume after a daemon restart, reading history, importing an outside session, or reload. agent.open.before contributes launch-only environment, instructions, tools, and MCP servers each time. Creating opens the agent; opening an existing agent does not create it; closing ends the running instance. Opening a tab in the app is a separate action.
worktree.create.after runs before the workspace is registered. It precedes workspace.create.after, and both precede the first agent's agent.create.before / agent.open.before.
Return early from a waiting hook
Start detached work and return when the operation should continue immediately:
server.addHook("worktree.create.after", async ({ worktree }) => {
void warmCaches(worktree.path);
});
Paseo only sees the returned promise, so detached work gets no error reporting and no cancellation signal.
Hooks
| Hook | Waits | Payload | Handler may change |
|---|---|---|---|
workspace.create.before |
yes | { request } |
Entire create request |
workspace.create.after |
no | { workspace } |
|
workspace.archive.after |
no | { workspace } |
|
worktree.create.before |
yes | { request } |
Creation options and destination |
worktree.create.after |
yes | { worktree } |
Files in the worktree; throw to abort creation |
agent.create.before |
yes | { request: { config, env?, metadata } } |
Saved config except cwd; env; metadata |
agent.create.after |
no | { agent } |
|
agent.open.before |
yes | { request } |
Launch-only env, appendSystemPrompt, tools, mcpServers |
agent.close.after |
no | { agent } |
|
agent.archive.after |
no | { agent, archivedAt } |
|
agent.turn.before |
no | { agent, turnId } |
|
agent.turn.after |
no | { agent, turnId, outcome } |
|
agent.permission.before |
no | { agent, request } |
|
agent.permission.after |
no | { agent, requestId, resolution } |
Shared payloads
interface PluginHookAgent {
id: string;
workspaceId: string | null;
parentAgentId: string | null;
provider: string;
cwd: string;
title: string | null;
readonly background: boolean;
metadata: Record<string, JsonValue>;
}
interface PluginHookWorkspace {
id: string;
projectId: string;
cwd: string;
name: string | null;
archivedAt: string | null;
metadata: Record<string, JsonValue>;
}
type PluginTurnOutcome =
| { kind: "completed" }
| { kind: "failed"; error: { message: string; code?: string } }
| { kind: "canceled"; reason: string };
| Field | Shape / meaning |
|---|---|
background |
true for a background agent |
turnId |
Provider-reported string or null; unique across resumed sessions |
timeline |
Deprecated, always []; fetch history with the SDK. |
request |
SDK AgentPermissionRequest; kind is tool, plan, question, mode, or other |
resolution |
SDK AgentPermissionResponse |
archivedAt |
Timestamp string |
Metadata
Agents and workspaces carry a metadata record for plugin data. Keys are strings, values are any JSON value, and Paseo stores the record without reading a key. Prefix keys with your plugin id so plugins do not collide. Labels stay strings for filtering and tagging; use metadata for structured data.
Set metadata when you create the agent or workspace, or change it later. null removes a key, and any other value replaces the key's whole value:
const agent = await paseo.agents.create({
config: { provider: "codex/gpt-5.5" },
cwd: "/projects/shop",
metadata: { "linear.issue": { id: "ENG-123" } },
});
agent.metadata; // { "linear.issue": { id: "ENG-123" } }
await agent.setMetadata({ "linear.issue": null });
await paseo.workspaces.ref(workspaceId).setMetadata({ "linear.issue": { id: "ENG-123" } });
Metadata survives a daemon restart. Every hook payload carries it: workspace.create.before and agent.create.before receive the metadata the caller sent, and the after hooks and agent.open.before receive what is stored. Against a host that predates metadata, these calls throw "Update the host to use metadata."
workspace.create.before
Receives { request } with source, optional title, optional metadata, and firstAgentContext. You may replace the entire explicit create request; a throw, invalid result, or timeout fails creation. Existing workspaces and directory lookup/import are unaffected.
Choose workspace isolation
server.addHook("workspace.create.before", async ({ request }) => {
if (request.source.kind !== "directory") {
return request;
}
return {
...request,
source: {
kind: "worktree",
cwd: request.source.path,
action: "branch-off",
},
};
});
Result: an explicit directory creation request becomes a worktree request. Existing workspaces and directory lookup/import operations are unaffected.
workspace.create.after
Fires after the workspace record is created and its directory is available. Receives { workspace }.
server.addHook("workspace.create.after", async ({ workspace }) => {
console.log(workspace);
});
workspace.archive.after
Fires after archive state is saved. Receives { workspace }; worktree cleanup can still be pending.
server.addHook("workspace.archive.after", async ({ workspace }) => {
console.log(workspace);
});
worktree.create.before
Choose the location and creation options for a new worktree. Paseo awaits this hook before git worktree add, on creation from the app, CLI, MCP, and agent creation. Receives { request }; return a complete replacement request or undefined to keep it. Throwing, invalid returned data, or a 30-second timeout aborts creation with the plugin and hook named in the error.
import { basename, dirname, join } from "node:path";
server.addHook("worktree.create.before", async ({ request }) => ({
...request,
path: join(
dirname(request.sourceCheckout),
`${basename(request.sourceCheckout)}.${request.branch.replaceAll("/", "-")}`,
),
}));
For source /home/me/src/paseo and branch feature/x, this creates /home/me/src/paseo.feature-x. See the complete worktree-placement example.
| Request field | Meaning |
|---|---|
kind |
branch-off, checkout-branch, checkout-change-request, or checkout-github-pr |
branch |
Requested local branch name |
baseRef |
Starting ref for branch-off; comparison base for change requests; absent for checkout-branch. To branch off a ref, return kind: "branch-off". |
slug |
Normalized worktree name |
path |
Absolute destination; initially the default location with any existing-path suffix resolved |
repoRoot |
Read-only main repository root |
sourceCheckout |
Read-only source checkout root, including when creation starts from another worktree |
forge, changeRequestNumber, headRef |
Change-request checkout identity; GitHub legacy checkouts use githubPrNumber instead of forge and changeRequestNumber |
headRepositoryOwner, headRepository |
Optional source repository facts; headRepository is present only on change-request checkouts |
checkoutRefs |
Optional fetch sources: { remoteName?: string, remoteRef: string }[] |
pushRemoteUrl, trackOriginHead |
Optional push destination and tracking policy |
Once path is returned, slug only feeds branch-off naming; the CLI looks up worktrees by the basename of their path.
Every field except repoRoot and sourceCheckout is transformable. Return all required facts for the chosen kind. Paseo resolves the Git source plan after this hook, so handlers can change the branch and base before fetching refs, while Git can still choose a unique final branch name afterward.
Paseo resolves symlinked parents and validates the returned path. It must be absolute, must not exist, and must not be the filesystem root, your home directory, the repository root, inside a .git directory, or an ancestor of the repository. An existing destination fails creation; Paseo never adds a suffix to a plugin-chosen path. The plugin must leave directory creation to Paseo.
Ordering: worktree.create.before → worktree manager create (or git worktree add) → worktree.create.after → workspace registration. To delegate git worktree add, removal, and restoration to an external tool such as Worktrunk, register a worktree manager with server.registerWorktreeManager() instead of creating directories inside worktree.create.before. Restoring a missing worktree recreates it at its recorded path without running creation hooks, delegating to the owning manager's optional restore handler when present.
worktree.create.after
Paseo waits for this hook after a new git worktree exists and before workspace registration, setup, terminals, or agents. Receives { worktree: { path, branch, sourceCheckout } }: the absolute worktree path, branch name, and source checkout directory. There is no workspace id yet. Return nothing; write files directly into the worktree. Throwing or exceeding 30 seconds aborts creation and removes the new worktree.
This covers branch-off, branch checkout, and PR checkout creation. Restoring a missing archived worktree uses a separate recovery path and does not fire this hook.
import { copyFile } from "node:fs/promises";
server.addHook("worktree.create.after", async ({ worktree }) => {
await copyFile(`${worktree.sourceCheckout}/.env`, `${worktree.path}/.env`);
});
agent.create.before
Receives { request: { config, env?, metadata } }. Config and metadata changes are saved and remain after the plugin is disabled or removed; env applies to the initial launch and is not saved. You cannot change config.cwd. A throw, invalid result, or timeout fails creation.
agent.create.before.config uses AgentSessionConfig:
| Fields | Constraint |
|---|---|
provider, model |
Separate fields; changing provider may require changing model/mode/options |
modeId, thinkingOptionId |
Provider-specific selections |
title, systemPrompt |
Agent configuration |
providerOptions |
Provider options, including speed and auto-accept selections |
mcpServers, toolPolicy |
MCP configuration and exact-tool preapprovals |
cwd |
Cannot change |
Change saved configuration
Add this callback inside contribute(server) to set the saved options for new Codex agents:
server.addHook("agent.create.before", async ({ request }) => {
if (request.config.provider !== "codex") {
return request;
}
return {
...request,
config: {
...request.config,
providerOptions: {
...request.config.providerOptions,
sandbox_mode: "workspace-write",
approval_policy: "on-request",
},
},
};
});
| Input | Result |
|---|---|
providerOptions.sandbox_mode: "read-only" |
"workspace-write" |
providerOptions.web_search: "disabled" |
Preserved by the spread |
The selected provider validates providerOptions. Explicit Codex sandbox and approval options
override its mode presets.
agent.create.after
Ordinary creation finishes. Receives { agent }; import and resume do not fire it.
server.addHook("agent.create.after", async ({ agent }) => {
console.log(agent);
});
agent.open.before
Receives { request }; only env, appendSystemPrompt, tools, and mcpServers may change, for this launch. All other fields are read-only. A throw, invalid result, or timeout fails the open.
Do not await a write to the agent being opened: setMetadata, setLabels, or an option, model, thinking or mode change. The write waits for the open to finish, the open waits for your hook, so the hook times out and the open fails. Start the write without awaiting it; it runs right after the open:
server.addHook("agent.open.before", async ({ request }, { paseo }) => {
void paseo.agents
.ref(request.agentId)
.setMetadata({ "my.plugin": { openedBy: "hook" } })
.catch((error) => console.error(error));
});
agent.open.before request example:
{
"agentId": "agent-123",
"workspaceId": "workspace-456",
"provider": "codex",
"cwd": "/projects/shop",
"title": "Workspace notes",
"background": false,
"labels": { "notes/enabled": "true" },
"metadata": { "linear.issue": { "id": "ENG-123" } },
"tools": [],
"mcpServers": {},
"reason": "resume",
"purpose": "interactive",
"env": { "COMPANY_ENV": "development" }
}
| Field | Values |
|---|---|
workspaceId |
String or null |
title |
Read-only string or null; creation title on create, stored title on resume. |
background |
Read-only true for a background agent. Fixed at creation. |
labels |
Read-only string map; creation labels on create, stored labels on resume. |
metadata |
Read-only JSON map; the metadata stored on the agent. |
tools |
Editable AgentToolDefinition[], local to this plugin. See Attach tools to agents. |
mcpServers |
Editable launch-only server map, local to this plugin. See Inject MCP servers. |
reason |
create, resume, refresh, import |
purpose |
interactive, history |
env |
Launch override map; excludes the daemon's inherited environment. Replace the map to add, replace, or remove overrides. |
Append instructions on every session opening
server.addHook("agent.open.before", async ({ request }) => ({
...request,
appendSystemPrompt: [...(request.appendSystemPrompt ?? []), "Follow the team engineering guide."],
}));
Instructions follow the saved agent prompt and daemon instructions, in plugin order. They are not saved in the agent configuration and are ignored for history opens. Reload the plugin after changing its data to apply new instructions on the next reopen. Running turns continue; removing an instruction does not remove conversation history. Internal agents also receive these instructions. The ACP adapter does not send system instructions to its providers. Plugin providers receive the composed prompt, but must apply it themselves.
Codex instruction updates require Codex 0.121.0 or newer with a recognizable version reported by the app server. Source builds reporting 0.0.0 must use a versioned build. Paseo adds a current instruction snapshot to existing threads; earlier snapshots remain in the conversation. A crash during an update or rewinding a thread can repeat a snapshot.
Inject environment variables on every session opening
server.addHook("agent.open.before", async ({ request }) => {
return {
...request,
env: {
...request.env,
COMPANY_ENV: "development",
},
};
});
Session-open overrides are re-derived on every open. agent.create.before.env applies only to the
initial launch and is not saved in the agent's configuration.
Inject MCP servers
Use agent.create.before.config.mcpServers when the server should become part of the agent's saved
configuration. For a plugin-owned server, add this callback inside contribute(server), replacing
the placeholder URL with your MCP endpoint:
server.addHook("agent.open.before", async ({ request }) => {
if (request.provider !== "codex" || request.background) return;
return {
...request,
mcpServers: {
...request.mcpServers,
company: { type: "http", url: "https://tools.example.com/mcp" },
},
};
});
request.mcpServers uses the same server configurations as AgentSessionConfig.mcpServers.
The map starts empty for each plugin and accumulates across that plugin's own callbacks. It never
contains the agent's saved servers or another plugin's servers. Replace the map to add, replace,
or remove this plugin's entries; returning undefined preserves it. Paseo merges the plugins'
final maps in plugin-ID order.
A name colliding with a saved server, Paseo's internal paseo server, or another plugin's server
fails the session open and names the server and both sources. A provider without MCP support fails
with does not support MCP servers, naming the plugin. Opens with purpose: "history" ignore
these servers. Install, disable, and reload changes reach existing agents through the
session reopen behavior.
Attach tools to agents
Define a tool in index.server.ts and attach it in server.addHook("agent.open.before", async handler).
This example gives append_workspace_note only to agents with the label notes/enabled: "true":
import { writeFile } from "node:fs/promises";
import path from "node:path";
import { z } from "zod";
import { defineAgentTool, type PluginServerContext } from "@getpaseo/plugin/server";
const appendWorkspaceNote = defineAgentTool({
name: "append_workspace_note",
description: "Append a note to AGENT_NOTES.md in this agent's working directory.",
input: z.object({ note: z.string().min(1).describe("Note to append") }),
async execute({ note }, { agent, signal }) {
const notePath = path.join(agent.cwd, "AGENT_NOTES.md");
await writeFile(notePath, `${note}\n`, { encoding: "utf8", flag: "a", signal });
return {
text: `Saved note to ${notePath}`,
structuredContent: { path: notePath },
};
},
});
export default function contribute(server: PluginServerContext) {
server.addHook("agent.open.before", async ({ request }) => {
if (request.labels["notes/enabled"] !== "true") return;
return { ...request, tools: [...request.tools, appendWorkspaceNote] };
});
return () => {};
}
Set the label when creating an agent with the SDK:
const agent = await paseo.agents.create({
config: { provider: "codex/gpt-5.4" },
cwd: "/projects/shop",
labels: { "notes/enabled": "true" },
});
Select agents using any of the session-open request fields:
| Select by | Condition in the callback |
|---|---|
| Label | request.labels["notes/enabled"] === "true" |
| Provider | request.provider === "codex" |
| Workspace | request.workspaceId === "workspace-456" |
| Individual agent | request.agentId === chosenAgentId |
| Background agent | request.background |
request.tools starts empty for each plugin. Each callback sees the tools returned by earlier
callbacks in that plugin; replace the array to add or remove tools. Returning undefined preserves
the request. Tools are ignored for purpose: "history".
Import defineAgentTool, AgentToolDefinition, AgentToolContext, and AgentToolResult from
@getpaseo/plugin/server. The helper infers the validated input from your Zod schema:
declare function defineAgentTool<Input extends z.ZodType>(tool: {
name: string;
title?: string;
description: string;
input: Input;
execute(
input: z.output<Input>,
context: AgentToolContext,
): AgentToolResult | Promise<AgentToolResult>;
}): AgentToolDefinition;
interface AgentToolResult {
text?: string;
structuredContent?: unknown;
isError?: boolean;
}
| Execution context | Value |
|---|---|
agent |
Calling agent as a PluginHookAgent, including id, workspaceId, provider, cwd, and title |
paseo |
SDK connected to this daemon |
signal |
Abort signal for this tool call; pass it to file operations or external requests |
execute runs in the plugin process. Closures and the original Zod schema stay there; only tool
metadata and call inputs/results cross the process boundary. Paseo validates input before calling
execute. Invalid input returns schema issues to the agent. A thrown error becomes
{ isError: true, text: message } and the plugin keeps running. Canceling the call or closing its
transport aborts signal and discards the result. Tool calls have a 10 minute ceiling, separate
from the 30 second hook timeout. Closing or reopening an agent session drops its old definitions.
Return model-visible text in text. structuredContent must be JSON-serializable; when text is
omitted, Paseo formats that value as text for the model. Set isError: true to report a tool error.
Paseo delivers attached tools through its agent tool transport, using MCP or native registration as the provider supports. The same definition and callback work with either. Attached tools obey the same gates as Paseo tools. Only that agent sees them.
Names must match /^[a-z][a-z0-9_]*$/ and be at most 64 characters. A name colliding with a Paseo
tool or another plugin's tool on the same agent fails the session open and names both owners.
A duplicate name within one plugin also fails the session open. Agents the callback does not
target are unaffected.
| Change | When the agent receives it |
|---|---|
Start, stop, or reload a plugin declaring agent.open.before |
Before the session's next agent tool call or prompt, as described below. |
| Change which agents the callback targets | Run paseo plugin reload agent-tools after editing this example, then send the agent a prompt when it is idle. |
| Apply immediately | Call await paseo.agents.ref(id).reload({ requestId: "reload-notes" }). requestId is optional. This reopens the provider session, reruns hooks with reason: "refresh", and interrupts a running turn. |
| Read the current snapshot | Call await paseo.agents.ref(id).refresh(). This reads state without reopening the session. |
When a plugin declaring agent.open.before starts, stops, or reloads, Paseo reruns that plugin's
callback for each open session, before the session's next agent tool call or prompt. The callback
gets the request it saw at the session's last open, with reason: "refresh" and the agent's current
title, workspace, labels, and metadata. A later plugin in the chain also reruns when the env or
instructions it receives change. Other callbacks do not run.
A reload counts as one change. A tool call or prompt during the reload waits for the plugin to start, so the session does not lose the plugin's tools in between. If the plugin fails to start, the session continues as if the plugin stopped.
- The tools the callback returns replace its old tools at once, also during a running turn. The new plugin instance answers the calls.
- If the env, instructions, MCP servers, tool definitions, or the plugin that provides a tool
differ from what the session launched with, the session reopens before its next idle prompt. A running turn continues without interruption.
A callback whose result depends on
reasonalways differs from acreateopen. Reverting the change before that prompt cancels the reopen. - If nothing differs, the session keeps running with its background work and subagents. A plugin that does not target the agent leaves it as it is.
- If the callback throws or times out, its tools stay off, and the session reopens before its next idle prompt. Paseo does not rerun it for the same plugin instance.
- If a returned tool collides with a Paseo tool or another plugin's tool, that plugin's tools stay off, and the session reopens before its next idle prompt.
- If two plugins return the same MCP server name, both plugins keep their agent tools, but the reopen before the next idle prompt fails with the collision error.
Agents that receive Paseo tools natively (OpenCode with the bridge, OMP) keep the tool list they launched with until the reopen. Their calls to a listed tool reach the new instance of the plugin that attached it, and fail if that plugin no longer attaches it.
If an automatic reopen fails, the triggering prompt fails with that error. The session keeps running with the tools it had, and each later idle prompt tries the reopen again. See the complete agent-tools example.
agent.close.after
A live agent runtime closes. Receives { agent }.
server.addHook("agent.close.after", async ({ agent }) => {
console.log(agent);
});
agent.archive.after
Archive state is saved. Receives { agent, archivedAt }; runtime cleanup can still be pending.
server.addHook("agent.archive.after", async ({ agent, archivedAt }) => {
console.log(agent, archivedAt);
});
agent.turn.before
A live turn starts. Receives { agent, turnId }. History replay does not fire it.
server.addHook("agent.turn.before", async ({ agent, turnId }) => {
console.log(agent, turnId);
});
agent.turn.after
A live turn completes, fails, or is canceled. Receives { agent, turnId, outcome }. outcome.kind is completed, failed, or canceled. The payload carries no history. Read the turn from the agent's timeline: refetch({ direction: "tail", limit: 1, wholeTurns: true }) returns the latest turn whole, as below. Keep the entries whose turnId equals event.turnId, because a turn that starts before your read, such as a follow-up another plugin sent, replaces this one as the latest. The filtered list is empty in that case, and when event.turnId is null. Plugins built against an older SDK that read event.timeline get an empty array.
Send a follow-up when a turn ends
Copy server/inspect.ts
into your plugin. The helper imports types from @getpaseo/protocol/agent-types; add
@getpaseo/protocol at the version matching your daemon to your development dependencies
and install them before loading the plugin. latestOutputText joins text chunks after the latest user message.
import type { PluginServerContext } from "@getpaseo/plugin/server";
import { latestOutputText } from "./server/inspect";
export default function contribute(server: PluginServerContext) {
server.addHook("agent.turn.after", async (event, context) => {
if (event.outcome.kind === "canceled") {
return;
}
const agent = context.paseo.agents.ref(event.agent.id);
const page = await agent.timeline.refetch({ direction: "tail", limit: 1, wholeTurns: true });
const turn = page.entries.filter((entry) => entry.turnId === event.turnId);
const text = latestOutputText(turn.map(({ item }) => item));
if (/out of credits/i.test(text)) {
await agent.send("Try again.");
}
});
return () => {};
}
Turn ends: "out of credits"
→ plugin sends "Try again."
→ a new turn starts
This sends a new message with the existing SDK. Persistent matches keep sending follow-ups; add limits or delays in your plugin when needed. Attachments and tool effects are not replayed.
agent.permission.before
A permission or question becomes pending. Receives { agent, request }; request is an AgentPermissionRequest. Send the answer through the SDK.
Answer a permission request
Using shellCommand from the same helper file:
import type { PluginServerContext } from "@getpaseo/plugin/server";
import { shellCommand } from "./server/inspect";
export default function contribute(server: PluginServerContext) {
server.addHook("agent.permission.before", async (event, context) => {
const command = shellCommand(event.request);
if (command === null) {
return;
}
const agent = context.paseo.agents.ref(event.agent.id);
if (/\brm\s+-rf\b/.test(command)) {
await agent.respondToPermission({
requestId: event.request.id,
response: { behavior: "deny", message: "Recursive deletion is blocked." },
});
return;
}
if (command.trim() === "git status") {
await agent.respondToPermission({
requestId: event.request.id,
response: { behavior: "allow" },
});
}
});
return () => {};
}
| Request | Result |
|---|---|
rm -rf build |
Declined |
git status |
Approved |
| Other command or request | Left pending for the user |
| Already-resolved request | SDK response fails |
The regex is an example policy, not a shell parser. Permission requests can also be questions, plans, and mode changes; requesting permission does not end the turn.
agent.permission.after
A pending request is answered or cleared. Receives { agent, requestId, resolution }; resolution is an AgentPermissionResponse.
server.addHook("agent.permission.after", async ({ agent, requestId, resolution }) => {
console.log(agent, requestId, resolution);
});
Background agents
Agent hooks exclude the daemon's private disposable helpers. Background agents and the agents in background workspaces use the same hooks.
A background agent is a helper hidden from tabs, lists and attention. Every hook's agent.background and the agent.open.before request's background are true for one, so you can skip it without a lookup:
server.addHook("agent.turn.after", async ({ agent }) => {
if (agent.background) return; // A helper reports to the agent that created it.
await notifyTeam(agent);
});
background is fixed when the agent is created and a hook cannot change it. An agent created in a background workspace without background: true reads false. Hosts older than 0.16.0 omit the field, so it reads as undefined.
Ordering and returned values
Creation request
→ agent.create.before hooks (plugin-ID order; registration order within each plugin)
→ resolve defaults and validate provider configuration
→ derive launch configuration with Paseo runtime tools and daemon prompt
→ agent.open.before hooks (same ordering; env and plugin-local tools and MCP servers)
→ set PASEO_AGENT_ID, PASEO_AGENT_CWD, and PASEO_WORKSPACE_ID when the agent has a workspace
→ open provider session and save agent configuration
| Callback returns | Next callback receives |
|---|---|
{ ...request, env: { ...request.env, REGION: "eu" } } |
Prior request with REGION added/replaced |
{ ...request, env: { REGION: "eu" } } |
Prior request with the entire override map replaced |
undefined |
Unchanged request |
| Throws or returns invalid data | Operation fails; later callbacks do not run |
There is no automatic deep merge. env accumulates across plugins; tools and mcpServers
accumulate only across callbacks within the same plugin. Returning a replacement map or array
replaces that scope's prior value.
Context and cleanup
| Contract | Behavior |
|---|---|
context.paseo |
Existing SDK connected to this daemon |
context.signal |
Aborted on invocation timeout or plugin stop; pass to external requests |
| Input data | Detached snapshot; change state through returned requests or SDK commands |
| Registration result | Idempotent remover, e.g. const remove = server.addHook(...); remove(); |
| Reload, disable, removal, shutdown | Remaining registrations removed |
| Unknown hook name | Registration fails |
| Hook timeout | 30 seconds; aborts the signal. A waiting hook fails the pending operation; a notification handler logs an error. |
| Event-handler error | Logged against plugin; original operation continues |
| Event delivery | Live, best effort; no replay, persistence, or automatic retry |
| Event concurrency | Different events may overlap; callback completion order is not guaranteed |
Complete examples
| Plugin | Includes |
|---|---|
| lifecycle-logger | Agent, workspace, and worktree hooks; JSON logs with environment values redacted |
| lifecycle-actions | Follow-ups, permissions, environment, provider switching, worktree selection |
| agent-configuration | MCP injection and Codex sandbox/approval options |
| agent-tools | Label-targeted tools and file operations in the plugin process |
| worktrunk | Worktree manager (create, remove, restore) and agent activity markers |
Read logger output with paseo plugin logs lifecycle-logger or the host's daemon.log.
Renamed hooks
The old registration methods are deprecated for removal after 2027-04-30. Existing plugins keep their behavior. Mixed old and new registrations within a plugin run in registration order. addHook accepts only the new names.
| Old registration | New registration |
|---|---|
server.before("workspace.create", handler) |
server.addHook("workspace.create.before", asyncHandler) |
server.on("workspace.created", handler) |
server.addHook("workspace.create.after", asyncHandler) |
server.on("workspace.archived", handler) |
server.addHook("workspace.archive.after", asyncHandler) |
server.before("agent.create", handler) |
server.addHook("agent.create.before", asyncHandler) |
server.on("agent.created", handler) |
server.addHook("agent.create.after", asyncHandler) |
server.before("agent.session_open", handler) |
server.addHook("agent.open.before", asyncHandler) |
server.on("agent.closed", handler) |
server.addHook("agent.close.after", asyncHandler) |
server.on("agent.archived", handler) |
server.addHook("agent.archive.after", asyncHandler) |
server.on("agent.turn_started", handler) |
server.addHook("agent.turn.before", asyncHandler) |
server.on("agent.turn_ended", handler) |
server.addHook("agent.turn.after", asyncHandler) |
server.on("agent.permission_requested", handler) |
server.addHook("agent.permission.before", asyncHandler) |
server.on("agent.permission_resolved", handler) |
server.addHook("agent.permission.after", asyncHandler) |