npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

opencode-posthog-observability

v0.1.5

Published

OpenCode plugin that sends AI observability telemetry to PostHog.

Downloads

310

Readme

opencode-posthog-observability

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_TOKEN or POSTHOG_PROJECT_TOKEN
  • OPENCODE_POSTHOG_HOST
  • OPENCODE_POSTHOG_DISTINCT_ID
  • OPENCODE_POSTHOG_AGENT_NAME
  • OPENCODE_POSTHOG_PROJECT_NAME
  • OPENCODE_POSTHOG_CAPTURE_INPUTS
  • OPENCODE_POSTHOG_CAPTURE_OUTPUTS
  • OPENCODE_POSTHOG_CAPTURE_METADATA
  • OPENCODE_POSTHOG_MAX_TEXT_LENGTH
  • OPENCODE_POSTHOG_DIAGNOSTICS
  • OPENCODE_POSTHOG_FLUSH_TIMEOUT_MS
  • OPENCODE_POSTHOG_TAGS as key=value,team=ai or 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"]
}