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

# Claude Code

> Send the OpenTelemetry data of Claude Code to Cloud Uplink or a Self-Hosted Uplink instance.

Claude Code exports OpenTelemetry metrics, log events, and traces. To connect it, run `agentgolf harness setup claude-code`. Add `--endpoint <url>` for a Self-Hosted Uplink instance. Then set the content limit. See [Content length](#content-length). The rest of this page is for manual setup and content policy.

## Settings

The **Harness Setup** card on **Settings > Uplink > Publishing Keys** shows these settings for manual setup, with the publishing key in `OTEL_EXPORTER_OTLP_HEADERS`. `agentgolf harness setup claude-code` writes the same settings, but keeps the key in the system keychain. See [Publishing key in the system keychain](#publishing-key-in-the-system-keychain) and [Set up with the CLI](https://docs.agent.golf/harnesses/overview.md#set-up-with-the-cli). To copy the settings by hand, replace:

* `<endpoint>` with `https://uplink.agent.golf` for Cloud Uplink, or with the listener of your Self-Hosted Uplink instance, for example `http://127.0.0.1:4318`.
* `<publishing-key>` with your personal publishing key. See [Publishing keys](https://docs.agent.golf/harnesses/overview.md#publishing-keys).

> [tab] settings.json
>
> Add the variables to the `env` block of `~/.claude/settings.json`, or of `$CLAUDE_CONFIG_DIR/settings.json`, and keep the file's other settings:
>
> ```json theme={null}
> {
>   "env": {
>     "CLAUDE_CODE_ENABLE_TELEMETRY": "1",
>     "CLAUDE_CODE_ENHANCED_TELEMETRY_BETA": "1",
>     "OTEL_METRICS_EXPORTER": "otlp",
>     "OTEL_LOGS_EXPORTER": "otlp",
>     "OTEL_TRACES_EXPORTER": "otlp",
>     "OTEL_EXPORTER_OTLP_PROTOCOL": "http/protobuf",
>     "OTEL_SERVICE_NAME": "claude-code",
>     "OTEL_EXPORTER_OTLP_ENDPOINT": "<endpoint>",
>     "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT": "<endpoint>/v1/traces",
>     "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT": "<endpoint>/v1/metrics",
>     "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT": "<endpoint>/v1/logs",
>     "OTEL_EXPORTER_OTLP_HEADERS": "x-agentgolf-publishing-key=<publishing-key>",
>     "OTEL_LOG_USER_PROMPTS": "1",
>     "OTEL_LOG_ASSISTANT_RESPONSES": "1",
>     "OTEL_LOG_TOOL_DETAILS": "1",
>     "OTEL_LOG_TOOL_CONTENT": "1",
>     "OTEL_LOG_RAW_API_BODIES": "1"
>   }
> }
> ```
>
> Each user has their own publishing key, so do not put the header in the Claude Code managed settings. To roll out the other variables to every developer, see [Team rollout](#team-rollout).

> [tab] Shell
>
> Set the variables in the shell that starts `claude`:
>
> ```bash theme={null}
> export CLAUDE_CODE_ENABLE_TELEMETRY='1'
> export CLAUDE_CODE_ENHANCED_TELEMETRY_BETA='1'
> export OTEL_METRICS_EXPORTER='otlp'
> export OTEL_LOGS_EXPORTER='otlp'
> export OTEL_TRACES_EXPORTER='otlp'
> export OTEL_EXPORTER_OTLP_PROTOCOL='http/protobuf'
> export OTEL_SERVICE_NAME='claude-code'
> export OTEL_EXPORTER_OTLP_ENDPOINT='<endpoint>'
> export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT='<endpoint>/v1/traces'
> export OTEL_EXPORTER_OTLP_METRICS_ENDPOINT='<endpoint>/v1/metrics'
> export OTEL_EXPORTER_OTLP_LOGS_ENDPOINT='<endpoint>/v1/logs'
> export OTEL_EXPORTER_OTLP_HEADERS='x-agentgolf-publishing-key=<publishing-key>'
> export OTEL_LOG_USER_PROMPTS='1'
> export OTEL_LOG_ASSISTANT_RESPONSES='1'
> export OTEL_LOG_TOOL_DETAILS='1'
> export OTEL_LOG_TOOL_CONTENT='1'
> export OTEL_LOG_RAW_API_BODIES='1'
> claude
> ```

| Variable | Value | Purpose |
| - | - | - |
| `CLAUDE_CODE_ENABLE_TELEMETRY` | `1` | Turns on telemetry. |
| `CLAUDE_CODE_ENHANCED_TELEMETRY_BETA` | `1` | Turns on traces, which carry the model and latency of each request. |
| `OTEL_METRICS_EXPORTER`, `OTEL_LOGS_EXPORTER`, `OTEL_TRACES_EXPORTER` | `otlp` | Exports metrics, log events, and traces. |
| `OTEL_EXPORTER_OTLP_PROTOCOL` | `http/protobuf` | The protocol that Uplink accepts. |
| `OTEL_SERVICE_NAME` | `claude-code` | The default Claude Code service name. See the note below. |
| `OTEL_EXPORTER_OTLP_ENDPOINT` | `<endpoint>` | The OTLP endpoint of the uplink instance. |
| `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`, `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`, `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` | The endpoint with `/v1/traces`, `/v1/metrics`, or `/v1/logs` | The full URL of each signal. |
| `OTEL_EXPORTER_OTLP_HEADERS` | `x-agentgolf-publishing-key=<publishing-key>` | Your personal publishing key. |
| `OTEL_LOG_*` | `1` | Content settings. See [Session content](#session-content). |

`claude-code` is the default Claude Code service name. Set it anyway: a shell that exports `OTEL_SERVICE_NAME` for another tool changes the service name of Claude Code. Then Agent Golf does not record the session. Keep the other default settings of Claude Code, and do not set `OTEL_METRICS_INCLUDE_SESSION_ID` to `false`.

## Publishing key in the system keychain

`agentgolf harness setup claude-code` saves your publishing key in the system keychain, not in `settings.json`. `agentgolf` 0.1.11 added the system keychain. The command writes the `env` block above without `OTEL_EXPORTER_OTLP_HEADERS`, and sets the [`otelHeadersHelper`](https://code.claude.com/docs/en/settings-reference#otelheadershelper) setting to `agentgolf otel-headers`. Claude Code runs this helper, which reads the key from the system keychain.

* Claude Code must find `agentgolf` on its `PATH`. If it does not, give the full path of the binary in `otelHeadersHelper`, for example the output of `command -v agentgolf`.
* When the helper fails, Claude Code exports nothing, and `/status` shows the error.
* On a device without a system keychain, run `agentgolf harness setup claude-code --print`. It prints the settings with the key in `OTEL_EXPORTER_OTLP_HEADERS`, and writes no file. Keep the file where you put them readable only by you.

For a second run, a key that the system keychain already holds, and the move from an earlier release, see [Claude Code and the system keychain](https://docs.agent.golf/cli/commands.md#claude-code-and-the-system-keychain).

## Team rollout

An admin can roll out every variable except the publishing key in the Claude Code managed settings. Each developer then adds only their key, with `agentgolf harness setup claude-code`. See [Roll out to a team](https://docs.agent.golf/harnesses/overview.md#roll-out-to-a-team).

`agentgolf harness managed-settings claude-code` prints the managed settings: an `env` block with each variable above except `OTEL_EXPORTER_OTLP_HEADERS`. Add `--endpoint <url>` for a Self-Hosted Uplink instance. See [`agentgolf harness managed-settings`](https://docs.agent.golf/cli/commands#agentgolf-harness-managed-settings). Install the file in one of these places:

* Linux: `/etc/claude-code/managed-settings.d/agentgolf.json`.
* macOS: `/Library/Application Support/ClaudeCode/managed-settings.d/agentgolf.json`.
* Or merge the `env` block into your existing `managed-settings.json`.

For example, on Linux:

```bash theme={null}
agentgolf harness managed-settings claude-code > agentgolf.json \
  && sudo install -D -m 0644 agentgolf.json /etc/claude-code/managed-settings.d/agentgolf.json
```

Then each developer runs `agentgolf harness setup --all`, or `agentgolf harness setup --all --endpoint <url>` with the same URL for a Self-Hosted Uplink instance. The command saves their personal publishing key in the system keychain, and sets `otelHeadersHelper` in `~/.claude/settings.json`, or in `$CLAUDE_CONFIG_DIR/settings.json`. It does not write `OTEL_EXPORTER_OTLP_HEADERS`.

Claude Code merges `env` variable by variable. When more than one settings file sets a variable, the file with the highest precedence applies. The managed settings leave `OTEL_EXPORTER_OTLP_HEADERS` and `otelHeadersHelper` unset, so the values of each user apply. Between `managed-settings.json` and the files of `managed-settings.d`, `env` also merges key by key.

To lock the helper too, add `--otel-headers-helper`. The managed settings then also set `otelHeadersHelper` to `agentgolf otel-headers`, with `--environment <env>` for an API other than production. If you merge the `env` block into `managed-settings.json`, merge the `otelHeadersHelper` setting too. A managed `otelHeadersHelper` wins over the value of each user. See [Settings precedence](https://code.claude.com/docs/en/settings#settings-precedence). The helper holds no key: on each device, it reads the personal publishing key of the user from the system keychain. Each device needs `agentgolf` on the `PATH` of Claude Code. `agentgolf` 0.1.11 added the flag and the helper.

Roll out the managed helper in this order:

1. Each developer runs `agentgolf harness setup claude-code` with a release that saves the key in the system keychain, 0.1.11 or later.
2. Then install the managed settings with the helper.

A helper that fails stops all exports of the device. This is also true on a device that still has the static header of an earlier release.

```bash theme={null}
agentgolf harness managed-settings claude-code --otel-headers-helper > agentgolf.json \
  && sudo install -D -m 0644 agentgolf.json /etc/claude-code/managed-settings.d/agentgolf.json
```

> [!WARNING]
>
> Never set `OTEL_EXPORTER_OTLP_HEADERS` in the managed settings. A managed value wins over the value of each user, and
> replaces their personal publishing key.

## Session content

By default, Claude Code sends lengths, tool names, and token counts, but no text and no tool arguments. These variables add content. The settings above turn on each one:

| Variable | Adds |
| - | - |
| `OTEL_LOG_USER_PROMPTS` | The text of the prompts. |
| `OTEL_LOG_ASSISTANT_RESPONSES` | The text of the responses. |
| `OTEL_LOG_TOOL_DETAILS` | The arguments and details of tool calls. |
| `OTEL_LOG_TOOL_CONTENT` | The content of tool calls, in `tool.output` span events: command output, file content, and diffs. It needs traces. Edit and Write also need `OTEL_LOG_TOOL_DETAILS`. |
| `OTEL_LOG_RAW_API_BODIES` | The raw API request and response bodies, with the full conversation history. |

Remove a variable where your policy does not allow the uplink instance to receive that content. With less content, Agent Golf links fewer sessions to pull requests automatically. See [Session content](https://docs.agent.golf/harnesses/overview.md#session-content).

### Content length

Claude Code truncates each content value at a content limit. The default limit is 61,440 UTF-16 code units. A raw request body holds the full conversation history, so in a long session the default limit can truncate it. When you set `OTEL_LOG_RAW_API_BODIES=1`, also set the limit to 262144 for the `claude` process:

```bash theme={null}
export CLAUDE_CODE_OTEL_CONTENT_MAX_LENGTH=262144
```

The CLI and the **Harness Setup** card do not set it, so add it yourself in the same place as the other variables, for example the `env` block of `~/.claude/settings.json`. Uplink does not read it.

* This value raises the limit. It does not remove it. Claude Code still truncates a longer body.
* If you set `OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT`, or one of its log record or span variants, to a lower value, Claude Code truncates at that lower value.

See `CLAUDE_CODE_OTEL_CONTENT_MAX_LENGTH` in the [Claude Code monitoring reference](https://code.claude.com/docs/en/monitoring-usage#common-configuration-variables).

## TLS with a private CA

If your Self-Hosted Uplink instance's certificate comes from a private CA, point Claude Code at the CA bundle:

```bash theme={null}
OTEL_EXPORTER_OTLP_CERTIFICATE=/etc/uplink/ca.pem
```

## Known limits

* A tool call that fails input validation sends no tool telemetry. The session does not show that call.
* Another failed tool call sends no tool output event. The session shows its outcome, but no output.

## Verify the setup

* Start `claude` and send a prompt. Then do the checks in [Verify the setup](https://docs.agent.golf/harnesses/overview.md#verify-the-setup).
* If requests show no model, provider, or latency, confirm `CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1` and `OTEL_TRACES_EXPORTER=otlp`.
* If Uplink receives requests but no session shows, confirm that `OTEL_SERVICE_NAME` is `claude-code` in the environment of Claude Code.
* If `/status` shows an `otelHeadersHelper` error, run the `otelHeadersHelper` command of your settings in a shell, for example `agentgolf otel-headers > /dev/null`. Exit code `3` means that the system keychain has no key: run `agentgolf harness setup claude-code`. For an `--environment` other than `prod`, set `AGENTGOLF_API_BASE_URL` to the API of that environment for the setup. Exit code `1` means that the CLI cannot read the system keychain. If the shell finds `agentgolf` but Claude Code does not, give the full path in `otelHeadersHelper`.


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