Which moments a hook can attach to, and what it can do there. Event names link to each harness’s documentation. “Block”, “deny” and “modify” change what the agent does; “observe only” can watch but not intervene. Where hook files live is on the Locations page.
| Moment | OpenCode 2.xPlugin hooks and events |
|---|---|
| Hook types | Plugin hooks and events |
| Session and workspace | |
| Session starts | |
| Configuration changes | |
| Worktree is resolved | |
| Worktree updates | |
| Session details change | |
| Session status changes | |
| Session is viewed | |
| Session is moved | |
| Session goes idle | |
| Session is forked | |
| Session is deleted | |
| Server connects | |
| Server shuts down | |
| Prompt and turn | |
| User submits a prompt | |
| Message is queued | |
| Queued message delivery changes | |
| Queued message is delivered | |
| Queued message is cancelled | |
| Agent is selected | |
| Agent starts | |
| Model step starts | |
| Model step streams | |
| Model step ends | |
| Model step fails | |
| Skill is activated | |
| Turn is retried | |
| Turn is interrupted | |
| Turn fails | |
| Agent finishes its turn | session.experimental.idleundocumented add context 2.2.1+, experimental. Runs when a session finishes model work with no pending input, but not after an interruption, a failure or a manual compaction. Input the hook adds continues the same execution. It reports background shells, subagents and image jobs still running. The built-in /goal loop uses it. |
| Agent ends | |
| Tools | |
| Tool input starts streaming | |
| Tool input streams | |
| Tool input is complete | |
| Before a tool runs | |
| Tool execution starts | |
| Tool execution reports progress | |
| After a tool runs (any result) | |
| After a tool succeeds | |
| After a tool fails | |
| Permissions and questions | |
| Permission is requested | permission.evaluateallow, deny, ask user, annotate An explicitly configured deny is final and does not invoke the hook. |
| Permission is answered | |
| Session permissions change | |
| Form is shown to the user | |
| User submits a form | |
| User cancels a form | |
| Shell, terminals and files | |
| Before a shell command | shell.create.beforemodify, set environment Can change the command, working directory, timeout, shell and environment. |
| Shell command starts | |
| After a shell command | |
| Background shell is created | |
| Background shell exits | |
| Background shell is removed | |
| Terminal is created | |
| Terminal updates | |
| Terminal exits | |
| Terminal is removed | |
| Persistent terminal is added | |
| Persistent terminal is removed | |
| Watched file changes | |
| Revert is staged | |
| Revert is applied | |
| Staged revert is cleared | |
| Git branch changes | |
| MCP | |
| MCP server status changes | |
| MCP resources change | |
| Context and compaction | |
| Instructions are loaded | |
| Before context is sent to the model | |
| Before context is compacted | |
| Compaction streams | |
| After context is compacted | |
| Compaction fails | |
| Model and provider | |
| Model is selected | |
| Before provider headers are sent | |
| Before a provider request | session.generatemodify, replace session.http.requestmodify, replace |
| After a provider response | session.http.responsemodify, replace |
| Token usage updates | |
| Credentials change | |
| Active credential switches | |
| Provider list changes | |
| Model list changes | |
| Model catalog refreshes | |
| Integration changes | |
| Messages and interface | |
| Text starts streaming | |
| Text streams | |
| Text is complete | |
| Reasoning starts | |
| Reasoning streams | |
| Reasoning ends | |
| Synthetic message is added | |
| Text is added to the prompt | |
| Interface command runs | |
| Toast is shown | |
| Session is selected in the interface | |
| Plugins and configuration | |
| Plugin updates | |
| Project updates | |
| Agent list changes | |
| Command list changes | |
| Skill list changes | |
| References change | |
| Web search settings change | |
| Update is available | |
| Installation updates | |
| Definitions a plugin can edit | |
| Tool definitions | |
| Agent definitions | |
| Command definitions | |
| Skill definitions | |
| MCP server definitions | |
| Provider definitions | provider.transformmodify |
| Model definitions | model.transformmodify |
| Integration definitions | |
| Reference definitions | |
| Web search definitions | |
| Worktree definitions | |
| Version control definitions | |
Notes and sources
OpenCode 2.x
- @opencode/cli 2.x, checked at 2.0.28. 1.x plugins do not run in 2.x.
- Plugins register hooks per domain with ctx.<domain>.hook(name, callback); each callback receives one mutable event. Hooks run in plugin order.
- Transforms are synchronous edits to registered definitions, replayed in registration order.
- Events are read with ctx.event.subscribe() and can only be observed.
- 2.1 renames provider replay data to native across text/reasoning lifecycle, tool and step/compaction events. Tool result native shallow-merges into call native; execution state is unchanged. SessionCompactionResult.providerState becomes native. session.compacted is removed; subscribe to current compaction lifecycle events.
- 2.1 adds paginated ctx.session.list to both Effect and Promise plugin APIs.
- 2.2.0 source: event.subscribe({types}) filters events by registered type; unknown types warn and are ignored. Plugin reload activation is awaited before model-step context preparation. Session instruction entry mutations use ctx.session.instructions.entry.*, independently of hook callbacks. Experimental desktop GUI plugins use a separate Electron/main and app renderer loader; this is not a CLI/TUI rendering guarantee.
- 2.2.1 adds the experimental
experimental.idlesession hook (ctx.session.hook). Input added from it, such as a synthetic message, continues the same execution instead of letting the session go idle. The built-in /goal plugin is its first user. - 2.2.4+ schedule lifecycle, traced at 2.2.7: ServerProcess.start forks Schedule.run outside the optional managed lifecycle branch, including opencode serve/standalone servers. A SQLite lease elects one scheduler per database; experimental.schedules remains checked at fire time. This is a core background scheduler, not a new plugin hook event; no firing probe.
- Since 2.3.1, schedules become experimental automations: use experimental.automations (schedules remains an alias), /automation and automation_* tools. Triggers support time/interval/cron or MCP push events, with prompt or Code Mode actions. Event triggers also require mcp_events. Every server starts the automation loop. Migration keeps only active/paused plain-prompt schedules without conditions/run limits and with a next due time; it drops the old table. Prior schedule findings describe 2.2.x. No scheduler or migration runtime probe.
- In 2.4.0, automations use the top-level automations setting. Set it to false to disable timer, cron and MCP-event automations.
- OpenCode v2 plugin development, Documentation, checked 2026-10-15
- OpenCode 2.0.29 session hooks, Source code, checked 2026-10-15
- OpenCode 2.0.29 event union, Source code, checked 2026-10-15
- OpenCode 2.1.0 official release notes; snapshot retained in October 21 review, Documentation, checked 2026-10-21
- OpenCode v2.1.1: packages/schema/src/session-legacy.ts, Source code, checked 2026-10-21
- OpenCode 2.2.0: entry-host, Source code, checked 2026-10-28
- OpenCode 2.2.0: entry-runner, Source code, checked 2026-10-28
- OpenCode 2.2.0: gui-desktop, Source code, checked 2026-10-28
- OpenCode 2.2.0: gui-root, Source code, checked 2026-10-28
- OpenCode 2.2.2: packages/plugin/src/effect/session.ts, Source code, checked 2026-10-30
- OpenCode 2.2.2: packages/core/src/plugin/goal.ts, Source code, checked 2026-10-30
- opencode v2.2.7: packages/server/src/process.ts, Source code, checked 2026-11-12
- opencode v2.2.7: packages/core/src/schedule.ts, Source code, checked 2026-11-12
- opencode v2.2.7: packages/core/src/schedule.ts, Source code, checked 2026-11-12
- opencode v2.3.2: packages/server/src/process.ts, Source code, checked 2026-11-20
- opencode v2.3.2: packages/core/src/automation.ts, Source code, checked 2026-11-20
- opencode v2.3.2: packages/schema/src/automation.ts, Source code, checked 2026-11-20
- opencode v2.3.2: packages/core/src/database/migration/20261116043204_automation.ts, Source code, checked 2026-11-20
- opencode v2.3.2: packages/schema/src/config/flag.ts, Source code, checked 2026-11-20
- OpenCode 2.4.0 release notes, Documentation, checked 2026-11-24