end_user stays the Claude user id. See Enrich with Microsoft Entra.
The source repository is available here.
Prerequisites
- A Claude Enterprise organization with the Compliance API enabled. The primary owner enables it in claude.ai → Organization settings → API. 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 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:
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.
- Open claude.ai → Organization settings → API.
- Under Keys, click Create key.
-
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.
-
Copy the secret immediately; it is shown only once. It starts with
sk-ant-api01-.
3
Organization UUID → ORGANIZATION_UUID
Call the List Organizations endpoint to find the The organizations are returned in a Copy the
uuid of the org you want to sync:data array, alongside has_more and next_page for pagination:uuid value (not the name). See Anthropic’s List organizations, users, roles, groups 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).
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:
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
SetENTRA_FETCH=true. Each run lists users from Microsoft Graph and keeps them in memory. Install the extra dependency first:
.env:
1
Register an app in Microsoft Entra
- Open the Microsoft Entra admin center.
- Go to App registrations → New registration.
- Give the app a name.
- Under Supported account types, choose Single tenant only - .
- 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
- Go to Certificates & secrets → New client secret.
- Copy the secret Value immediately. That value is
AZURE_CLIENT_SECRET.
4
Grant User.Read.All
- Go to API permissions → Add a permission → Microsoft Graph → Application permissions.
- Add
User.Read.All. - Click Grant admin consent.
Or point at a JSON file
LeaveENTRA_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 useuser.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.
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
Claude Compliance Nebuly integration
Full install guide, env-var table, CLI flags, and customization docs
Claude Compliance API
Anthropic’s official Compliance API reference
Nebuly Interaction API
API reference for the Interaction ingestion endpoint