// How to monitor usage, track costs, configure analytics, and measure ROI for Claude Code. Use when user asks about monitoring, telemetry, metrics, costs, analytics, or OpenTelemetry.
| name | administration |
| description | How to monitor usage, track costs, configure analytics, and measure ROI for Claude Code. Use when user asks about monitoring, telemetry, metrics, costs, analytics, or OpenTelemetry. |
Claude Code supports OpenTelemetry (OTel) for metrics and events. The system exports time series data via standard metrics protocol and events through logs/events protocol.
Enable telemetry:
export CLAUDE_CODE_ENABLE_TELEMETRY=1
Configure exporters (optional, pick what you need):
# Metrics
export OTEL_METRICS_EXPORTER=otlp # Options: otlp, prometheus, console
# Logs
export OTEL_LOGS_EXPORTER=otlp # Options: otlp, console
Default intervals:
Customize intervals:
export OTEL_METRIC_EXPORT_INTERVAL=30000 # milliseconds
export OTEL_LOGS_EXPORT_INTERVAL=10000 # milliseconds
Claude Code tracks eight core metrics:
CLI sessions started
Use for: Tracking adoption and active users
Code additions/removals tracked by type
Use for: Measuring productivity and code generation volume
Creation count
Use for: Tracking automated PR generation
Git commits via Claude Code
Use for: Measuring development activity
Session costs in USD (model-segmented)
Use for: Budget tracking and cost allocation
Important: Cost metrics are approximations. For official billing data, refer to your API provider (Claude Console, AWS Bedrock, or Google Cloud Vertex).
Tokens consumed (input/output/cache types)
Use for: Understanding API usage patterns and optimizing costs
Accept/reject counts per tool
Use for: Understanding user trust and automation acceptance
Actual usage duration in seconds
Use for: Measuring engagement and productivity time
Segment metrics by:
user.account_uuid - Individual user trackingorganization.id - Team/organization groupingsession.id - Session-specific analysismodel - Model usage breakdownapp.version - Version trackingFive event types are exported:
Prompt submissions (content redacted by default)
Enable prompt logging:
export OTEL_LOG_USER_PROMPTS=1
Use for: Understanding user interaction patterns
Tool execution completion with success status and duration
Use for: Monitoring tool performance and reliability
Claude API calls with cost and token data
Use for: Detailed cost analysis and API usage tracking
Failed requests with HTTP status codes
Use for: Troubleshooting and reliability monitoring
User accept/reject actions with decision source
Use for: Understanding automation trust and user preferences
Monitor costs by model and user:
export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_METRICS_EXPORTER=prometheus
View costs segmented by:
Implement budget monitoring:
Reference the Claude Code ROI Measurement Guide for:
Productivity Metrics:
Quality Metrics:
Adoption Metrics:
# prometheus.yml
scrape_configs:
- job_name: 'claude-code'
static_configs:
- targets: ['localhost:9464']
Start with Prometheus exporter:
export OTEL_METRICS_EXPORTER=prometheus
claude
Create dashboards to visualize:
Export to your own backend:
export OTEL_EXPORTER_OTLP_ENDPOINT=https://your-backend.com
export OTEL_EXPORTER_OTLP_HEADERS="api-key=your-key"
Set up telemetry from day one to establish baselines
Use organization and user IDs for proper attribution
Review cost metrics weekly to identify trends
Monitor active users and session frequency
Track bug rates and code review findings
Configure alerts for:
Share analytics to demonstrate value and identify improvements
Use metrics to:
User Prompts:
OTEL_LOG_USER_PROMPTS=1Sensitive Data:
Access Control:
CLAUDE_CODE_ENABLE_TELEMETRY=1# docker-compose.yml for full monitoring stack
version: '3.8'
services:
prometheus:
image: prom/prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
grafana:
image: grafana/grafana
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
Configure Claude Code:
export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_METRICS_EXPORTER=prometheus
export OTEL_EXPORTER_PROMETHEUS_PORT=9464