> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nebuly.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Compliance

> Sync Claude chats and sessions into Nebuly via the Claude Compliance API

The Claude Compliance integration is a self-hosted utility script that pulls conversation data from Anthropic's [Claude Compliance API](https://platform.claude.com/docs/en/manage-claude/compliance-api) and ingests each user/assistant turn into Nebuly as an Interaction.

The data flow is:

Compliance API (chats + local and remote sessions) → interaction cut → Nebuly ingestion

The script is incremental and resumable: it tracks a local SQLite cache of already-synced data, so you can re-run it safely at any time without creating duplicates.

If your organization signs in with Microsoft Entra, the same script can enrich each interaction with directory data. `end_user` stays the Claude user id. See [Enrich with Microsoft Entra](#enrich-with-microsoft-entra).

The source repository is available [here](https://github.com/nebuly-ai/nebuly-integration-examples/tree/main/claude_compliance).

## Prerequisites

* A **Claude Enterprise** organization with the **Compliance API enabled**. The primary owner enables it in [claude.ai → Organization settings → API](https://claude.ai/admin-settings/api-access). Standalone Claude Console organizations cannot use this integration: they only get Admin API keys, which reach the Activity Feed and not chats or sessions.
* **Python ≥ 3.12** and [Poetry](https://python-poetry.org/docs/#installing-with-the-official-installer) installed on the machine that runs the script.

## Install & run

Clone the integration examples repository, install dependencies, configure your `.env` file, and run the sync:

```bash theme={null}
git clone https://github.com/nebuly-ai/nebuly-integration-examples.git
cd nebuly-integration-examples/claude_compliance
poetry install
# Only if you enable Entra enrichment with ENTRA_FETCH=true:
# poetry install --with entra
cp .env.example .env
# Fill in NEBULY_API_KEY, COMPLIANCE_API_KEY, and ORGANIZATION_UUID
poetry run python -m compliance_sync --from-date 2026-01-01
```

Follow the guide below to retrieve the necessary credentials.

For the complete environment variable reference, available CLI flags, payload customization and resumable-cache details, check the project README.

## Get your credentials

The script requires three environment variables. Follow the steps below to obtain each one.

**1. Nebuly secret key → NEBULY\_API\_KEY**

In Nebuly, go to **Settings → Projects → View Nebuly keys → Secret keys** and copy the secret key for the project you want to sync.

**2. Compliance Access Key → COMPLIANCE\_API\_KEY**

Who can create the key:

* The **primary owner** of the parent organization can create a key that covers every linked organization.
* An **organization owner** can create a key limited to their own organization.

1. Open [claude.ai → Organization settings → API](https://claude.ai/admin-settings/api-access).
2. Under **Keys**, click **Create key**.
3. Select **both** scopes:

   * **`read:compliance_user_data`**: required to read chats, local sessions, and remote sessions.
   * **`read:compliance_org_data`**: required to call List Organizations in the next step.

   Scopes cannot be changed after the key is created. To change them, create a new key.
4. Copy the secret immediately; it is shown only once. It starts with `sk-ant-api01-`.

> [!WARNING]
>
> A key scoped to the parent organization can read every chat, file, project, and session transcript across all linked organizations. A key scoped to a single organization is limited to that organization. Treat it like a root credential and store it in a secrets manager. See Anthropic's [Get access to the Compliance API](https://platform.claude.com/docs/en/manage-claude/compliance-api-access) for full details.

**3. Organization UUID → ORGANIZATION\_UUID**

Call the List Organizations endpoint to find the `uuid` of the org you want to sync:

```bash theme={null}
curl -sS "https://api.anthropic.com/v1/compliance/organizations" \
  --header "x-api-key: $COMPLIANCE_API_KEY" \
  --header "anthropic-version: 2023-06-01"
```

The organizations are returned in a `data` array, alongside `has_more` and `next_page` for pagination:

```json theme={null}
{
  "data": [
    { "uuid": "00000000-0000-0000-0000-000000000000", "name": "Example Org", "created_at": "2026-01-01T10:00:00Z" }
  ],
  "has_more": false,
  "next_page": null
}
```

Copy the `uuid` value (not the `name`). See Anthropic's [List organizations, users, roles, groups](https://platform.claude.com/docs/en/manage-claude/compliance-org-data) for the full response schema.

## What is synced

By default the script syncs three sources. Limit a run with `--sources` (for example `chats,local_sessions`).

| Source | Compliance API | What becomes a Nebuly interaction |
| - | - | - |
| `chats` | `GET apps/chats` and chat messages | Each user/assistant pair. Deleted chats and chats with no user are skipped. |
| `local_sessions` | `GET apps/sessions/local` and session messages | Each prompt and its reply. A session that is still active stays open until it has been idle (`SESSION_IDLE_MINUTES`, default 30). |
| `remote_sessions` | `GET apps/sessions/remote` and session messages | Same cut as local sessions. Pending, active, and paused sessions are revisited on the next run. |

`end_user` is the Claude user id (`user.id`, or `started_by_user.id` when a remote session has no owner). It is not the email address.

Session interactions carry a `product surface` tag from Compliance. Use it to tell these products apart:

| Product | Where it appears |
| - | - |
| Claude chat | `chats`. Compliance does not label web, desktop, and local separately. |
| Cowork on desktop or local | Local session, `product surface` `cowork` |
| Cowork on the web | Remote session, `product surface` `cowork_remote` |
| Claude Code on desktop or local | Local session, `product surface` `claude_code`. Claude Code on the web is not in this API. |
| Claude in Chrome | Local session, `product surface` `claude_in_chrome` |
| Claude in Microsoft 365 and Google Workspace | Local session, `product surface` such as `office_agents/excel`, `office_agents/word`, or `office_agents/google_docs` |
| Claude Science | Local session, `product surface` `claude_science` |

Not included: Claude agents, Claude Design, Claude in Slack, and token or cost fields. Spend can be added later from Anthropic's Analytics APIs.

## Enrich with Microsoft Entra

If Claude users authenticate with Microsoft, you can enrich each interaction from Entra. Compliance itself does not include team, market, or tenure. Those values live in the directory. The sync joins them by email and sets them on the same POST as the interaction.

Turn this on before the first sync. A later run does not send an interaction again, so directory fields are not added after the fact.

Use one of the two options. `ENTRA_FETCH` and `ENTRA_EXTRACT_PATH` cannot both be set.

### Fetch users when the sync starts

Set `ENTRA_FETCH=true`. Each run lists users from Microsoft Graph and keeps them in memory. Install the extra dependency first:

```bash theme={null}
poetry install --with entra
```

Then set these in `.env`:

```bash theme={null}
ENTRA_FETCH=true
AZURE_TENANT_ID=
AZURE_CLIENT_ID=
AZURE_CLIENT_SECRET=
```

**1. Register an app in Microsoft Entra**

1. Open the [Microsoft Entra admin center](https://entra.microsoft.com).
2. Go to **App registrations → New registration**.
3. Give the app a name.
4. Under **Supported account types**, choose **Single tenant only - \{tenant name}**.
5. Click **Register**.

**2. Tenant and client IDs**

On the app **Overview** page, copy:

* **Directory (tenant) ID** → `AZURE_TENANT_ID`
* **Application (client) ID** → `AZURE_CLIENT_ID`

**3. Client secret**

1. Go to **Certificates & secrets → New client secret**.
2. Copy the secret **Value** immediately. That value is `AZURE_CLIENT_SECRET`.

> [!WARNING]
>
> Client secrets expire. Rotate the secret before it lapses.

**4. Grant User.Read.All**

1. Go to **API permissions → Add a permission → Microsoft Graph → Application permissions**.
2. Add **`User.Read.All`**.
3. Click **Grant admin consent**.

The permission must show **Granted** before you run the sync. This is an application permission, because the script uses client credentials.

### Or point at a JSON file

Leave `ENTRA_FETCH` unset and set `ENTRA_EXTRACT_PATH` to a file of Graph user objects (`{ "users": [ ... ] }` or a bare array). The field names are `mail`, `userPrincipalName`, `department`, `jobTitle`, `officeLocation`, `city`, `country`, `usageLocation`, `companyName`, and `employeeHireDate`. You can export that file with `microsoft_entra` in the same repository (`poetry run python -m entra_export`).

### What gets added

The match is case-insensitive. Chats use `user.email_address`. Sessions use the email on the session **listing**, because the messages endpoint often returns `email_address: null`. An email that is missing, or that is not in the directory, is still sent. It just has no directory fields. `end_user` stays the Claude user id.

| Entra field | Interaction field |
| - | - |
| `department` | `team` |
| `country`, otherwise `usageLocation` | `market` |
| `employeeHireDate` | `tenure` (`YYYY-MM-DD`, UTC) |

The same values are also stored as tags (`department`, `job_title`, `office_location`, `city`, `country`, `company_name`, `employee_hire_date`). Empty values are omitted.

## FAQ

**Where does the synced data appear?**\
Conversations imported by the script show up on the **Interactions** page in your Nebuly project.

**When will my data appear?**\
There can be a delay of up to 30 minutes between the moment the script sends data and when it becomes visible in Nebuly. The script only syncs when you run it, so for ongoing sync schedule it (for example with cron).

**Is it safe to re-run the script?**\
Yes. The script maintains a local SQLite cache at `.cache/sync_state.db` that records which interactions have already been synced. Re-running it will pick up only new data and will not create duplicates.

**How can I see what would be sent without triggering ingestion?**\
Pass the `--dry-run` flag. The script will fetch and convert data but will skip the POST to Nebuly's ingestion endpoint, printing a summary instead.

**Are token and cost included?**\
No. The Compliance API does not expose per-interaction token or cost fields.

**Why do some interactions have no team, market, or tenure?**\
Entra did not contain that user's email, or the chat or session listing had no email. `end_user` is still the Claude user id. Enable enrichment before the first sync. A later run does not update an interaction that was already sent.

## Resources

> [card] [Claude Compliance Nebuly integration](https://github.com/nebuly-ai/nebuly-integration-examples/tree/main/claude_compliance)
>
> Full install guide, env-var table, CLI flags, and customization docs

> [card] [Claude Compliance API](https://platform.claude.com/docs/en/manage-claude/compliance-api)
>
> Anthropic's official Compliance API reference

> [card] [Nebuly Interaction API](https://docs.nebuly.com/tracking/api-reference/events/post-events-interaction-with-trace-v2.md)
>
> API reference for the Interaction ingestion endpoint


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.