> For the complete documentation index, see [llms.txt](https://herd-security.gitbook.io/herd-security-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://herd-security.gitbook.io/herd-security-docs/ai/ai-coach/connect-claude-code.md). Agents can also search and read this documentation through its [MCP server](https://herd-security.gitbook.io/herd-security-docs/~gitbook/mcp).

# Connect Claude Code to AI Insights

Create an ingest token in AI Insights and point Claude Code's OpenTelemetry export at Herd, so your engineering team's Claude Code activity shows up alongside the rest of your AI use.

## What it does

Claude Code has a built-in OpenTelemetry export. When you turn it on and point it at Herd, each machine that runs Claude Code sends its own activity to AI Insights, authenticated with an **ingest token** that Herd issues to your organization. The data comes from the machines and not from a provider API, so this works on any Claude plan.

Create the token in Herd, then set a few environment variables wherever your team runs Claude Code. After that, the **Connect Claude Code** card shows when Herd last received data from your organization.

You decide how much of the activity is sent. By default Claude Code sends the event log only. Prompt text, the commands Claude Code runs, and the output those commands return are each sent only if you opt in. See [What data is sent](#what-data-is-sent).

{% hint style="info" %}
Usage and cost figures come from Anthropic's Admin API instead, through the **Admin API key** field on the same card. That's a separate credential: setting up telemetry here doesn't bring in spend data, and the key doesn't bring in telemetry. See [Claude Code usage and cost in AI Insights](https://herd-security.gitbook.io/herd-security-docs/ai/ai-coach/claude-code-usage-and-cost.md).
{% endhint %}

***

## Before you start

* You're a Herd admin, or someone whose group grants the **Manage AI Governance** permission. Creating, rotating, and revoking the token all require it.
* You need a way to set environment variables on each machine that runs Claude Code, such as a shell profile, Claude Code's managed settings, or whatever your team already uses for machine configuration.
* Decide up front whether you want prompt text, tool inputs, and tool results included. Rolling the settings out once is easier than revisiting every machine.

***

## Create the ingest token

1. Click **AI Insights** in the left-hand sidebar, then click **Setup** in the top-right corner to open the **Setup** page.
2. Find the **Connect Claude Code** card and click **Create ingest token**. This issues one token for the whole organization, and every machine uses the same one.
3. Copy the token now. The token (it starts with `hg-`) is shown only this once, inside a block of ready-to-copy settings. Put it somewhere safe, like the secret store or password manager your team already uses.
4. Click **I've saved the token**.

{% hint style="info" %}
Before you click **I've saved the token**, you can check the token. **Send test event**, under **Check Herd's receiver**, sends a labelled sample from your browser to Herd's receiver with that token. A pass shows the receiver accepts the token and the sample's format. It does not show that Claude Code is set up on anyone's computer: only real data arriving shows that. Nothing is stored, and the last-received time does not change. To test later, rotate the token.
{% endhint %}

After that, the card shows only a short preview of the token. Herd stores only a hash of the token and its last four characters, so it can't show you the full value again. If you lose it, rotate to issue a new one.

{% hint style="warning" %}
Treat the ingest token like a password. Anyone who has it can send data into your organization's AI Insights. Don't commit it to a repository, paste it into a ticket, or put it in a shared doc.
{% endhint %}

This ingest token carries telemetry. If your organization also has agent oversight, the hooks that check tool calls use a separate credential, the shared hook token. They are two credentials; see [Agent Oversight Hook Token](https://herd-security.gitbook.io/herd-security-docs/ai/agent-oversight/hook-token.md).

\[Screenshot: Connect Claude Code card, not connected]

***

## Configure Claude Code on each machine

Set these on **every machine that runs Claude Code**, or once in Claude Code's **managed settings** so they apply fleet-wide. The card shows the settings ready to copy, with your organization's real endpoint and token already filled in. Copy the block from the card. The version below shows the shape only.

\[Screenshot: exporter settings block]

```bash
export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_LOGS_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=http/json
export OTEL_EXPORTER_OTLP_ENDPOINT=<the endpoint shown on the card>
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer <your token>"
export OTEL_BLRP_MAX_EXPORT_BATCH_SIZE=100
```

All six are required:

| Variable                          | What it does                                                                                   |
| --------------------------------- | ---------------------------------------------------------------------------------------------- |
| `CLAUDE_CODE_ENABLE_TELEMETRY`    | Turns on Claude Code's OpenTelemetry export. Nothing is sent without this.                     |
| `OTEL_LOGS_EXPORTER`              | Exports the event log: prompts, API requests, and tool runs.                                   |
| `OTEL_EXPORTER_OTLP_PROTOCOL`     | Must be `http/json`. Herd accepts OTLP/JSON only, not `grpc` or `http/protobuf`.               |
| `OTEL_EXPORTER_OTLP_ENDPOINT`     | The endpoint shown on the card. Claude Code appends `/v1/logs` itself, so don't add it.        |
| `OTEL_EXPORTER_OTLP_HEADERS`      | Your organization's ingest token, as a bearer token.                                           |
| `OTEL_BLRP_MAX_EXPORT_BATCH_SIZE` | Keeps each export at or under 100 log records. Herd rejects a larger request with a 413 error. |

{% hint style="info" %}
These six are for telemetry. They do not include `OTEL_METRICS_INCLUDE_ENTRYPOINT`, which is how Claude Code tells Herd how a session was started. A session set up with only these variables reads **Not reported yet** under **Who ran it**, a column and filter on **Agents → Activity** (visible when your organization has agent oversight). To have Claude Code report it, add `export OTEL_METRICS_INCLUDE_ENTRYPOINT=true` to the same settings. Herd's generated managed settings file already includes it; see [Roll Out the Agent Oversight Managed Settings](https://herd-security.gitbook.io/herd-security-docs/ai/agent-oversight/managed-settings-rollout.md). Even then, Herd recognises only a terminal session (**Driven by a person**) and a headless run (**Ran by itself**). Any other entry point reads **Not reported yet**.
{% endhint %}

Start Claude Code in a fresh shell so it picks up the variables, run a prompt or two, then check the status row on the **Connect Claude Code** card.

If you'd rather not have each machine talk to Herd directly, point them at your own **OpenTelemetry Collector** and forward from there. The Collector carries the same endpoint and token. Set its `send_batch_size` and `send_batch_max_size` to 100 or less.

### Optional: include prompt and tool content

These three are **off unless you set them**. Each one adds a category of content to what Claude Code sends, and each is a privacy trade-off. Read what it covers before turning it on, and tell your engineers which ones you've enabled.

```bash
export OTEL_LOG_USER_PROMPTS=1
export OTEL_LOG_TOOL_DETAILS=1
export OTEL_LOG_TOOL_CONTENT=1
```

| Variable                | What it adds                                                                                               | What that means for your team                                                                                                                                      |
| ----------------------- | ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `OTEL_LOG_USER_PROMPTS` | The text of each prompt.                                                                                   | Whatever your engineers type into Claude Code is sent as written, including anything they paste in.                                                                |
| `OTEL_LOG_TOOL_DETAILS` | Tool inputs: the shell commands Claude Code runs, file paths and arguments, and MCP server and tool names. | Reveals the shape of your codebase and tooling: repository paths, filenames, and which MCP servers your team uses. Commands can also carry arguments and literals. |
| `OTEL_LOG_TOOL_CONTENT` | Tool results: the output those tools return.                                                               | The widest of the three. Command output and file contents read by tools are sent, so anything a tool happens to print travels with it.                             |

{% hint style="info" %}
AI Insights needs prompt content to score. Without these variables Herd receives structural telemetry only, so there is nothing to score: the connection shows activity arriving but no scored conversations. Set them if you want Claude Code work scored and coached like the rest of your AI use.
{% endhint %}

***

## What data is sent

With the six required variables set and nothing else, Claude Code sends the event log: a record of prompts, API requests, and tool runs. That shows whether and how your team uses Claude Code.

The content of that work (prompt text, tool inputs, and tool results) is sent only when you set the matching optional variable above. Leave one unset and that category isn't sent.

Nothing is sent from a machine where `CLAUDE_CODE_ENABLE_TELEMETRY` isn't set, so coverage follows your rollout: a machine you haven't configured contributes nothing.

Content that does arrive is encrypted at rest.

### What the token can and cannot do

The ingest token is inbound only. Herd is granted nothing in your systems, and there are no permissions or scopes to consent to.

* It can write Claude Code telemetry into your organization's AI Insights, and nothing else. It reads nothing from Herd and can't reach another organization.
* Herd keeps only a hash of the token and its last four characters, which is why the full value is shown once and never again.
* You can review it in Herd on the **Connect Claude Code** card. On your side, look at the environment, managed settings, or Collector config that carries the token.

{% hint style="info" %}
Herd does not attribute a session to a person from the email Claude Code reports. To name developers on their sessions, each one connects a device. See [Name developers on Claude Code sessions](https://herd-security.gitbook.io/herd-security-docs/ai/agent-oversight/name-developers-on-sessions.md).
{% endhint %}

***

## Rotate or revoke the token

Both actions are on the **Connect Claude Code** card:

* **Rotate** issues a new token, shown once like the first.
* **Revoke** turns the token off.

{% hint style="warning" %}
Roll out the new settings first. Rotating or revoking stops every machine still using the old token on its next request. If you rotate before updating machines, your team keeps working but their activity stops arriving, and nothing on the machine says so. Plan a rotation like a configuration change: distribute the new token, confirm data is still arriving, then finish.
{% endhint %}

***

## Troubleshooting

**The status row says Herd hasn't received anything.** Work down the list:

* `CLAUDE_CODE_ENABLE_TELEMETRY=1` has to be set in the environment Claude Code actually runs in. Variables set in a shell profile don't reach sessions that were already open, so start a new one.
* `OTEL_EXPORTER_OTLP_PROTOCOL` must be `http/json`. With `grpc` or `http/protobuf`, Claude Code exports but Herd won't accept the data.
* Check the endpoint against the card, and make sure nothing has appended `/v1/logs`, because Claude Code adds that itself.
* Check the header format: `Authorization=Bearer <your token>`, with the token pasted whole and the word `Bearer` kept.

**It was working and stopped.** Someone probably rotated or revoked the token. Check the card: if the preview no longer matches the token your machines are using, roll out the current one.

**Data is arriving, but prompts and commands aren't in it.** That's the default. Set the optional variables in [Include prompt and tool content](#optional-include-prompt-and-tool-content) on each machine.

**Some engineers' work shows up and others' doesn't.** The variables are per machine. Confirm the unconfigured machines have all six required variables, with the same token.

**Exports are rejected with a 413 error.** Herd accepts at most 100 log records per request. Set `OTEL_BLRP_MAX_EXPORT_BATCH_SIZE=100` on machines that export directly, or set `send_batch_size` and `send_batch_max_size` to 100 or less on your Collector.

**You've lost the token.** It can't be recovered, because Herd only keeps a preview. Rotate to issue a new one and roll it out.
