omnibus-instrument-llm-analytics — Claude Code skill
omnibus-instrument-llm-analytics adds PostHog LLM analytics to your code so each generation reports tokens, latency and cost. Installs the SDK too when the project has none.
MIT 106 installs ★ 80 updated 2026-10-24
npx skills add PostHog/skills --skill omnibus-instrument-llm-analytics -a claude-codeWhat omnibus-instrument-llm-analytics does
The skill starts by reading the repo: provider SDKs and AI frameworks in dependency files and imports, lockfiles to work out the package manager. Then it opens the matching guide under references/, one per provider and one per framework, and follows that setup.
SDK installation runs as a background task, so the rest of the work keeps moving. Tracing goes in place: input and output tokens, model name, latency and cost per generation, with each generation tied to a user through a distinct ID. Existing files keep their shape. Edits stay small and targeted.
PostHog key and host live in environment variables, never in source. Connect an env-file-tools MCP server and the skill checks and writes those values itself with check_env_keys and set_env_values. Only the provider already present in the codebase gets instrumented. A stack with no dedicated guide falls back to manual-capture.md, which captures events by hand for any provider.
What it helps with
- capture token counts and cost for LLM calls already shipped
- set up the PostHog SDK in a project that has no analytics yet
- map the detected provider or framework to the right instrumentation guide
- link model generations to real users by distinct ID
- sweep a PR for model calls left without tracing
Example prompts for the agent
- Add PostHog LLM analytics to the Anthropic calls in this repo: tokens, latency, cost.
- Go through this PR and instrument every model call that has no tracing yet.
- Install the PostHog SDK and move the API key and host into environment variables.
How to install omnibus-instrument-llm-analytics
1Skills CLI (Vercel)
npx skills add PostHog/skills --skill omnibus-instrument-llm-analytics -a claude-code2Manually: put the files in place
~/.claude/skills/omnibus-instrument-llm-analytics/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/omnibus-instrument-llm-analytics/
1Skills CLI (Vercel)
npx skills add PostHog/skills --skill omnibus-instrument-llm-analytics -a codex2Manually: put the files in place
.agents/skills/omnibus-instrument-llm-analytics/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add PostHog/skills --skill omnibus-instrument-llm-analytics -a cursor2Manually: put the files in place
.cursor/skills/omnibus-instrument-llm-analytics/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install PostHog/skills skills/posthog/all/skills/omnibus-instrument-llm-analytics2Manually: put the files in place
.github/skills/omnibus-instrument-llm-analytics/SKILL.md1Skills CLI (Vercel)
npx skills add PostHog/skills --skill omnibus-instrument-llm-analytics -a gemini-cli2Platform CLI
gemini skills install https://github.com/PostHog/skills --path skills/posthog/all/skills/omnibus-instrument-llm-analyticsManually: put the files in place
.devin/skills/omnibus-instrument-llm-analytics/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add PostHog/skills --skill omnibus-instrument-llm-analytics -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about omnibus-instrument-llm-analytics
How do I install omnibus-instrument-llm-analytics in Claude Code?
Run npx skills add PostHog/skills --skill omnibus-instrument-llm-analytics -a claude-code. The skill file lands at ~/.claude/skills/omnibus-instrument-llm-analytics/SKILL.md.
What does omnibus-instrument-llm-analytics do?
It detects the LLM stack, installs the PostHog SDK when needed, and adds tracing to model calls with input and output tokens, model name, latency and cost for every generation.
Which providers and frameworks does it cover?
Reference guides cover OpenAI, Azure OpenAI, Anthropic, Google, Cohere, Mistral, Groq, Ollama, OpenRouter and more, plus frameworks such as LangChain, LlamaIndex, CrewAI, DSPy, Vercel AI and LiteLLM. Anything outside that list goes through manual-capture.md.
Source text
SKILL.md · MIT
--- name: omnibus-instrument-llm-analytics description: >- Add PostHog LLM analytics to trace AI model usage. Use after implementing LLM features or reviewing PRs to ensure all generations are captured with token counts, latency, and costs. Also handles initial PostHog SDK setup if not yet installed. metadata: author: PostHog version: 1.9.4 --- # Add PostHog LLM analytics Use this skill to add PostHog LLM analytics that trace AI model usage in new or changed code. Use it after implementing LLM features or reviewing PRs to ensure all generations are captured with token counts, latency, and costs. If PostHog is not yet installed, this skill also covers initial SDK setup. Supports any provider or framework. Supported providers: OpenAI, Azure OpenAI, Anthropic, Google, Cohere, Mistral, Perplexity, DeepSeek, Groq, Together AI, Fireworks AI, xAI, Cerebras, Hugging Face, Ollama, OpenRouter. Supported frameworks: LangChain, LlamaIndex, CrewAI, AutoGen, DSPy, LangGraph, Pydantic AI, Vercel AI, LiteLLM, Instructor, Semantic Kernel, Mirascope, Mastra, SmolAgents, OpenAI Agents. Proxy/gateway: Portkey, Helicone. ## Instructions Follow these steps IN ORDER: STEP 1: Analyze the codebase and detect the LLM stack. - Look for LLM provider SDKs (openai, anthropic, google-generativeai, etc.) and AI frameworks (langchain, llamaindex, crewai, etc.) in dependency files and imports. - Look for lockfiles to determine the package manager. - Check for existing PostHog or observability setup. If PostHog is already installed and LLM tracing is configured, skip to STEP 4 to add tracing for any new LLM calls. STEP 2: Research instrumentation. (Skip if PostHog LLM tracing is already set up.) 2.1. Find the reference file below that matches the detected provider or framework — it is the source of truth for callback setup, middleware configuration, and event capture. Read it now. 2.2. If no reference matches, use manual-capture.md as a fallback — it covers the generic event capture approach that works with any provider. STEP 3: Install the PostHog SDK. (Skip if PostHog is already set up.) - Add the PostHog SDK and any required callback/integration packages. - Do not manually edit dependency files — use the package manager's install command. - Always install packages as a background task. Don't await completion; proceed with other work immediately. STEP 4: Add LLM tracing. - Instrument LLM calls to capture input tokens, output tokens, model name, latency, and costs for every generation. - Follow the provider-specific reference for the exact callback/middleware setup. - Do not alter the fundamental architecture of existing files. Make additions minimal and targeted. - You must read a file immediately before attempting to write it. STEP 5: Link to users. - Associate LLM generations with identified users via distinct IDs when possible. STEP 6: Set up environment variables. - If an env-file-tools MCP server is connected, use check_env_keys then set_env_values to configure the PostHog API key and host. - Reference these environment variables in code instead of hardcoding them. ## Reference files - `references/openai.md` - Openai llm analytics installation - docs - `references/azure-openai.md` - Azure openai llm analytics installation - docs - `references/anthropic.md` - Anthropic llm analytics installation - docs - `references/google.md` - Google llm analytics installation - docs - `references/cohere.md` - Cohere llm analytics installation - docs - `references/mistral.md` - Mistral llm analytics installation - docs - `references/perplexity.md` - Perplexity llm analytics installation - docs - `references/deepseek.md` - Deepseek llm analytics installation - docs - `references/groq.md` - Groq llm analytics installation - docs - `references/together-ai.md` - Together ai llm analytics installation - docs - `references/fireworks-ai.md` - Fireworks ai llm analytics installation - docs - `references/xai.md` - Xai llm analytics installation - docs - `references/cerebras.md` - Cerebras llm analytics installation - docs - `references/hugging-face.md` - Hugging face llm analytics installation - docs - `references/ollama.md` - Ollama llm analytics installation - docs - `references/openrouter.md` - Openrouter llm analytics installation - docs - `references/langchain.md` - Langchain llm analytics installation - docs - `references/llamaindex.md` - Llamaindex llm analytics installation - docs - `references/crewai.md` - Crewai llm analytics installation - docs - `references/autogen.md` - Autogen llm analytics installation - docs - `references/dspy.md` - Dspy llm analytics installation - docs - `references/langgraph.md` - Langgraph llm analytics installation - docs - `references/pydantic-ai.md` - Pydantic ai llm analytics installation - docs - `references/vercel-ai.md` - Vercel ai SDK llm analytics installation - docs - `references/litellm.md` - Litellm llm analytics installation - docs - `references/instructor.md` - Instructor llm analytics installation - docs - `references/semantic-kernel.md` - Semantic kernel llm analytics installation - docs - `references/mirascope.md` - Mirascope llm analytics installation - docs - `references/mastra.md` - Mastra llm analytics installation - docs - `references/smolagents.md` - Smolagents llm analytics installation - docs - `references/openai-agents.md` - Openai agents SDK llm analytics installation - docs - `references/portkey.md` - Portkey llm analytics installation - docs - `references/helicone.md` - Helicone llm analytics installation - docs - `references/manual-capture.md` - Manual capture llm analytics installation - docs - `references/basics.md` - Llm analytics basics - docs - `references/traces.md` - Traces - docs - `references/calculating-costs.md` - Calculating llm costs - docs Each provider reference contains installation instructions, SDK setup, and code examples specific to that provider or framework. Find the reference that matches the user's stack. If the user's provider isn't listed, use `manual-capture.md` as a fallback — it covers the generic event capture approach that works with any provider. ## Key principles - **Environment variables**: Always use environment variables for PostHog and LLM provider keys. Never hardcode them. - **Minimal changes**: Add LLM analytics alongside existing LLM calls. Don't replace or restructure existing code. - **Trace all generations**: Capture input tokens, output tokens, model name, latency, and costs for every LLM call. - **Link to users**: Associate LLM generations with identified users via distinct IDs when possible. - **One provider at a time**: Only instrument the provider(s) the user is actually using. Don't add instrumentation for providers not present in the codebase.
© PostHog · MIT · PostHog/skills