Skip to main content

Contexts

Handlers take a context, not positional arguments. Whatever your handler needs from the host, it reaches through ctx.

The base surface

ContextBase is what every handler gets:

ctx.ai              sessions, agents, streaming
ctx.workbench       applyLayout · createStatusBarItem · open
ctx.workspace       the open workspace
ctx.terminal        integrated terminals and terminal agents
ctx.media           media
ctx.system          host system surface
ctx.state           this mod's state
ctx.hooks           interception
ctx.permissions     what this mod is allowed to do
ctx.logger          structured logging
ctx.modId           this mod's id

ctx.emit()          publish one of your declared events
ctx.on()            subscribe to an event
ctx.action()        invoke a governed host action
ctx.listActions()       ctx.describeAction()
ctx.listEvents()        ctx.describeEvent()
ctx.subscribeActionTraces()   ctx.completedActionTraces

The last block is the interesting one. See Connections. Discovery methods like listActions only make sense because actions and events have owners other than you.

ctx.terminal is also a connection to host-owned resources. It can discover every integrated terminal, borrow one with explicit authority, or run a provider-native terminal agent.

The wider contexts

Two handler kinds receive more than the base:

ContextGiven to
ViewContextview components
ToolContexttool handlers

Logging

Use ctx.logger. It is the injected host logger, so its output lands where the host collects it. A module-level console.log does not.