[FEATURE] Support injecting external TraceID / traceparent context for distributed tracing integration

Resolved 💬 2 comments Opened Jun 8, 2026 by lizunmvn Closed Jun 11, 2026

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Problem Statement

Problem

When Claude Code is used as part of a larger distributed system, it generates its own root
TraceID internally with no way to:

  1. Inject an external traceparent (W3C Trace Context) to make Claude Code's spans a child of an

upstream trace

  1. Control TraceID generation to match an existing APM system's format or ID space

We tested both approaches:

  • Setting TRACEPARENT environment variable before launching Claude Code — not used as parent

span context

  • Writing TRACEPARENT into settings.json env block — same result

CLAUDE_CODE_PROPAGATE_TRACEPARENT=1 only propagates Claude Code's own traceparent to child
processes, it does not accept an inbound traceparent to attach to.

## Use Case

Our infrastructure collects OpenTelemetry traces from multiple services (Java Spring Boot + OTEL
SDK). We want Claude Code's spans to participate in the same trace tree, so that:

  • A user request triggers Claude Code as part of a workflow
  • Claude Code's spans appear as children under the same TraceID in our APM backend
  • Downstream Java services called within that session share the same trace

Currently there is no way to achieve end-to-end trace continuity across Claude Code sessions.

Proposed Solution

Requested Change

Support one of the following:

Option A (preferred): Respect TRACEPARENT environment variable as the parent span context
when Claude Code starts, following the W3C Trace Context
spec
. This is the standard mechanism every other
OTEL-instrumented process uses.

Option B: Add a new environment variable (e.g. CLAUDE_CODE_PARENT_TRACEPARENT) explicitly
for this purpose, to avoid ambiguity.

## Expected Behavior

```bash
export TRACEPARENT="00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
claude
# All spans emitted by this Claude Code session should use 4bf92f3577b34da6a3ce929d0e0e4736 as
TraceID
# and 00f067aa0ba902b7 as the parent SpanID

Environment

  • Claude Code version: 2.1.x
  • Platform: macOS (darwin arm64)
  • Telemetry: OTEL HTTP/protobuf exporter configured via settings.json

Alternative Solutions

_No response_

Priority

Critical - Blocking my work

Feature Category

CLI commands and flags

Use Case Example

_No response_

Additional Context

_No response_

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗