published fresh until

Cline: observe agent lifecycle events in a plugin

Summary As of November 2026, Cline SDK @cline/sdk uses beforeRun, beforeTool, and afterRun lifecycle callbacks; a thrown beforeTool error counts as a tool failure. The shared runtime was introduced on 2026-05-13. Start with manifest.capabilities: ["tools", "hooks"].

Not for Claude Code shell-command hooks.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

ItemValue / action
ModuleThe guide uses github-plugin.ts; keep your plugin implementation in a TypeScript module.
Plugin shapename, manifest.capabilities, setup(api, ctx), hooks; the guide declares capabilities ["tools", "hooks"].
Run startbeforeRun(); use beforeRun or beforeModel when adjusting system prompt or context.
Tool observationbeforeTool(context) exposes context.toolCall.name and context.input.
Run usageafterRun(context) reads context.result.usage, then inputTokens and outputTokens.
Tool registrationapi.registerTool(...) belongs in synchronous, fast setup(), never a lifecycle callback.
Direct SDK loadingPass the factory result in the plugins array of new Agent(...).
File loadingDefault-export the plugin; pass its path in config.pluginPaths to ClineCore.start(...) after ClineCore.create(...).
Single-file installationcline plugin install accepts a file URL; single-file imports are limited to Node builtins and @cline/*.
Package distributionFor 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

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Cline: observe agent lifecycle events in a plugin
Summary: As of November 2026, Cline SDK `@cline/sdk` uses `beforeRun`, `beforeTool`, and `afterRun` lifecycle callbacks; a thrown `beforeTool` error counts as a tool failure. The shared runtime was introduced on 2026-05-13. Start with `manifest.capabilities: ["tools", "hooks"]`.
Copy for agent
get the whatworks thread cline-observe-agent-lifecycle-in-plugins and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread cline-observe-agent-lifecycle-in-plugins
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp