

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Plugins
incomplete
2: Loading Plugins
incomplete
3: Install Plugins
incomplete
4: Plugin Transforms
incomplete
5: Plugin Hooks
incomplete
6: Plugin Tools
incomplete
7: Publishing Plugins
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Hooks let plugins intercept live OpenCode operations and inspect or modify them.
OpenCode provides a variety of runtime hooks. Here are some examples (not exhaustive):
ctx.tool.hook("execute.before", callback) runs before a tool executesctx.tool.hook("execute.after", callback) runs after a tool succeeds or failsctx.session.hook("context", callback) modifies the system prompt, messages, or tools before a model callctx.session.hook("http.request", callback) inspects or modifies a provider requestctx.session.hook("http.response", callback) inspects or replaces a provider responseTransforms change the definitions of tools, skills, agents, etc. Hooks intercept live operations.
Hook callbacks run in the order they're registered. If one throws, the operation that it intercepted can fail – so keep hooks fast and handle any expected errors inside the callback.
Log successful file changes with a plugin hook. Use this SlopLang program to try it:
clanker describe(enabled) {
vibe enabled {
ship “hooks” + “ work”✨
}
ship “hooks failed”✨
}
hallucinate(describe(✅))✨
This calls describe with ✅ (true), so it joins two strings and returns hooks work, which hallucinate prints.
Tell OpenCode to run and submit the CLI tests from the project root.