Hooks run inside the agent harness at fixed points whether or not the model asks, so you can enforce guardrails and audit logs that an Model Context Protocol (MCP)A published agreement for an AI application to discover what a separate program offers and ask it to run one of those offerings.Full definition → tool cannot guarantee. The post shows how to wire this up in Cline.
Key takeaways · AI-distilled
In Cline, a plugin is a single object attached to the agent harness that can wrap tools, providers, message rewriters, automations or hooks, and the same plugin works across the CLI, VS Code, JetBrains and the SDK.
Its example beforeTool agent hookA script the harness runs automatically at a fixed point in an agent's loop — before a tool call, after an edit, on session start.Full definition → matches Terminal and shellA text interface for navigating files and running programs.Full definition → commands against regexes such as rm -rf, forced Git and version controlA system for recording and comparing changes to a codebase.Full definition → push, mkfs and dd, and returns skip with a reason, so the agent reports the block instead of running the command.
A beforeRun/afterRun pair can journal each run to a JSONL file with duration, status, iterations, token counts and cost. The author notes afterRun also fires for failed or aborted runs, so the hook should record status rather than assume success.
Cline exposes seven hooks: beforeRun/afterRun, beforeTool/afterTool, beforeModel/afterModel and onEvent. Suggested uses include redacting secrets in beforeModel and streaming live progress through onEvent.
Terms in this piece · Glossary
Model Context Protocol (MCP) — A published agreement for an AI application to discover what a separate program offers and ask it to run one of those offerings.
agent hook — A script the harness runs automatically at a fixed point in an agent's loop — before a tool call, after an edit, on session start.
Terminal and shell — A text interface for navigating files and running programs.