:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(aio): share coding agent onboarding docs (#81653)
Manoel Aranda Neto208c1d1527e0
diff --git a/docs/onboarding/ai-observability/claude-code.tsx b/docs/onboarding/ai-observability/claude-code.tsxnew file mode 100644index 000000000000..464458d637a9--- /dev/null+++ b/docs/onboarding/ai-observability/claude-code.tsx@@ -0,0 +1,183 @@+import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'++import { StepDefinition } from '../steps'++export const getClaudeCodeSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {+ const { CodeBlock, Markdown, Blockquote, dedent } = ctx++ return [+ {+ title: 'Prerequisites',+ badge: 'required',+ content: (+ <>+ <Markdown>+ {dedent`+ [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview) is Anthropic's agentic coding tool that runs in your terminal. The [PostHog plugin](https://github.com/PostHog/ai-plugin) captures every Claude Code session as structured AI Observability events: generations, tool executions, and traces.++ This is useful for:++ - **Transparency and auditability:** See what Claude did in each session, including every tool call and LLM invocation.+ - **Cost tracking:** Monitor token usage and costs across your team.+ - **Team sharing:** Give your team visibility into coding sessions without sharing terminal access.+ - **Debugging:** Trace through multi-step agent runs to understand what happened.++ You need:++ - [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview) installed+ - A [PostHog account](https://app.posthog.com/signup) with a project token+ `}+ </Markdown>+ </>+ ),+ },+ {+ title: 'Install the PostHog plugin',+ badge: 'required',+ content: (+ <>+ <Markdown>Install the PostHog plugin for Claude Code:</Markdown>+ <CodeBlock+ language="bash"+ code={dedent`+ claude plugin install posthog+ `}+ />+ <Markdown>+ This adds a `SessionEnd` hook that parses your session logs and sends events to PostHog when+ each session finishes.+ </Markdown>+ </>+ ),+ },+ {+ title: 'Configure PostHog',+ badge: 'required',+ content: (+ <>+ <Markdown>+ Set environment variables with your PostHog project token and enable the integration. You can+ find your project token in your [PostHog project+ settings](https://app.posthog.com/settings/project).+ </Markdown>+ <CodeBlock+ language="bash"+ code={dedent`+ export POSTHOG_API_KEY="<ph_project_token>"+ export POSTHOG_LLMA_CC_ENABLED="true"+ `}+ />+ <Blockquote>+ <Markdown>+ **Tip:** Add these variables to your shell profile, such as `~/.zshrc` or `~/.bashrc`, so+ they persist across sessions.+ </Markdown>+ </Blockquote>+ <Markdown>+ Alternatively, configure them in your Claude Code settings file (`~/.claude/settings.json` or+ `.claude/settings.local.json`):+ </Markdown>+ <CodeBlock+ language="json"+ code={dedent`+ {+ "env": {+ "POSTHOG_API_KEY": "<ph_project_token>",+ "POSTHOG_LLMA_CC_ENABLED": "true"+ }+ }+ `}+ />+ <Markdown>If you use PostHog EU, set the host as well:</Markdown>+ <CodeBlock+ language="bash"+ code={dedent`+ export POSTHOG_HOST="https://eu.i.posthog.com"+ `}+ />+ </>+ ),+ },+ {+ title: 'Run a session',+ badge: 'required',+ content: (+ <>+ <Markdown>Start Claude Code as normal and use it for a task:</Markdown>+ <CodeBlock+ language="bash"+ code={dedent`+ claude+ `}+ />+ <Markdown>+ When the session ends, the plugin parses the session log file and sends events to PostHog. No+ changes to your workflow are needed.+ </Markdown>+ <Markdown>You can check the status of the last send from within Claude Code:</Markdown>+ <CodeBlock+ language="text"+ code={dedent`+ /posthog:llma-cc-status+ `}+ />+ </>+ ),+ },+ {+ title: 'Configuration options',+ badge: 'optional',+ content: (+ <>+ <Markdown>+ {dedent`+ All configuration is done with environment variables:++ | Variable | Default | Description |+ | --- | --- | --- |+ | \`POSTHOG_API_KEY\` | _(required)_ | Your PostHog project token |+ | \`POSTHOG_LLMA_CC_ENABLED\` | \`false\` | Set to \`true\` to enable the integration |+ | \`POSTHOG_HOST\` | \`https://us.i.posthog.com\` | PostHog ingestion host |+ | \`POSTHOG_LLMA_PRIVACY_MODE\` | \`false\` | When \`true\`, LLM input and output content is not sent to PostHog. Token counts, costs, latency, and model metadata are still captured. |+ | \`POSTHOG_LLMA_DISTINCT_ID\` | git user email | Distinct ID for events. Falls back to \`claude-code:{session_id}\` if no git email is found. |+ | \`POSTHOG_LLMA_TRACE_GROUPING\` | \`session\` | \`session\`: one trace per Claude Code session. \`message\`: one trace per user prompt. |+ | \`POSTHOG_LLMA_MAX_ATTRIBUTE_LENGTH\` | \`12000\` | Maximum character length for serialized tool input and output attributes |++ ### Trace grouping modes++ - **\`session\` (default):** All generations and tool executions within a Claude Code session are grouped into one trace. Use this to understand complete coding sessions.+ - **\`message\`:** Each user prompt creates a separate trace. Multiple LLM turns within one prompt, including tool-use loops, are grouped under the same trace. Use this to analyze individual interactions.++ ### Privacy mode++ When \`POSTHOG_LLMA_PRIVACY_MODE=true\`, all LLM input and output content, user prompts, tool inputs, and tool outputs are redacted. Token counts, costs, latency, and model metadata are still captured without exposing code or conversations.++ ### Ingest past sessions++ To send data from Claude Code sessions that happened before you installed the plugin, use the ingestion command below.+ `}+ </Markdown>+ <CodeBlock+ language="text"+ code={dedent`+ /posthog:llma-cc-ingest+ `}+ />+ <Markdown>+ {dedent`+ ### What gets captured++ The plugin captures three types of events:++ - **\`$ai_generation\`:** Each LLM call, including model, provider, token usage (input, output, cache read, and cache creation), stop reason, and input and output messages in [OpenAI chat format](https://posthog.com/docs/ai-observability/generations).+ - **\`$ai_span\`:** Each tool execution (Bash, Read, Write, Edit, Grep, Glob, MCP tools, and others), including tool name, input parameters, output result, duration, and error information. [Learn more about spans](https://posthog.com/docs/ai-observability/spans).+ - **\`$ai_trace\`:** Completed sessions or prompts, depending on grouping mode, with aggregated token totals and latency. [Learn more about traces](https://posthog.com/docs/ai-observability/traces).+ `}+ </Markdown>+ </>+ ),+ },+ ]+}++export const ClaudeCodeInstallation = createInstallation(getClaudeCodeSteps)diff --git a/docs/onboarding/ai-observability/openclaw.tsx b/docs/onboarding/ai-observability/openclaw.tsxnew file mode 100644index 000000000000..77effdd4dc2d--- /dev/null+++ b/docs/onboarding/ai-observability/openclaw.tsx@@ -0,0 +1,140 @@+import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'++import { StepDefinition } from '../steps'++export const getOpenClawSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {+ const { CodeBlock, Markdown, Blockquote, dedent } = ctx++ return [+ {+ title: 'Prerequisites',+ badge: 'required',+ content: (+ <Markdown>+ {dedent`+ [OpenClaw](https://github.com/openclaw/openclaw) is a self-hosted AI assistant gateway that connects messaging platforms such as Telegram, Slack, Discord, and WebChat to AI models. The [\`@posthog/openclaw\`](https://github.com/PostHog/posthog-openclaw) plugin captures LLM generations, tool executions, and conversation traces as \`$ai_generation\`, \`$ai_span\`, and \`$ai_trace\` events.++ You need:++ - A running [OpenClaw](https://github.com/openclaw/openclaw) gateway. The PostHog plugin supports Node.js 20 or later.+ - A [PostHog account](https://app.posthog.com/signup) with a project token.+ `}+ </Markdown>+ ),+ },+ {+ title: 'Install the PostHog plugin',+ badge: 'required',+ content: (+ <>+ <Markdown>+ Install the [`@posthog/openclaw`](https://github.com/PostHog/posthog-openclaw) plugin with the+ OpenClaw CLI:+ </Markdown>+ <CodeBlock+ language="bash"+ code={dedent`+ openclaw plugins install @posthog/openclaw+ `}+ />+ </>+ ),+ },+ {+ title: 'Configure the plugin',+ badge: 'required',+ content: (+ <>+ <Markdown>+ Add the PostHog plugin to your OpenClaw config file (`~/.openclaw/openclaw.json` or+ `openclaw.yaml`):+ </Markdown>+ <CodeBlock+ language="json"+ code={dedent`+ {+ "plugins": {+ "entries": {+ "posthog": {+ "enabled": true,+ "config": {+ "apiKey": "<ph_project_token>",+ "host": "<ph_client_api_host>"+ }+ }+ }+ },+ "diagnostics": {+ "enabled": true+ }+ }+ `}+ />+ <Markdown>+ You can find your project token and host in your [PostHog project+ settings](https://app.posthog.com/settings/project).+ </Markdown>+ <Blockquote>+ <Markdown>+ **Note:** `diagnostics.enabled` must be `true` to capture trace-level (`$ai_trace`) events.+ Generation and span events work without it.+ </Markdown>+ </Blockquote>+ </>+ ),+ },+ {+ title: 'Start the gateway',+ badge: 'required',+ content: (+ <>+ <Markdown>Start or restart the OpenClaw gateway for the plugin to take effect:</Markdown>+ <CodeBlock+ language="bash"+ code={dedent`+ node openclaw.mjs gateway+ `}+ />+ <Markdown>+ The PostHog plugin initializes on startup. When users send messages through a connected channel,+ AI Observability events are captured and sent to PostHog.+ </Markdown>+ </>+ ),+ },+ {+ title: 'Configuration options',+ badge: 'optional',+ content: (+ <Markdown>+ {dedent`+ All options go under the \`config\` key inside the \`posthog\` plugin entry:++ | Option | Type | Default | Description |+ | --- | --- | --- | --- |+ | \`apiKey\` | \`string\` | _(required)_ | Your PostHog project token |+ | \`host\` | \`string\` | \`https://us.i.posthog.com\` | PostHog ingestion host |+ | \`privacyMode\` | \`boolean\` | \`false\` | When enabled, message content is not sent to PostHog. Token counts, latency, model information, and errors are still captured. |+ | \`traceGrouping\` | \`"message"\` or \`"session"\` | \`"message"\` | \`"message"\`: one trace per LLM call cycle. \`"session"\`: groups all generations in a conversation into one trace. |+ | \`sessionWindowMinutes\` | \`number\` | \`60\` | Minutes of inactivity before starting a new session window. Applies in both trace grouping modes. |++ ### Trace grouping modes++ - **\`"message"\` (default):** Each agent invocation gets its own trace. Tool-use iterations within one invocation share the same trace.+ - **\`"session"\`:** All generations within a conversation window are grouped into one trace. A new trace starts after \`sessionWindowMinutes\` of inactivity. Use this for chat channels where per-message traces fragment conversation flow.++ ### What gets captured++ The plugin captures three types of events:++ - **\`$ai_generation\`:** Each LLM call, including model, provider, token usage, cost, latency, and input and output messages in [OpenAI chat format](https://posthog.com/docs/ai-observability/generations).+ - **\`$ai_span\`:** Each tool execution, including tool name, input parameters, output result, duration, and parent generation. [Learn more about spans](https://posthog.com/docs/ai-observability/spans).+ - **\`$ai_trace\`:** Completed message cycles with aggregated token totals and latency. [Learn more about traces](https://posthog.com/docs/ai-observability/traces).+ `}+ </Markdown>+ ),+ },+ ]+}++export const OpenClawInstallation = createInstallation(getOpenClawSteps)diff --git a/docs/onboarding/ai-observability/opencode.tsx b/docs/onboarding/ai-observability/opencode.tsxnew file mode 100644index 000000000000..9873d2cd91e7--- /dev/null+++ b/docs/onboarding/ai-observability/opencode.tsx@@ -0,0 +1,132 @@+import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'++import { StepDefinition } from '../steps'++export const getOpenCodeSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {+ const { CodeBlock, Markdown, Blockquote, dedent } = ctx++ return [+ {+ title: 'Prerequisites',+ badge: 'required',+ content: (+ <Markdown>+ {dedent`+ [OpenCode](https://opencode.ai) is an open-source AI coding agent that runs in your terminal. The [\`@posthog/opencode\`](https://github.com/PostHog/posthog-opencode) plugin captures LLM generations, tool executions, and conversation traces as \`$ai_generation\`, \`$ai_span\`, and \`$ai_trace\` events and sends them to PostHog.++ You need:++ - [OpenCode](https://opencode.ai/docs) installed+ - A [PostHog account](https://app.posthog.com/signup) with a project token+ `}+ </Markdown>+ ),+ },+ {+ title: 'Install the plugin',+ badge: 'required',+ content: (+ <>+ <Markdown>Add `@posthog/opencode` to the `plugin` array in your `opencode.json` file:</Markdown>+ <CodeBlock+ language="json"+ code={dedent`+ {+ "$schema": "https://opencode.ai/config.json",+ "plugin": ["@posthog/opencode"]+ }+ `}+ />+ <Markdown>+ Use `opencode.json` in your project root for a project-level install, or+ `~/.config/opencode/opencode.json` for a global install. OpenCode installs the package when it+ starts and caches it in `~/.cache/opencode/node_modules/`.+ </Markdown>+ </>+ ),+ },+ {+ title: 'Configure PostHog',+ badge: 'required',+ content: (+ <>+ <Markdown>+ Set environment variables with your PostHog project token and host. You can find both in your+ [PostHog project settings](https://app.posthog.com/settings/project).+ </Markdown>+ <CodeBlock+ language="bash"+ code={dedent`+ export POSTHOG_API_KEY="<ph_project_token>"+ export POSTHOG_HOST="<ph_client_api_host>"+ `}+ />+ <Blockquote>+ <Markdown>+ **Tip:** Add these variables to your shell profile, such as `~/.zshrc` or `~/.bashrc`, so+ they persist across sessions.+ </Markdown>+ </Blockquote>+ <Markdown>If `POSTHOG_API_KEY` is not set, the plugin does not capture or send events.</Markdown>+ </>+ ),+ },+ {+ title: 'Run a session',+ badge: 'required',+ content: (+ <>+ <Markdown>Start OpenCode as normal and use it for a task:</Markdown>+ <CodeBlock+ language="bash"+ code={dedent`+ opencode+ `}+ />+ <Markdown>+ The plugin initializes and captures events for each LLM call, tool execution, and completed+ prompt.+ </Markdown>+ </>+ ),+ },+ {+ title: 'Configuration options',+ badge: 'optional',+ content: (+ <Markdown>+ {dedent`+ Configure the plugin with environment variables:++ | Variable | Default | Description |+ | --- | --- | --- |+ | \`POSTHOG_API_KEY\` | _(required)_ | Your PostHog project token |+ | \`POSTHOG_HOST\` | \`https://us.i.posthog.com\` | PostHog ingestion host |+ | \`POSTHOG_PRIVACY_MODE\` | \`false\` | When \`true\`, the plugin does not send LLM content, prompts, or tool inputs and outputs. Token counts, costs, latency, and model metadata are still captured. |+ | \`POSTHOG_ENABLED\` | \`true\` | Set to \`false\` to disable the plugin |+ | \`POSTHOG_DISTINCT_ID\` | Machine hostname | Distinct ID included in all events |+ | \`POSTHOG_PROJECT_NAME\` | Current directory name | Project name included in all events |+ | \`POSTHOG_TAGS\` | _(none)_ | Custom tags added to all events in \`key1:val1,key2:val2\` format |+ | \`POSTHOG_MAX_ATTRIBUTE_LENGTH\` | \`12000\` | Maximum length for serialized tool input and output attributes |++ ### Privacy mode++ When \`POSTHOG_PRIVACY_MODE=true\`, all LLM content, user prompts, tool inputs, and tool outputs are redacted. Token counts, costs, latency, and model metadata are still captured.++ The plugin always redacts sensitive keys matching terms such as \`api_key\`, \`token\`, \`secret\`, \`password\`, \`authorization\`, \`credential\`, and \`private_key\`, regardless of privacy mode.++ ### What gets captured++ The plugin captures three types of events:++ - **\`$ai_generation\`:** Each LLM call, including model, provider, token usage, cost, stop reason, and input and output messages in [OpenAI chat format](https://posthog.com/docs/ai-observability/generations).+ - **\`$ai_span\`:** Each tool execution, including tool name, input parameters, output result, duration, parent generation, and error details. [Learn more about spans](https://posthog.com/docs/ai-observability/spans).+ - **\`$ai_trace\`:** Each completed prompt, including aggregated token totals, latency, input and output state, and error status. [Learn more about traces](https://posthog.com/docs/ai-observability/traces).+ `}+ </Markdown>+ ),+ },+ ]+}++export const OpenCodeInstallation = createInstallation(getOpenCodeSteps)diff --git a/docs/onboarding/ai-observability/pi.tsx b/docs/onboarding/ai-observability/pi.tsxnew file mode 100644index 000000000000..c4aeea84d9e1--- /dev/null+++ b/docs/onboarding/ai-observability/pi.tsx@@ -0,0 +1,129 @@+import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'++import { StepDefinition } from '../steps'++export const getPiSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {+ const { CodeBlock, Markdown, Blockquote, dedent } = ctx++ return [+ {+ title: 'Prerequisites',+ badge: 'required',+ content: (+ <Markdown>+ {dedent`+ [Pi](https://github.com/badlogic/pi-mono) is an open-source coding agent that runs in your terminal. The \`@posthog/pi\` extension captures LLM generations, tool executions, and conversation traces as \`$ai_generation\`, \`$ai_span\`, and \`$ai_trace\` events and sends them to PostHog.++ You need:++ - [Pi](https://github.com/badlogic/pi-mono) coding agent installed. The extension requires Node.js 22 or later.+ - A [PostHog account](https://app.posthog.com/signup) with a project token.+ `}+ </Markdown>+ ),+ },+ {+ title: 'Install the extension',+ badge: 'required',+ content: (+ <>+ <Markdown>Install the PostHog extension globally:</Markdown>+ <CodeBlock+ language="bash"+ code={dedent`+ pi install npm:@posthog/pi+ `}+ />+ <Markdown>Or install it for the current project:</Markdown>+ <CodeBlock+ language="bash"+ code={dedent`+ pi install -l npm:@posthog/pi+ `}+ />+ </>+ ),+ },+ {+ title: 'Configure PostHog',+ badge: 'required',+ content: (+ <>+ <Markdown>+ Set environment variables with your PostHog project token and host. You can find these in your+ [PostHog project settings](https://app.posthog.com/settings/project).+ </Markdown>+ <CodeBlock+ language="bash"+ code={dedent`+ export POSTHOG_API_KEY="<ph_project_token>"+ export POSTHOG_HOST="<ph_client_api_host>"+ `}+ />+ <Markdown>Then start Pi as normal:</Markdown>+ <CodeBlock+ language="bash"+ code={dedent`+ pi+ `}+ />+ <Markdown>+ The extension initializes and captures events for each LLM call, tool execution, and completed+ agent run.+ </Markdown>+ <Blockquote>+ <Markdown>+ **Tip:** Add these variables to your shell profile, such as `~/.zshrc` or `~/.bashrc`, so+ they persist across sessions.+ </Markdown>+ </Blockquote>+ </>+ ),+ },+ {+ title: 'Configuration options',+ badge: 'optional',+ content: (+ <Markdown>+ {dedent`+ Configure the extension with environment variables or a \`~/.pi/agent/posthog.json\` config file. Environment variables take precedence over config file values.++ | Variable | Default | Description |+ | --- | --- | --- |+ | \`POSTHOG_API_KEY\` | _(required)_ | Your PostHog project token |+ | \`POSTHOG_HOST\` | \`https://us.i.posthog.com\` | PostHog ingestion host |+ | \`POSTHOG_PRIVACY_MODE\` | \`false\` | When \`true\`, LLM input and output content is not sent to PostHog. Token counts, costs, latency, and model metadata are still captured. |+ | \`POSTHOG_ENABLED\` | \`true\` | Set to \`false\` to disable the extension |+ | \`POSTHOG_TRACE_GROUPING\` | \`message\` | \`message\`: one trace per user prompt. \`session\`: group all generations in a session into one trace. |+ | \`POSTHOG_SESSION_WINDOW_MINUTES\` | \`60\` | Minutes of inactivity before starting a new session window |+ | \`POSTHOG_PROJECT_NAME\` | Current directory name | Project name included in all events |+ | \`POSTHOG_AGENT_NAME\` | Agent name | Agent name. Defaults to the project name and detects subagent names when available. |+ | \`POSTHOG_TAGS\` | _(none)_ | Custom tags added to all events in \`key1:val1,key2:val2\` format |+ | \`POSTHOG_MAX_ATTRIBUTE_LENGTH\` | \`12000\` | Maximum length for serialized tool input and output attributes |++ ### Trace grouping modes++ - **\`message\` (default):** Each user prompt creates a new trace. Multiple LLM turns within one prompt, including tool-use loops, are grouped under the same trace.+ - **\`session\`:** All generations within a session window are grouped into one trace. A new trace starts after \`POSTHOG_SESSION_WINDOW_MINUTES\` of inactivity.++ ### Privacy mode++ When \`POSTHOG_PRIVACY_MODE=true\`, all LLM input and output content, user prompts, tool inputs, and tool outputs are redacted. Token counts, costs, latency, and model metadata are still captured.++ Even with privacy mode off, sensitive keys in tool inputs and outputs, such as \`api_key\`, \`token\`, \`secret\`, \`password\`, and \`authorization\`, are redacted.++ ### What gets captured++ The extension captures three types of events:++ - **\`$ai_generation\`:** Each LLM call, including model, provider, token usage, cost, latency, and input and output messages in [OpenAI chat format](https://posthog.com/docs/ai-observability/generations).+ - **\`$ai_span\`:** Each tool execution (read, write, edit, bash, and others), including tool name, input parameters, output result, and duration. [Learn more about spans](https://posthog.com/docs/ai-observability/spans).+ - **\`$ai_trace\`:** Completed agent runs with aggregated token totals and latency. [Learn more about traces](https://posthog.com/docs/ai-observability/traces).+ `}+ </Markdown>+ ),+ },+ ]+}++export const PiInstallation = createInstallation(getPiSteps)