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

# Claude Code (CLI)

> Trace your terminal Claude Code sessions in RunAgain — no code changes.

Claude Code has built-in OpenTelemetry. It emits **log-events** (not spans):
`api_request`, `tool_result`, `user_prompt`, `api_error`, and `tool_decision`.
RunAgain accepts these at its OTLP **logs** endpoint (`/v1/logs`) and turns each
event into a span, grouping every `session.id` into a single trace.

<Info>
  This captures Claude Code running in your terminal — every session becomes one
  trace with its prompts, tool calls, API requests, token usage and cost.
</Info>

## 1. Generate an API key

In your project: **Overview → onboarding → Claude Code (CLI) → Generate API
key** (or **Settings → Create API key**). Copy the `sk_…` value.

## 2. Enable telemetry

Add these to your shell profile, or to `~/.claude/settings.json` under `"env"`:

```bash theme={null}
export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_LOGS_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=http/json
export OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://ingest.runagain.ai/v1/logs
export OTEL_EXPORTER_OTLP_LOGS_HEADERS="x-runagain-key=<your key>"

# optional: flush every 5s while testing, and capture prompt text
export OTEL_LOGS_EXPORT_INTERVAL=5000
export OTEL_LOG_USER_PROMPTS=1
```

<Warning>
  The endpoint decodes OTLP/JSON only, so **`OTEL_EXPORTER_OTLP_PROTOCOL=http/json`
  is required**. Use the logs-specific endpoint (`/v1/logs`) and header
  variables so metrics export (if you enable it elsewhere) isn't affected.
</Warning>

## 3. Run Claude Code

```bash theme={null}
claude   # use Claude Code normally — each session shows up as a trace
```

## What you'll see

Each session becomes one trace on your [Traces](/app/traces) page:

* `claude_code.api_request` → a **generation** span with provider `anthropic`,
  the model, input/output/cache tokens, and cost.
* `claude_code.tool_result` / `tool_decision` → **tool** spans (failures are
  marked as errors).
* `claude_code.user_prompt` → the prompt (when `OTEL_LOG_USER_PROMPTS=1`).

<Note>
  Cost comes from Claude Code's own `cost_usd`, so it's accurate regardless of
  RunAgain's pricing table.
</Note>
