[BUG] OpenTelemetry not emitting in non-interactive (-p) mode
Bug Description
Claude Code does not emit any OpenTelemetry data (metrics, logs, or traces) when running in non-interactive -p mode. Interactive mode works correctly with the same configuration.
Steps to Reproduce
# This emits nothing to OTel:
CLAUDE_CODE_ENABLE_TELEMETRY=1 \
OTEL_METRICS_EXPORTER=otlp \
OTEL_LOGS_EXPORTER=otlp \
OTEL_EXPORTER_OTLP_PROTOCOL=grpc \
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 \
OTEL_SERVICE_NAME=test-agent \
claude -p "say hello"
# Even console exporter produces no output:
CLAUDE_CODE_ENABLE_TELEMETRY=1 \
OTEL_METRICS_EXPORTER=console \
OTEL_LOGS_EXPORTER=console \
OTEL_METRIC_EXPORT_INTERVAL=1000 \
OTEL_LOGS_EXPORT_INTERVAL=1000 \
claude -p "say hello"
Expected Behavior
OTel data should be exported in -p mode, same as interactive mode. At minimum, the claude_code.session.count, claude_code.token.usage, claude_code.cost.usage metrics and claude_code.user_prompt, claude_code.api_request, claude_code.tool_result events should fire.
Actual Behavior
Zero OTel output in -p mode. No metrics, no logs/events, no traces. The console exporter produces nothing. The same configuration works perfectly in interactive mode.
Impact
This blocks OTel observability for any automation using claude -p, including:
- CI/CD pipelines
- Agent runtimes (K8s Jobs running
claude -pfor automated tasks) - Batch processing scripts
Environment
- Version: 2.1.100
- Platform: macOS (darwin) + Linux (K8s container, node:22-bookworm)
- Verified with both gRPC (port 4317) and HTTP/protobuf (port 4318)
- Collector confirmed reachable from the container (curl returns 405)
- Interactive mode works with identical env vars on same machine
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗