# Claude Code integration

Read more about Swarmia's other [AI coding tool integrations](https://help.swarmia.com/getting-started/integrations/ai-coding-tool-integrations) and [measuring the productivity impact of AI tools](https://help.swarmia.com/use-cases/measure-the-productivity-impact-of-ai-tools).

There are multiple ways to run Claude Code, each with a different set of supported integration options for getting your data into Swarmia. For a quick overview of the options and compatibility, see the table below. You can just go to [Settings → AI tools → Claude Code](https://app.swarmia.com/settings/ai-assistants), click "Add new", and Swarmia guides you through the setup.

<figure><img src="https://2772466312-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMa8uBmGhQgR7MTPq9yh7%2Fuploads%2FgvMZgZfFcLdYH9HykEkk%2Fimage.png?alt=media&#x26;token=25af2f05-3e6b-488a-9450-183d10698a02" alt=""><figcaption></figcaption></figure>

If you're unsure which authentication method you're using, see [*How do I know which authentication method I'm using?*](#how-do-i-know-which-authentication-method-im-using) below.

|                                                  | <p><strong>Claude Console</strong></p><p>(API-based billing)</p> | <p><strong>Claude subscription</strong></p><p>(Pro, Max, Team, Enterprise)</p> | <p><strong>3rd-party platform</strong></p><p>(Amazon Bedrock, Google Vertex AI, Microsoft Foundry, and LiteLLM)</p> |
| ------------------------------------------------ | ---------------------------------------------------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------- |
| **Analytics API**                                | :white\_check\_mark: Recommended                                 | :x: Not available                                                              | :x: Not available                                                                                                   |
| **OpenTelemetry:** managed settings in Claude.ai | :x: Not available                                                | :white\_check\_mark: Recommended                                               | :x: Not available                                                                                                   |
| **OpenTelemetry:** managed settings in MDM       | :heavy\_check\_mark: Available                                   | :heavy\_check\_mark: Available                                                 | <p><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span> Recommended<br>(requires user email)</p>  |
| **OpenTelemetry:** shared project settings       | :heavy\_check\_mark: Available                                   | :heavy\_check\_mark: Available                                                 | :x: Not available                                                                                                   |

We recommend using [Claude Code's default attribution settings](https://code.claude.com/docs/en/settings#attribution-settings) for commit and PR messages, since those are used in Swarmia's [automatic AI assistant detection](https://help.swarmia.com/use-cases/measure-the-productivity-impact-of-ai-tools/ai-impact-on-pr-metrics#automatic-ai-assistant-detection-for-prs).

## Analytics API

{% hint style="info" %}
Analytics API availability:

* :white\_check\_mark: Claude Console
* :x: Claude subscription
* :x: 3rd-party platform

If you're unsure which authentication method you're using, see [*How do I know which authentication method I'm using?*](#how-do-i-know-which-authentication-method-im-using) below.
{% endhint %}

[Create a Claude Code Admin API key](https://console.anthropic.com/settings/admin-keys) (note that these differ from the standard API keys) and copy it to [Settings → AI tools → Claude Code](https://app.swarmia.com/settings/ai-assistants) in Swarmia. You need to be a Claude organization admin to create Admin API keys. We fetch 30 days of historical activity data upon connection.

{% hint style="warning" %}
The historical [*enabled users*](https://help.swarmia.com/use-cases/measure-the-productivity-impact-of-ai-tools/ai-adoption-metrics) don't include people who had a license but got removed before you connected Claude Code to Swarmia.
{% endhint %}

## OpenTelemetry monitoring

Claude Code’s [OpenTelemetry monitoring](https://code.claude.com/docs/en/monitoring-usage) lets your users send event-level data directly to Swarmia.

To enable the integration, add the following JSON to all your users' Claude Code settings. There are multiple ways to distribute the settings, which are explained below. See the Claude Code's [settings precedence](https://code.claude.com/docs/en/settings#settings-precedence) for more information about the priority order of settings.

```json
{
  "env": {
    "CLAUDE_CODE_ENABLE_TELEMETRY": "1",
    "OTEL_METRICS_EXPORTER": "otlp",
    "OTEL_EXPORTER_OTLP_PROTOCOL": "http/json",
    "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT": "https://hook.swarmia.com/otel/v1/metrics",
    "OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE": "delta",
    "OTEL_METRIC_EXPORT_INTERVAL": "600000",
    "OTEL_EXPORTER_OTLP_HEADERS": "Authorization=<AUTHORIZATION_TOKEN>",
    "OTEL_RESOURCE_ATTRIBUTES": "user.email=developer@example.com"
  }
}
```

* &#x20;`"OTEL_RESOURCE_ATTRIBUTES": "user.email=developer@example.com"` is **required only if you're using Claude Code via a 3rd-party platform** (Amazon Bedrock, Google Vertex AI, Microsoft Foundry, and LiteLLM) so that Swarmia can match the activity to the right author.
* Replace `<AUTHORIZATION_TOKEN>` with a key you can generate in [Settings → AI tools → Claude Code](https://app.swarmia.com/settings/ai-assistants) by clicking "Add new" and "Click to reveal".

{% hint style="warning" %}
The OpenTelemetry monitoring option has these limitations:

* **No historical backfill:** Swarmia collects the events in real time, and there's no way to fetch data from the time before you enabled the integration.
* **No data on idle users:** Swarmia receives only usage data, so there's no visibility into people who have a license but are not using it. Consequently, [*enabled users*](https://help.swarmia.com/use-cases/measure-the-productivity-impact-of-ai-tools/ai-adoption-metrics) only include *active users*.
  {% endhint %}

Below are the different ways to distribute the settings.

### Managed settings in Claude.ai

{% hint style="info" %}
Managed settings in Claude.ai availability:

* :x: Claude Console
* :white\_check\_mark: Claude subscription
* :x: 3rd-party platform

If you're unsure which authentication method you're using, see [*How do I know which authentication method I'm using?*](#how-do-i-know-which-authentication-method-im-using) below.
{% endhint %}

Add the JSON configuration to the [Claude.ai managed settings](https://claude.ai/admin-settings/claude-code).

<figure><img src="https://2772466312-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMa8uBmGhQgR7MTPq9yh7%2Fuploads%2FY6tULiFoC4tBFWbpptje%2F003853%402x.png?alt=media&#x26;token=e6e65441-d206-487e-ad33-55a03c615203" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
Claude Code users will see a warning when you update the managed settings:

![](https://2772466312-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMa8uBmGhQgR7MTPq9yh7%2Fuploads%2FfEVcIMGI5FRXHt5dS5Xo%2Fimage.png?alt=media\&token=6f826b70-2546-485c-a826-fbca5e23f5ef)
{% endhint %}

### Managed settings in MDM

{% hint style="info" %}
Managed settings in MDM availability:

* :white\_check\_mark: Claude Console
* :white\_check\_mark: Claude subscription
* :white\_check\_mark: 3rd-party platform (requires user email)

If you're unsure which authentication method you're using, see [*How do I know which authentication method I'm using?*](#how-do-i-know-which-authentication-method-im-using) below.
{% endhint %}

Deploy the JSON configuration via device management (e.g., MDM) to all users, e.g., `/Library/Application Support/ClaudeCode/managed-settings.json`. These are enforced for all users. [Read more in Claude Code Docs](https://code.claude.com/docs/en/settings#settings-files).

### Shared project settings

{% hint style="info" %}
Shared project settings availability:

* :white\_check\_mark: Claude Console
* :white\_check\_mark: Claude subscription
* :x: 3rd-party platform

If you're unsure which authentication method you're using, see [*How do I know which authentication method I'm using?*](#how-do-i-know-which-authentication-method-im-using) below.
{% endhint %}

Add the JSON configuration in shared project settings files in each repository (`.claude/settings.json`). The users can override these with their personal settings.

## Frequently asked questions

### How do I know which authentication method I'm using?

* **Claude Console:**
  * You pay per API usage
  * You see activity at [platform.claude.com/claude-code](https://platform.claude.com/claude-code)
* **Claude subscription:**
  * You pay a fixed monthly fee per license and also have access to Claude.ai
  * You see activity at [claude.ai/analytics/claude-code](https://claude.ai/analytics/claude-code)
* **3rd-party platform:**
  * You have one of these environment variables set:
    * `CLAUDE_CODE_USE_BEDROCK` (AWS Bedrock)
    * `CLAUDE_CODE_USE_VERTEX` (Google Vertex AI)
    * `CLAUDE_CODE_USE_FOUNDRY` (Microsoft Foundry)
    * `ANTHROPIC_BASE_URL` (LLM gateway, such as LiteLLM)

### Analytics API: Why do you need an admin API key? Isn't that a bit excessive?

We build our integrations with the principle of least privilege, and we'd love to ask for fewer permissions, but the [Claude Code Analytics API](https://docs.claude.com/en/api/claude-code-analytics-api) requires an admin key. You can [read more about our data access here](https://help.swarmia.com/resources/security-and-data-retention/data-access#claude-code-analytics-api).

If you don't want to share your admin key with Swarmia, you can use the [OpenTelemetry option](#opentelemetry-monitoring).

### OpenTelemetry monitoring: How long does it take for the data to become visible?

The timestamp in [Settings → AI tools → Claude Code → OpenTelemetry monitoring](https://app.swarmia.com/settings/ai-assistants) shows the latest event Swarmia has received in real time. The AI tool metrics are calculated from the events once a day, so it can take up to 24 hours for the data to become visible.

<figure><img src="https://2772466312-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMa8uBmGhQgR7MTPq9yh7%2Fuploads%2FPOLVAFX4xvLxYfB0B0Ze%2F003893%402x.png?alt=media&#x26;token=b22cf27e-2be3-4066-af50-5ec107f924f5" alt=""><figcaption></figcaption></figure>
