ExtensionAPI interface provides extensions with methods to interact with the agent, register tools and commands, and respond to events.
Import
Interface
Extensions receive theExtensionAPI through the ExtensionContext when they are initialized.
Methods
registerTool
Register a custom tool that the agent can invoke.ToolDefinition
required
registerCommand
Register a slash command that users can invoke.RegisteredCommand
required
on
Subscribe to extension events.string
required
Event type to subscribe to (e.g., “tool_call”, “session_start”)
function
required
Event handler function
agent_start/agent_end- Agent turn lifecycletool_call/tool_result- Tool invocationsession_start/session_shutdown- Session lifecyclesession_compact/session_fork/session_switch- Session operationsinput- User input eventsturn_start/turn_end- Turn boundaries
exec
Execute a bash command.string
required
The bash command to execute
ExecOptions
object
showDialog
Display a dialog to the user (TUI only).ExtensionUIDialogOptions
required
showWidget
Show a persistent widget in the footer (TUI only).ExtensionWidgetOptions
required
Example
ExtensionActions
TheExtensionActions interface provides methods for modifying agent state.