Observability for Claude Code with Opik
Claude Code sessions can be logged to Opik in two ways: with the Opik Claude Code plugin, which hooks into Claude Code directly and captures every turn, tool call and subagent with full content, or through Claude Code’s native OpenTelemetry export, which sends spans to Opik’s OTLP endpoint. Most teams should start with the plugin.
Quick start
Inside Claude Code:
In a terminal, then restart Claude Code:
Back inside Claude Code:
Your next turn appears as a trace in the claude-code project in Opik. The rest of this page
explains the two options in full, how to route traces to a project or workspace, and how to
validate.
When this guide applies
Use this guide if you want to review Claude Code conversations in Opik: what developers asked, what the model answered, which tools ran, how subagents nested, and what each turn cost.
This guide covers telemetry flowing from Claude Code to Opik. For the other direction,
letting Claude Code read your traces, score outputs and run evaluations from chat, register the
Opik MCP server with it. One command, uvx opik mcp configure, installs the server
and the Opik skills. The two are independent, and you can use either or both.
Opik shows you what Claude Code did. If the question is where the tokens went and how to spend fewer of them, that is Cost Intelligence: every Claude Code API call captured on the wire and attributed to system prompt, tool schemas, MCP servers, skills, memory and user input, per user and per repository, with policy controls that typically cut spend by 15% to 30%. Only counts and metadata leave the machine, never content. Claude Code is Cost Intelligence’s primary agent, and it runs side by side with the Opik plugin.
Choose a path
Option 1: Opik Claude Code plugin
The opik-claude-code-plugin turns each
conversation turn into an Opik trace. Tool calls, thoughts and responses become spans, and
subagent invocations nest under their parent Task span.
Install
From inside Claude Code:
Restart any running Claude Code session; hooks only load when a session starts.
Configure the connection
This writes ~/.opik.config with your Opik URL, API key and workspace. Self-hosted and
Enterprise deployments enter their own URL at the prompt.
Turn tracing on
Traces land in the claude-code project by default. To route them elsewhere without touching
the Opik SDK settings the rest of your code uses:
or add cc_project_name / cc_workspace under [opik] in ~/.opik.config.
Embed Claude Code in a larger trace
If Claude Code runs inside a workflow you already trace with Opik, attach its spans to that trace:
What you see in Opik
Open the project and pick a trace: the user prompt is the trace input, the assistant’s final answer is the output, and each tool call is a span with its input and result. The Threads tab groups turns from the same session. Token usage and cost are recorded on each LLM span.
Option 2: Native OpenTelemetry export
Claude Code can emit OTel metrics, events and, in beta, trace spans. Opik ingests the trace spans only. Use this path when you already ship Claude Code telemetry to an OTel collector and want Opik as one more destination, or when you cannot install plugins.
Without CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1 Claude Code sends only metrics and events, and
nothing appears in Opik. Prompt, tool I/O and assistant output are redacted by default; the
flags in this section un-redact them. Assistant output on spans additionally requires the detailed-tracing
beta, which is available for the Claude Agent SDK and non-interactive claude -p runs but gated
in interactive sessions. If you need full content in interactive sessions, use the plugin.
Set these before starting Claude Code (Opik Cloud shown; swap the endpoint for your deployment, see the Opik OpenTelemetry overview):
Spans arrive as claude_code.interaction (one per prompt) with nested claude_code.llm_request
and claude_code.tool spans. Opik maps their content to trace and span input/output and
calculates cost from the model and token attributes.
For the full variable reference, endpoint modes and validation steps, see Claude Agent SDK and Claude Code OpenTelemetry.
Validation
- Run a short Claude Code turn that uses a tool, for example “list the files in this directory”.
- Open the target project in Opik (
claude-codefor the plugin, yourprojectNamefor OTel). - Confirm the trace carries content:
- Plugin: the trace input is your prompt and the trace output is the assistant’s answer.
- Native OTel: the trace is named
claude_code.interaction, its input is your prompt, and the model’s response is on theclaude_code.llm_requestspans (with model, tokens and cost). The trace-level output stays empty on this path. Tool calls appear asclaude_code.toolspans with their input and result.