Monitor your Claude Code usage with Cloudflare Workers and Workers Analytics Engine.
- Public, Secure endpoint for OpenTelemetry/OTLP
- Powerful analytics via ClickHouse SQL
- Truly Serverless, zero-maintenance
One-click deployment with
Monitoring via OpenTelemetry is the Claude Code built-in feature.
Once you deploy the worker to the https://cc-monitor.your-org.workers.dev
, you can enable monitoring with env settings like:
You can leverage your company's MDM solution to deploy this as org-managed settings.
See more details from the Claude Code official guide.
You can query the collected data in the Cloudflare Console (Analytics Engine Studio), Cloudflare API or Grafana Dashboard.
Blobs (Fixed Schema):
blob1
:metric_type
(session_count
,cost_usage
, etc.)blob2
:service.name
(e.g.claude-code
)blob3
:service.version
(e.g.1.0.48
)blob4
:organization.id
(UUID)blob5
:user.id
(hashed user ID)blob6
:user.account_uuid
(UUID)blob7
:user.email
(email address)blob8
:session.id
(UUID)blob9
:terminal.type
(e.g.iTerm
)blob10+
: Metric-specific attributes
Doubles:
double1
:timestamp_ms
- Timestamp in millisecondsdouble2
:metric_value
- The actual metric value
The endpoint processes the following Claude Code metrics:
Metric Name | Description | Additional Attributes |
---|---|---|
claude_code.session.count |
CLI session starts | |
claude_code.cost.usage |
Usage costs in USD | model |
claude_code.token.usage |
Token consumption | model |
claude_code.active_time.total |
Active time tracking | |
claude_code.lines_of_code.count |
Code changes | |
claude_code.pull_request.count |
PR creation events | |
claude_code.commit.count |
Commit events | |
claude_code.code_edit_tool.decision |
Tool decisions | decision , language , tool_name |
SELECT
blob1 as metric_type,
blob7 as user_email,
SUM(double2) as total_value
FROM claude_code_metrics_{{SCHEMA_VERSION}}
WHERE metric_type = 'cost_usage'
GROUP BY metric_type, user_email
ORDER BY total_value DESC
Claude Code → OTLP/HTTP → Cloudflare Worker → Analytics Engine
The worker acts as a bridge between Claude Code's OTLP metrics and Cloudflare's Analytics Engine:
- Receives OTLP metrics via HTTP/JSON POST requests
- Authenticates requests using Bearer token validation
- Transforms OTLP data to Analytics Engine format
- Stores metrics in Analytics Engine for querying
The endpoint uses Bearer token authentication:
- Development: Set
AUTH_SECRET
in.dev.vars
- Production: Use
wrangler secret put AUTH_SECRET
Use strong, randomly generated secrets and rotate secrets regularly.