---
title: "Claude Code Stats app plugin documentation"
description: "Set up Claude Code Stats and find what to read next in the docs."
---

> This is the Markdown version of https://grafana.com/grafana/plugins/timurdigital-claudestats-app/docs/

# Introduction

These docs take you from an installed plugin to a working team usage dashboard. Start with the setup on this page, which gets Claude Code telemetry into Grafana. Then read [Configure](https://grafana.com/grafana/plugins/timurdigital-claudestats-app/docs/configure/) to match the app to how your metrics arrive, and [Features](https://grafana.com/grafana/plugins/timurdigital-claudestats-app/docs/features/) for what each tab shows.

## Before you begin

Before you set up the app, ensure you have:

- **Grafana permissions:** The `Organization administrator` role. Only organization administrators can enable and configure apps.
- **Grafana version:** Grafana 13.2.0 or later.
- **A Prometheus-compatible data source:** The app queries Claude Code metrics with PromQL. Grafana Cloud stacks include a Prometheus (Mimir) data source by default. Self-hosted setups can use Prometheus.
- **Claude Code with telemetry enabled:** Each team member's Claude Code must export OpenTelemetry metrics, as described in [Connect your data](#connect-your-data).
- **For the event-based views, a Loki data source:** The **Prompts**, **Workflow**, **Reliability** and **Security** tabs and the tool performance panels on the **Tools** tab read Claude Code events from Loki. Grafana Cloud stacks include a Loki data source by default. For details, refer to [Send events to Loki](#send-events-to-loki).
- **For the Traces tab, a Tempo data source:** The **Traces** tab reads Claude Code traces from Tempo. Grafana Cloud stacks include a Tempo data source by default. For details, refer to [Send traces to Tempo](#send-traces-to-tempo).

## Enable the app

To enable Claude Code Stats:

1. Click **Administration** > **Plugins and data** > **Plugins** in the left-side menu.
2. Enter `Claude Code Stats` in the search bar.
3. Select **Claude Code Stats**.
4. Click **Enable**.

After you enable the app, refer to [Configure](https://grafana.com/grafana/plugins/timurdigital-claudestats-app/docs/configure/) for its settings.

## Connect your data

Claude Code exports usage metrics over OpenTelemetry (OTLP). Choose the path that matches your setup, then set the same **Metric format** in the app, as described in [Configure](https://grafana.com/grafana/plugins/timurdigital-claudestats-app/docs/configure/#metric-format).

### Send metrics directly to Grafana Cloud

To send metrics straight to the Grafana Cloud OTLP endpoint:

1. Open your [Grafana Cloud portal](https://grafana.com/profile/org), select your stack and click **Configure** in the **OpenTelemetry** tile.

2. Click **Generate API Token** and copy the OTLP endpoint and the generated `OTEL_EXPORTER_OTLP_HEADERS` value. The part after `Basic` is the Base64 encoding of your instance ID and token, `<instance-id>:<token>`, not the token alone.

3. Add these variables to each team member's shell profile, such as `~/.zshrc` or `~/.bashrc`:

   ```bash
   export CLAUDE_CODE_ENABLE_TELEMETRY=1
   export OTEL_METRICS_EXPORTER=otlp
   export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
   export OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp-gateway-prod-<region>.grafana.net/otlp"
   export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic <base64-of-instance-id:token>"
   # Grafana Cloud (Mimir) needs cumulative temporality
   export OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=cumulative
   ```

4. Reload the shell and restart Claude Code.

5. In the app's configuration, set **Ingestion path** to **Direct OTLP**.

The configuration page's **Setup Guide** tab builds this script for you from your endpoint, token and the features you pick. For details, refer to [Setup Guide](https://grafana.com/grafana/plugins/timurdigital-claudestats-app/docs/configure/#setup-guide).

### Send metrics through an OpenTelemetry Collector to Prometheus

To send metrics to a self-hosted OpenTelemetry Collector that writes to Prometheus:

1. Add these variables to each team member's shell profile:

   ```bash
   export CLAUDE_CODE_ENABLE_TELEMETRY=1
   export OTEL_METRICS_EXPORTER=otlp
   export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
   export OTEL_EXPORTER_OTLP_ENDPOINT="http://<collector-host>:4318"
   ```

2. In the Collector, receive OTLP, convert delta temporality to cumulative with the `deltatocumulative` processor and export with `prometheusremotewrite`.

3. Reload the shell and restart Claude Code.

4. In the app's configuration, keep **Ingestion path** set to **Prometheus / OTEL Collector**, which is the default.

### Check that data arrives

Claude Code exports metrics every 60 seconds by default. Use Claude Code for a few minutes, then open **Explore**, select your Prometheus data source and query the cost metric:

| Ingestion path              | Query                              |
| --------------------------- | ---------------------------------- |
| Direct OTLP                 | `claude_code_cost_usage`           |
| Prometheus / OTEL Collector | `claude_code_cost_usage_USD_total` |

When the query returns series, open the app. If it returns nothing, refer to [Troubleshooting](https://grafana.com/grafana/plugins/timurdigital-claudestats-app/docs/troubleshooting/).

### Send events to Loki

The **Prompts**, **Workflow**, **Reliability** and **Security** tabs and the tool performance panels on the **Tools** tab read the events Claude Code sends as OpenTelemetry logs, such as prompts, API requests and errors, refusals, tool results, subagents, hooks, permission changes and logins. To send them:

1. Add this variable to each team member's shell profile, next to the ones above:

   ```bash
   export OTEL_LOGS_EXPORTER=otlp
   ```

   Events go to the same OTLP endpoint as the metrics.

2. Get the events into Loki:

   - **Grafana Cloud:** The OTLP gateway sends logs to your stack's Loki. No other change is needed.
   - **OpenTelemetry Collector:** Add a `logs` pipeline that exports to Loki's OTLP endpoint, such as `http://<loki-host>:3100/otlp`, with the `otlp_http` exporter.

3. Restart Claude Code.

The app expects Loki's native OTLP ingestion, which stores `service.name` as the `service_name` label and the event attributes as structured metadata. On the **Prompts**, **Workflow**, **Reliability**, **Security** and **Tools** tabs, pick the Loki data source in **Events**.

### Send traces to Tempo

The **Traces** tab reads the traces Claude Code sends, which link each prompt to its model requests and tool calls. Tracing is a beta feature of Claude Code. To send traces:

1. Add these variables to each team member's shell profile, next to the ones above:

   ```bash
   export CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1
   export OTEL_TRACES_EXPORTER=otlp
   ```

   Traces go to the same OTLP endpoint as the metrics.

2. Get the traces into Tempo:

   - **Grafana Cloud:** The OTLP gateway sends traces to your stack's Tempo. No other change is needed.
   - **OpenTelemetry Collector:** Add a `traces` pipeline that exports to Tempo's OTLP endpoint, such as `<tempo-host>:4317`, with the `otlp_grpc` exporter.

3. Restart Claude Code.

On the **Traces** tab, pick the Tempo data source in **Traces**.

### Optional telemetry settings

Some panels need an extra Claude Code setting or a minimum Claude Code version. Set the variables in each team member's shell profile, next to the ones above, and restart Claude Code.

| Feature                                                                                                                                             | Requires                                                                                                                                                                                                                                                               |
| --------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Every panel                                                                                                                                         | `CLAUDE_CODE_ENABLE_TELEMETRY=1`, `OTEL_METRICS_EXPORTER=otlp`, `OTEL_EXPORTER_OTLP_PROTOCOL` and `OTEL_EXPORTER_OTLP_ENDPOINT`, as in [Connect your data](#connect-your-data). `OTEL_EXPORTER_OTLP_PROTOCOL` has no default: without it, Claude Code exports nothing. |
| Real names in **Cost by Subagent**, **Cost by Skill**, **Cost by MCP Server**, **Cost by Plugin**, **Cost by MCP Tool** and their token equivalents | `OTEL_LOG_TOOL_DETAILS=1`, Claude Code v2.1.273 or later. Without it, user-defined subagents, third-party skills and plugins, and user-configured MCP servers and their tools appear as `custom` or `third-party`.                                                     |
| **Repository** filter, **Cost by Repository** and **Tokens by Repository**                                                                          | `OTEL_METRICS_INCLUDE_REPOSITORY=true`, Claude Code v2.1.269 or later. For details, refer to [Filter by repository](#filter-by-repository).                                                                                                                            |
| Your own filters, such as team or cost center                                                                                                       | The attribute in `OTEL_RESOURCE_ATTRIBUTES`, and the label under [Filters](https://grafana.com/grafana/plugins/timurdigital-claudestats-app/docs/configure/#filters). For details, refer to [Filter by your own attributes](#filter-by-your-own-attributes).           |
| Readable names for team members who use an API key, Amazon Bedrock, Google Cloud or Microsoft Foundry                                               | `enduser.id` in `OTEL_RESOURCE_ATTRIBUTES`. For details, refer to [Name team members who don't sign in with a Claude account](#name-team-members-who-dont-sign-in-with-a-claude-account).                                                                              |
| The **Prompts**, **Workflow**, **Reliability** and **Security** tabs and the tool performance panels on the **Tools** tab                           | `OTEL_LOGS_EXPORTER=otlp` and a Loki data source. For details, refer to [Send events to Loki](#send-events-to-loki).                                                                                                                                                   |
| The **Traces** tab                                                                                                                                  | `CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1`, `OTEL_TRACES_EXPORTER=otlp` and a Tempo data source. For details, refer to [Send traces to Tempo](#send-traces-to-tempo).                                                                                                     |
| **Team** filter                                                                                                                                     | Sessions signed in through a Claude apps gateway. For details, refer to [Filter by team](#filter-by-team).                                                                                                                                                             |
| **Surface** on the **Overview** tab                                                                                                                 | `OTEL_METRICS_INCLUDE_ENTRYPOINT=true`.                                                                                                                                                                                                                                |
| **Lines of Code by Model**                                                                                                                          | Claude Code v2.1.172 or later. Lines from older versions appear as `unknown`.                                                                                                                                                                                          |

#### Filter by team

Sessions signed in through a Claude apps gateway carry the team member's identity-provider groups in `user.groups`. The app then shows a **Team** filter with one entry per group. Picking a group shows the usage of sessions in that group, including team members who are in several groups. No setting is needed.

The filter lists the first five groups of each session. A group that only ever appears sixth or later in a team member's list of groups isn't offered.

#### Filter by repository

Set `OTEL_METRICS_INCLUDE_REPOSITORY=true` (Claude Code v2.1.269 and later) to tag metrics with the Git repository Claude Code works in, taken from its `origin` remote. The app then shows a **Repository** filter and the **Cost by Repository** and **Tokens by Repository** panels.

#### Filter by your own attributes

Attributes in `OTEL_RESOURCE_ATTRIBUTES`, such as `team.id=platform` or `cost_center=eng-42`, reach Prometheus as labels on every metric, with dots turned into underscores. To filter by one, add it under [Filters](https://grafana.com/grafana/plugins/timurdigital-claudestats-app/docs/configure/#filters) on the configuration page.

#### Name team members who don't sign in with a Claude account

The app names each team member by the email address of their Claude account. Sessions that use an API key, Amazon Bedrock, Google Cloud or Microsoft Foundry don't send an email, so the app falls back to the anonymous ID Claude Code generates for each machine, a long random string. To show a readable name instead, set `enduser.id` in each team member's shell profile:

```bash
export OTEL_RESOURCE_ATTRIBUTES="enduser.id=jdoe@example.com"
```

If `OTEL_RESOURCE_ATTRIBUTES` is already set, add `enduser.id=...` to it, separated by a comma. An email address from a Claude account takes precedence over `enduser.id`.

For every Claude Code telemetry setting, refer to [Monitoring usage](https://code.claude.com/docs/en/monitoring-usage) in the Claude Code docs.

## Common tasks

- [Match the app to how your metrics arrive](https://grafana.com/grafana/plugins/timurdigital-claudestats-app/docs/configure/#metric-format)
- [See what your team spends and on which models](https://grafana.com/grafana/plugins/timurdigital-claudestats-app/docs/features/costs/)
- [Find what drives token usage](https://grafana.com/grafana/plugins/timurdigital-claudestats-app/docs/features/tokens/)
- [Check how often Claude's edits are accepted](https://grafana.com/grafana/plugins/timurdigital-claudestats-app/docs/features/tools/)
- [Track commits, pull requests and active time](https://grafana.com/grafana/plugins/timurdigital-claudestats-app/docs/features/productivity/)
- [Get alerted on spend spikes, API errors, refusals and permission escalations](https://grafana.com/grafana/plugins/timurdigital-claudestats-app/docs/configure/#set-up-alerts)
- [Fix panels that show no data](https://grafana.com/grafana/plugins/timurdigital-claudestats-app/docs/troubleshooting/)
