Claude Code

Claude Code exports its own telemetry over OpenTelemetry. Point it at Trefur and every session's token use, cost and model calls show up in your workspace, with nothing to install.

What Trefur records

  • Usage metrics: claude_code.token.usage, claude_code.cost.usage, claude_code.active_time.total, claude_code.session.count, claude_code.lines_of_code.count.
  • API request events (claude_code.api_request): one run per model API call, with its model, tokens, cost and duration.

Everything is filed under the agent the telemetry key belongs to. Other metrics and log records are acknowledged and counted as not stored in the standard OTLP response, so nothing fails on the Claude Code side.

1. Create a telemetry key

  1. Sign in to app.trefur.com and choose Add agent.
  2. Name the agent, answer where it runs, and choose Continue.
  3. Open Advanced: use a telemetry key, then choose Create a telemetry key.
  4. Copy the key. It is shown once, belongs to this agent alone and expires in 90 days.

A name such as claude-code keeps it easy to find. Every Claude Code that uses the key reports as that one agent; create a key per team if you want them apart.

2. Set the environment

In the shell that starts Claude Code:

export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_METRICS_EXPORTER=otlp
export OTEL_LOGS_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=https://api.trefur.com/v1/metrics
export OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://api.trefur.com/v1/logs
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer trf_obs_..."

Or in Claude Code's settings.json, so every session picks them up:

{
  "env": {
    "CLAUDE_CODE_ENABLE_TELEMETRY": "1",
    "OTEL_METRICS_EXPORTER": "otlp",
    "OTEL_LOGS_EXPORTER": "otlp",
    "OTEL_EXPORTER_OTLP_PROTOCOL": "http/protobuf",
    "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT": "https://api.trefur.com/v1/metrics",
    "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT": "https://api.trefur.com/v1/logs",
    "OTEL_EXPORTER_OTLP_HEADERS": "Authorization=Bearer trf_obs_..."
  }
}

To roll the settings out to a team, put the same env block in the settings file your organisation distributes to Claude Code.

3. Start Claude Code

Use Claude Code as usual. Metrics are exported on Claude Code's export interval, about once a minute by default, and API request events a few seconds after each call. The app shows when the agent's first event arrives.

Details

  • Both OTLP/HTTP encodings work: http/protobuf and http/json.
  • The key travels as Authorization: Bearer on every export. It belongs to this agent alone and expires in 90 days; renew it from the agent's Connect tab.
  • Traces from your own agents go to the OTLP/HTTP trace endpoint.