lainra/claude-code-telemetry
Claude Code Telemetry is a lightweight bridge that captures telemetry data from Claude Code and forwards it to Langfuse for visualization, with a secure local turnkey installation under a minute.
Claude Code Telemetry ๐
See exactly how you/your team uses Claude Code
Track costs, usage patterns, and session data in real-time
https://github.com/user-attachments/assets/2634cec3-94af-4a2d-90da-44cd641f1746
๐ฏ What This Actually Does
Claude Code Telemetry is a lightweight bridge that captures telemetry data from Claude Code and forwards it to Langfuse for visualization. You get:
- ๐ฐ Cost Tracking - See costs per session, user, and model
- ๐ Usage Metrics - Token counts, cache hits, and tool usage
- โฑ๏ธ Session Grouping - Automatically groups work into 1-hour sessions
- ๐ Full Transparency - Every API call logged with complete details
- ๐ Safe local data - The packaged self-hosted Langfuse keeps your data local
The original motivation from the author was that when using Claude Code Pro/Max, it didn't have good options for telemetry out of the box compared to API-based requests that can be integrated with various solutions and wanted to provide a secure turnkey local setup for people using Claude Code to benefit from.
๐๏ธ Built on Standards
Uses OpenTelemetry for data collection, Langfuse for visualization, and Claude's native observability APIs. No proprietary formats, no vendor lock-in.
๐ Quick Start (30 seconds)
Prerequisites
๐ณ Docker Desktop - Install here if you don't see the whale icon in your menu bar
Setup
# Clone and enter directory
git clone https://github.com/lainra/claude-code-telemetry && cd claude-code-telemetry
# Run automated setup
./quickstart.sh
# Enable telemetry
source claude-telemetry.env
# Test it works
claude "What is 2+2?"That's it! View your dashboard at http://localhost:3000
Need Help?
Let Claude guide you through the setup:
claude "Set up the telemetry dashboard"๐ธ What You'll See in Langfuse
Session View
Every conversation becomes a trackable session:
Session: 4:32 PM - 5:15 PM (43 minutes)
โโโ Total Cost: $18.43
โโโ API Calls: 6 (2 Haiku, 4 Opus)
โโโ Total Tokens: 45,231 (31,450 cached)
โโโ Tools Used:
โ โโโ Read: 23 calls
โ โโโ Edit: 8 calls
โ โโโ Bash: 4 calls
โ โโโ Grep: 2 calls
โโโ Cache Savings: $12.30 (40% cost reduction)
Individual API Calls
Full details for every Claude interaction:
4:45 PM - claude-3-opus-20240229
โโโ Input: 12,453 tokens (8,234 from cache)
โโโ Output: 3,221 tokens
โโโ Cost: $4.87
โโโ Duration: 3.2s
โโโ Context: Feature implementation
Cost Breakdown
Track spending by model and user:
Today's Usage:
โโโ Total: $67.43
โโโ By Model:
โ โโโ Opus: $61.20 (91%)
โ โโโ Haiku: $6.23 (9%)
โโโ By User:
โโโ alex@team.com: $28.90
โโโ sarah@team.com: $22.15
โโโ mike@team.com: $16.38
๐ง How It Works
Claude Code โ OpenTelemetry โ Telemetry Bridge โ Langfuse
โ โ โ โ
User asks Sends OTLP Parses & forwards Shows in
questions telemetry data to Langfuse dashboard
The bridge:
- Listens for OpenTelemetry data from Claude Code
- Enriches it with session context
- Forwards to Langfuse for visualization
- Groups related work into analyzable sessions
๐ What This Tool Is (and Isn't)
โ What It Does:
- Tracks costs - Know exactly what you're spending
- Shows usage patterns - See when and how Claude is used
- Groups work sessions - Understand complete tasks, not just individual calls
- Provides full transparency - Every token and dollar accounted for
- Runs locally - Your data stays on your infrastructure
โ What It Doesn't Do:
- Measure productivity - Can't tell if you're working faster
- Analyze code quality - Doesn't evaluate AI-generated code
- Provide strategic insights - Just shows raw data, not recommendations
- Enable team collaboration - No sharing or pattern discovery features
- Calculate ROI - You'll need to determine value yourself
๐ ๏ธ Installation Options
Option 1: Full Stack (Recommended)
Includes Langfuse dashboard + telemetry bridge:
./quickstart.shOption 2: Bridge Only (Manual w/NPM)
Already have Langfuse? Just run the bridge:
# Configure your existing Langfuse credentials
export LANGFUSE_PUBLIC_KEY=your-public-key
export LANGFUSE_SECRET_KEY=your-secret-key
export LANGFUSE_HOST=your-langfuse-url
# Install and start the bridge
npm install
npm startOption 3: Bridge Only (Docker)
Already have Langfuse? Run the bridge in Docker:
# Create .env file with your Langfuse credentials
cp .env.example .env
# Edit .env with your LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, and LANGFUSE_HOST
# Run just the telemetry bridge container
docker compose up telemetry-bridge๐ Requirements
- Docker Desktop (install) - For quickstart
- Claude Code CLI (
claude) - Node.js 18+ (optional) - For bridge-only mode
๐๏ธ Configuration
| Setting | Default | Description |
|---|---|---|
SESSION_TIMEOUT |
1 hour | Groups related work into sessions |
OTLP_RECEIVER_PORT |
4318 | OpenTelemetry standard port |
LANGFUSE_HOST |
http://localhost:3000 | Langfuse dashboard URL |
LOG_LEVEL |
info | Logging verbosity |
See .env.example for all options.
๐ Privacy & Security
- 100% Local - No external services unless you configure them
- No Code Storage - Only metadata about interactions
- You Control the Data - Runs on your infrastructure
- Optional Prompt Logging - Choose whether to log prompts
๐ Documentation
- Environment Variables - Complete configuration guide
- Telemetry Guide - Understanding the data format
๐ค Should You Use This?
Use this if you want to:
- Track Claude Code costs across your team
- Understand usage patterns and peak times
- Have transparency into AI tool spending
- Keep telemetry data on your own infrastructure
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
๐ License
MIT License - see LICENSE for details.
Simple, honest telemetry for Claude Code
100% AI-assisted repository, made with โค๏ธ by Claude and @lainra
Report Issue ยท
Submit PR