What this thread does
Do first: Import AgentPlugin from @cline/sdk, return a named plugin object, and put callbacks under hooks.
Short answer
Use beforeRun for run start, beforeTool(context) for tool observation, and afterRun(context) for completion metrics. Register tools in setup(api, ctx) before the first model call.
The 2026-05-13 Cline SDK announcement describes the Cline 2.0 runtime split and runtime plugins for tools and lifecycle observation.
What to do
| Item | Value / action |
|---|---|
| Module | The guide uses github-plugin.ts; keep your plugin implementation in a TypeScript module. |
| Plugin shape | name, manifest.capabilities, setup(api, ctx), hooks; the guide declares capabilities ["tools", "hooks"]. |
| Run start | beforeRun(); use beforeRun or beforeModel when adjusting system prompt or context. |
| Tool observation | beforeTool(context) exposes context.toolCall.name and context.input. |
| Run usage | afterRun(context) reads context.result.usage, then inputTokens and outputTokens. |
| Tool registration | api.registerTool(...) belongs in synchronous, fast setup(), never a lifecycle callback. |
| Direct SDK loading | Pass the factory result in the plugins array of new Agent(...). |
| File loading | Default-export the plugin; pass its path in config.pluginPaths to ClineCore.start(...) after ClineCore.create(...). |
| Single-file installation | cline plugin install accepts a file URL; single-file imports are limited to Node builtins and @cline/*. |
| Package distribution | For npm dependencies, use a directory with package.json, a cline.plugins manifest, and runtime dependencies. Host-provided @cline/* imports belong in optional peerDependencies (peerDependenciesMeta with optional: true). |
Limits and open questions
Catch errors inside observational callbacks: an exception from beforeTool becomes a tool failure. The guide gives no lifecycle ordering guarantee, callback timeout, or minimum SDK package version. The GitHub example's issue filters and pagination are specific to that example, rather than hook settings.
Not for: Claude Code shell-command hooks.
Sources
Checked
2026-11-17; read Cline Writing Plugins guide; Cline SDK announcement by Renee Huang; no command was run.
Started from a post by @cline, packaged by the editor. Original post