Plugin SDK & Hooks

Plugin SDK Overview

Learn how the Trenchcoat plugin collects telemetry from Claude Code sessions and sends it to the Trenchcoat API.

The Trenchcoat plugin runs inside Claude Code and captures telemetry as you work. It attaches to Claude Code's hook system, intercepts lifecycle events, and sends structured event batches to your Trenchcoat workspace — giving you full visibility into how your agents use tools, spawn subagents, and consume tokens.

How it works

The plugin operates entirely on your local machine. No data is captured or transmitted until you connect it to your Trenchcoat API key.

Claude Code session


 Hook fires (PreToolUse, PostToolUse, Stop, Notification)


 Plugin hook script runs (~/.claude/plugins/trenchcoat/hooks/)


 Event queued in local buffer


 Batch flushed (every 30s, or when buffer hits 50 events)


 POST /api/v1/events  →  Trenchcoat API  →  Supabase

The plugin never blocks Claude Code's execution. Hook scripts are fire-and-forget; failures are logged locally and retried on the next flush cycle.

What data is collected

CategoryEvents
Session lifecyclesession_start, session_end
Tool invocationstool_use, tool_result
Subagent activitysubagent_stop
Assistant outputassistant_stop

Each event carries a session_id (a UUID stable for the lifetime of a Claude Code session), a UTC timestamp, and an event-specific data payload. See Event Schema for the full field reference.

What you can do with this data

Once events are flowing into Trenchcoat, your dashboard shows:

  • Sessions — a timeline of every Claude Code session, with duration and cost
  • Tool usage — which tools fire most often, and which ones error
  • Token attribution — tokens broken down by component type (tools, subagents, assistant turns)
  • Cost — per-session and aggregate spend derived from model pricing

Supported platforms

PlatformStatus
Claude CodeSupported
Other MCP clientsPlanned
Custom agents (API)Planned

Multi-platform support is on the roadmap. If you are building a custom agent and want to send events directly, the API Reference documents the ingestion endpoint — the plugin is just a convenience wrapper around it.

Next steps

Follow the Installation guide to get the plugin running in under five minutes.

On this page