opencode-posthog-observabilityOpenCode plugin that sends AI observability telemetry to PostHog.
0
50
9 in 7 days
28.5
Multi-signal model
1 month ago
2026-07-08
Install and configure
opencode.jsonWrites to this project's opencode.json — applies to this repository only.
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-posthog-observability@0.1.5"]
}Writes to ~/.config/opencode/opencode.json — applies to every project.
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-posthog-observability@0.1.5"]
}If you want to modify the plugin locally, install it into the project and reference the local path.
shell
pnpm add -D opencode-posthog-observabilityopencode loads npm dependencies through its embedded runtime on startup and caches them locally — no manual global install needed.
OpenCode plugin that sends AI generation telemetry to PostHog AI Observability.
Each completed OpenCode assistant message is captured as one PostHog $ai_generation event. Completed and failed OpenCode tool calls are captured as child $ai_span events. The plugin keeps each generation as its own trace while grouping related turns with the OpenCode session ID.
Install
npm install opencode-posthog-observability
Add the plugin to opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-posthog-observability"]
}
Set your PostHog project token:
export OPENCODE_POSTHOG_PROJECT_TOKEN=phc_your_project_token
For EU projects, set:
export OPENCODE_POSTHOG_HOST=https://eu.i.posthog.com
Configuration
The plugin reads config from the first file it finds:
OPENCODE_POSTHOG_CONFIG.opencode/posthog-observability.json.opencode/posthog-observability.jsonc.opencode/opencode-posthog-observability.json.opencode/opencode-posthog-observability.jsonc- matching files in your global OpenCode config directory
Example:
{
"projectToken": "phc_your_project_token",
"host": "https://us.i.posthog.com",
"distinctId": "opencode",
"projectName": "my-project",
"agentName": "opencode",
"captureInputs": true,
"captureOutputs": true,
"captureMetadata": true,
"maxTextLength": 12000,
"diagnostics": false,
"tags": {
"env": "local"
}
}
Environment variables override file config:
OPENCODE_POSTHOG_PROJECT_TOKENorPOSTHOG_PROJECT_TOKENOPENCODE_POSTHOG_HOSTOPENCODE_POSTHOG_DISTINCT_IDOPENCODE_POSTHOG_AGENT_NAMEOPENCODE_POSTHOG_PROJECT_NAMEOPENCODE_POSTHOG_CAPTURE_INPUTSOPENCODE_POSTHOG_CAPTURE_OUTPUTSOPENCODE_POSTHOG_CAPTURE_METADATAOPENCODE_POSTHOG_MAX_TEXT_LENGTHOPENCODE_POSTHOG_DIAGNOSTICSOPENCODE_POSTHOG_FLUSH_TIMEOUT_MSOPENCODE_POSTHOG_TAGSaskey=value,team=aior JSON
Privacy
By default, the plugin captures prompt input, assistant output, tool input/output, model/provider metadata, token counts, latency, OpenCode session/message/tool IDs, and configured tags.
When OpenCode exposes reasoning separately from the final answer, reasoning is sent as its own output entry before the assistant response. This keeps PostHog's conversation view readable without discarding reasoning content.
Disable sensitive content capture when needed:
export OPENCODE_POSTHOG_CAPTURE_INPUTS=false
export OPENCODE_POSTHOG_CAPTURE_OUTPUTS=false
The plugin redacts common secret-looking object keys before sending metadata or prompt inputs: token, secret, password, authorization, cookie, apiKey, and bearer.
Development
npm install
npm test
For local OpenCode tests before publishing:
npm pack
npm install ./opencode-posthog-observability-0.1.0.tgz --prefix .opencode
Then point local .opencode/opencode.json at the installed artifact:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["./node_modules/opencode-posthog-observability/dist/index.js"]
}