Skip to content

Latest commit

ย 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“Š Claude Code Monitor

Real-time telemetry monitoring and analytics for Claude Code sessions

Node.js OpenTelemetry License PRs Welcome

Track token usage, monitor costs, and analyze Claude Code performance with beautiful dashboards and comprehensive analytics.

๐Ÿš€ Quick Start โ€ข โœจ Features โ€ข ๐Ÿ“Š Dashboard โ€ข ๐Ÿ”ง Configuration โ€ข ๐Ÿ“ˆ Analytics


๐ŸŽฏ About

Claude Code Monitor is a comprehensive OpenTelemetry-based monitoring solution specifically designed to capture, store, and visualize Claude Code token usage and cost data in real-time. Whether you're a developer tracking API costs or a team analyzing AI tool usage patterns, this tool provides the insights you need.

๐ŸŒŸ Why Claude Code Monitor?

  • ๐Ÿ’ฐ Cost Transparency: Track exact token costs by model and session
  • ๐Ÿ“ˆ Usage Insights: Understand your Claude Code usage patterns over time
  • ๐Ÿ” Real-time Monitoring: See live token consumption as you work
  • ๐Ÿ“Š Rich Analytics: Comprehensive reports and trend analysis
  • ๐Ÿ›  Easy Integration: Seamless OpenTelemetry integration with minimal setup
  • ๐ŸŽจ Beautiful Dashboards: Interactive web interface with charts and visualizations

โœจ Features

๐Ÿš€ Core Capabilities

  • ๐Ÿ“ก Real-time Telemetry: Receives Claude Code metrics via OTLP protocol
  • ๐Ÿ’Ž Token Analytics: Track input, output, cache read/creation tokens
  • ๐Ÿ’ฐ Cost Tracking: Monitor spending across different AI models
  • ๐Ÿ“Š Interactive Dashboard: Beautiful web interface with real-time charts
  • ๐Ÿ“ˆ Prometheus Export: Industry-standard metrics for external monitoring
  • ๐Ÿ“‹ Usage Reports: Daily, weekly, and historical analysis
  • ๐Ÿ”„ Session Tracking: Monitor individual Claude Code sessions

๐ŸŽจ Dashboard Features

  • Real-time token distribution charts
  • Per-model cost breakdown
  • 30-day historical trends
  • Auto-refresh every 30 seconds
  • Responsive design for all devices

๐Ÿ“Š Analytics & Reporting

  • Daily usage summaries
  • Weekly trend analysis
  • Cost optimization insights
  • Token efficiency metrics
  • Session duration tracking

๐Ÿš€ Quick Start

1๏ธโƒฃ Install Dependencies

npm install

2๏ธโƒฃ Automatic Setup (Recommended)

./setup-claude-telemetry.sh
source ~/.bashrc  # or ~/.zshrc for zsh users

3๏ธโƒฃ Start Monitoring

# Start the OTLP receiver
npm run receiver

# In another terminal, start the web dashboard
npm run web

4๏ธโƒฃ Use Claude Code

Use Claude Code normally - tokens will be automatically tracked! ๐ŸŽ‰

๐Ÿ“Š Dashboard

Access your monitoring dashboard at:

Dashboard Screenshots

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  ๐Ÿ“Š Claude Code Usage Dashboard            โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Today's Stats          Token Distribution  โ”‚
โ”‚  โ€ข 1,234 Input         โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ 45%    โ”‚
โ”‚  โ€ข 2,567 Output        โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ 55%    โ”‚  
โ”‚  โ€ข 15,432 Cache Read   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ 89%    โ”‚
โ”‚  โ€ข 1,098 Cache Create  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ 11%    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  ๐Ÿ’ฐ Cost Breakdown     ๐Ÿ“ˆ 30-Day Trend     โ”‚
โ”‚  โ€ข Model A: $12.34     โ–ฒโ–ฒโ–ฒโ–ฒโ–ฒโ–ฒโ–ฒโ–ฒโ–ฒโ–ฒโ–ฒ       โ”‚
โ”‚  โ€ข Model B: $5.67      โ–ฒโ–ฒโ–ฒโ–ฒโ–ฒโ–ฒโ–ฒโ–ฒโ–ฒโ–ฒโ–ฒ       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ”ง Configuration

Manual Environment Setup

If you prefer manual configuration:

export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_METRICS_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
export OTEL_EXPORTER_OTLP_PROTOCOL=http/json

Environment Variables

Variable Default Description
CLAUDE_CODE_ENABLE_TELEMETRY 1 Enable Claude Code telemetry
OTEL_EXPORTER_OTLP_ENDPOINT http://localhost:4318 OTLP endpoint URL
OTEL_EXPORTER_OTLP_PROTOCOL http/json Protocol format
OTEL_EXPORTER_PROMETHEUS_PORT 9464 Prometheus metrics port

๐Ÿ›  Commands

Core Operations

npm run receiver     # ๐ŸŽฏ Start OTLP receiver for telemetry
npm run web         # ๐ŸŒ Launch web dashboard  
npm run monitor     # ๐Ÿ“Š Start Prometheus metrics export

Analytics & Reports

npm run report           # ๐Ÿ“‹ Generate comprehensive usage report
npm run report daily     # ๐Ÿ“… Today's detailed usage
npm run report weekly    # ๐Ÿ“ˆ Weekly summary and trends

Development & Testing

npm run test-data       # ๐Ÿงช Generate sample test data
npm run test-session   # ๐Ÿ”ฌ Simulate single session
npm run test-history   # ๐Ÿ“Š Generate historical data

๐Ÿ“ˆ Analytics

Usage Reports

Get detailed insights into your Claude Code usage:

$ npm run report daily

๐Ÿ“Š Claude Code Usage Report - 2024-01-15
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ’Ž Token Usage:
  โ€ข Input Tokens:        1,234 (12.3%)
  โ€ข Output Tokens:       2,567 (25.7%) 
  โ€ข Cache Read:          5,432 (54.3%)
  โ€ข Cache Creation:        768 (7.7%)
  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  โ€ข Total Tokens:       10,001

๐Ÿ’ฐ Cost Breakdown:
  โ€ข claude-3-sonnet-20241022: $12.34
  โ€ข claude-3-haiku-20240307:  $3.45
  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  โ€ข Total Cost:         $15.79

๐Ÿ“ˆ Performance:
  โ€ข Sessions:            47
  โ€ข Avg Tokens/Session:  213
  โ€ข Peak Hour:           14:00-15:00

Prometheus Integration

Monitor your metrics with industry-standard tools:

  • Grafana Dashboards: Import pre-built dashboards
  • Alert Rules: Set up cost and usage alerts
  • Historical Data: Long-term trend analysis

๐Ÿ” Data Storage

File Structure

ccmonitor/
โ”œโ”€โ”€ daily-usage.json     # ๐Ÿ’พ Primary data store
โ”œโ”€โ”€ logs/                # ๐Ÿ“‹ Application logs
โ””โ”€โ”€ config/              # โš™๏ธ Configuration files

Data Format

Data is stored in JSON format with incremental daily aggregation:

{
  "2024-01-15": {
    "inputTokens": 1234,
    "outputTokens": 2567,
    "cacheReadTokens": 5432,
    "cacheCreationTokens": 768,
    "totalTokens": 10001,
    "sessions": 47,
    "modelCosts": {
      "claude-3-sonnet-20241022": 12.34
    }
  }
}

๐Ÿš€ Advanced Usage

Remote Monitoring

Monitor Claude Code usage on remote servers:

# Create SSH tunnel
ssh -L 3000:localhost:3000 -L 9464:localhost:9464 user@server

# Access dashboards locally
open http://localhost:3000      # Web dashboard
open http://localhost:9464      # Prometheus metrics

Docker Deployment

Deploy with Docker for production environments:

# Build and run
docker build -t claude-monitor .
docker run -p 3000:3000 -p 4318:4318 -p 9464:9464 claude-monitor

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

git clone https://github.com/yourusername/claude-code-monitor.git
cd claude-code-monitor
npm install
npm run dev

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™‹โ€โ™‚๏ธ Support

๐ŸŒŸ Acknowledgments


Made with โค๏ธ for the Claude Code community

โญ Star us on GitHub โ€ข ๐Ÿ› Report Bug โ€ข ๐Ÿ’ก Request Feature

About

๐Ÿ“Š Claude Code Telemetry Monitor - Real-time token usage tracking and cost analytics dashboard for Claude Code sessions via OpenTelemetry OTLP protocol ๐Ÿ“Š Claude Code ้ฅๆต‹็›‘ๆŽงๅ™จ - ้€š่ฟ‡ OpenTelemetry OTLP ๅ่ฎฎๅฎžๆ—ถ่ทŸ่ธช Claude Code ไผš่ฏ็š„ไปค็‰Œไฝฟ็”จ้‡ๅ’Œๆˆๆœฌๅˆ†ๆžไปช่กจๆฟ

Resources

Stars

11 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages