Connecting Claude Code
Connect Claude Code to CloudZero to bring your Claude Code usage and cost data into a unified view of all your cloud and AI spend. Claude Code (Anthropic's coding agent) exports its own OpenTelemetry traces natively, so you can send telemetry straight to CloudZero from the CLI. There is no gateway, proxy, or macOS agent to install. Once connected, you organize Claude Code costs alongside your other costs using Dimensions that matter to your business, such as team, product, or environment.
This guide covers enabling Claude Code's enhanced telemetry and pointing its OTLP trace exporter at the dedicated CloudZero route.
How it works
Claude Code exports OpenTelemetry traces over OTLP/HTTP. CloudZero recognizes Claude Code's spans by name and turns each one into a cost and usage event. Activity appears in AI Signals within a few minutes of usage, and full cost exploration in the Explorer follows within about 24 hours.
Claude Code must send to the dedicated
/v2/telemetry/claude-coderoute. Its spans do not carry the standardgen_ai.*attributes, so the generic OTel route would ignore every span. Use the endpoint exactly as shown in Step 2.
CloudZero displays exactly the metadata Claude Code sends. Nothing is added, inferred, or reshaped. CloudZero never reads or stores prompt or response content. Only model, token, timing, and status metadata are ingested.
This integration does not use the Create Connection flow in Settings > Cloud Connections. You connect it by creating a CloudZero API key and pointing telemetry at CloudZero, as described below. Confirm it is working in AI Signals once data flows.
What you need
- A CloudZero user with API key access
- Claude Code installed and in use by the team you are onboarding
- Outbound HTTPS connectivity from every machine running Claude Code to
telemetry.cloudzero.comon port 443
The traces this integration reads come from Claude Code's enhanced telemetry, which is an Anthropic beta. If you set the environment variables below and traces do not appear, update Claude Code to the latest version and try again.
Step 1: Create a CloudZero API key
- In CloudZero, go to Settings > API Keys.
- Create a new API key.
- Under Scopes, open the Ai-Telemetry-Ingest category and select
ingest-claude-code-v1. - Copy the key value and store it securely. You set it as an environment variable in Step 2. Treat it like any other secret.
Scopes are enforced per route. The
ingest-claude-code-v1scope authorizes the Claude Code ingest endpoint only. If a request later returns 403, the key is missing this scope.
Step 2: Enable telemetry and point it at CloudZero
Set these environment variables wherever Claude Code runs, such as a developer's shell profile, a CI environment, or the managed settings file for an org-wide rollout (Step 3):
CLAUDE_CODE_ENABLE_TELEMETRY=1
CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1
OTEL_TRACES_EXPORTER=otlp
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://telemetry.cloudzero.com/v2/telemetry/claude-code
OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_HEADERS=Authorization=<your-cloudzero-api-key>| Variable | Value | Why |
|---|---|---|
CLAUDE_CODE_ENABLE_TELEMETRY | 1 | Master switch for Claude Code telemetry. |
CLAUDE_CODE_ENHANCED_TELEMETRY_BETA | 1 | Required for traces specifically. Without this, Claude Code may still emit metrics but sends zero traces. The master switch alone is not enough. |
OTEL_TRACES_EXPORTER | otlp | Tells Claude Code to export traces over OTLP. |
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT | https://telemetry.cloudzero.com/v2/telemetry/claude-code | The CloudZero route for Claude Code. |
OTEL_EXPORTER_OTLP_TRACES_PROTOCOL | http/protobuf | CloudZero's ingest does not accept gRPC. |
OTEL_EXPORTER_OTLP_HEADERS | Authorization=<your-cloudzero-api-key> | The raw key from Step 1, with no Bearer prefix. Store it as a secret. |
Two flags are required, not one.
CLAUDE_CODE_ENABLE_TELEMETRYturns telemetry on in general.CLAUDE_CODE_ENHANCED_TELEMETRY_BETAturns on the traces this integration reads. A deployment can have the first flag set and metrics flowing elsewhere while still sending CloudZero nothing, because traces need the second flag too.
Use the traces-specific endpoint variable, set exactly as shown.
OTEL_EXPORTER_OTLP_TRACES_ENDPOINTis used verbatim. Do not substitute the genericOTEL_EXPORTER_OTLP_ENDPOINT. The OTel SDK appends/v1/tracesto that value, which misses the route and returns a 403 or 404.
Step 3: Roll out org-wide (optional)
Once you have confirmed data is flowing from one machine (Step 4), put the same variables in Claude Code's managed settings file so every developer picks them up automatically, with nothing to set themselves:
- macOS:
/Library/Application Support/ClaudeCode/managed-settings.json - Linux:
/etc/claude-code/managed-settings.json
{
"env": {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
"CLAUDE_CODE_ENHANCED_TELEMETRY_BETA": "1",
"OTEL_TRACES_EXPORTER": "otlp",
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT": "https://telemetry.cloudzero.com/v2/telemetry/claude-code",
"OTEL_EXPORTER_OTLP_TRACES_PROTOCOL": "http/protobuf",
"OTEL_EXPORTER_OTLP_HEADERS": "Authorization=<your-cloudzero-api-key>"
}
}Managed settings take precedence over anything a user sets themselves and cannot be overridden, so this is the reliable way to guarantee every developer's Claude Code reports to CloudZero. See Claude Code's settings documentation for other operating systems or MDM-based deployment.
Step 4: Send traffic and verify
- Export the variables from Step 2, or deploy the managed settings from Step 3, on a machine running Claude Code.
- Use Claude Code normally for a few minutes.
- Open CloudZero and watch the AI Signals view for activity.
You should see activity in the AI Signals view within a few minutes of usage. The Explorer follows within about 24 hours.
Smoke-test authentication and routing
Before you wait on real usage, you can confirm your key and route work. An empty POST should return HTTP 202:
curl -i -X POST \
"https://telemetry.cloudzero.com/v2/telemetry/claude-code" \
-H "Authorization: <your-cloudzero-api-key>" \
-H "Content-Type: application/x-protobuf" \
--data-binary $'\x00'Expected response:
HTTP/2 202
content-type: application/json
{"status":"accepted"}
A 202 confirms authentication, scope, and routing are good. A 403 means the key is missing the ingest-claude-code-v1 scope, so re-check Step 1.
A 202 does not confirm your traces landed. The ingest is fail-open and returns 202 even for an empty body. The smoke test proves your key and route work. The AI Signals view proves Claude Code's real traces are being ingested. If the smoke test passes but nothing appears after real usage, re-check Step 2. The most common cause is a missing enhanced-telemetry beta flag.
What to expect
After you connect, Claude Code activity works like any other cost data in CloudZero:
- AI Signals: normalized Claude Code inference events as they arrive, showing model, token counts, and timing. Events appear within a few minutes of usage.
- Explorer: the downstream exploration experience, breaking down cost by model over time. This data is processed downstream of ingest, so allow about 24 hours after activity for it to appear here.
From there, you can explore your Claude Code costs in the Explorer, organize them by team or product using Dimensions, track trends in Dashboards, set Budgets, or ask questions in the AI Hub.
Data privacy
Claude Code redacts prompt and tool content from its telemetry by default, so there is nothing you need to configure to keep that data from leaving the machine. As with every CloudZero telemetry route, CloudZero never reads or stores prompt or response content even when it is present. Only model, token, and timing metadata are ingested.
Troubleshooting
If data is not appearing in the AI Signals view 5 minutes after confirmed Claude Code usage, work through these in order.
- Missing the enhanced-telemetry beta flag. The most common cause.
CLAUDE_CODE_ENABLE_TELEMETRY=1alone is not enough.CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1is also required for traces. Re-check Step 2. - Wrong endpoint variable (appends
/v1/traces). UseOTEL_EXPORTER_OTLP_TRACES_ENDPOINTset tohttps://telemetry.cloudzero.com/v2/telemetry/claude-code. Do not use the genericOTEL_EXPORTER_OTLP_ENDPOINT. - Pointed at the wrong CloudZero route. Claude Code must go to
/v2/telemetry/claude-code, not the generic/v2/telemetry/otel-genai. The generic route does not recognize Claude Code's spans and silently drops them. - Wrong protocol.
OTEL_EXPORTER_OTLP_TRACES_PROTOCOLmust behttp/protobuf. CloudZero's ingest does not accept gRPC. Bearerprefix on the API key. The header value must be the raw key, such asAuthorization=<your-cloudzero-api-key>, notAuthorization=Bearer <your-cloudzero-api-key>.- Missing scope. A 403 on the smoke test means the key lacks
ingest-claude-code-v1. Re-check Step 1. - Old Claude Code version. Enhanced telemetry is a beta feature. If the flags have no effect, update Claude Code and retry.
- Config not picked up. Environment variables are read at startup. Open a new terminal or restart the process after any change. If you are using managed settings, confirm the file is at the exact path Claude Code expects for the operating system.
Have questions or feedback? Reach out to your account manager.
Updated 15 days ago

