[Bug] OTel console exporter corrupts agent view in pty-backed background sessions

Status Open
Reported on v2.1.221
Maintainer reply None cached
Activity 0 comments · opened Aug 6, 2026

Bug Description
Title: [BUG] OTel console exporter corrupts agent view — patchConsole protects foreground sessions but not pty-backed background sessions ### What's Wrong? With console in the OTel exporter list, exporter output corrupts agent view. Foreground sessions are unaffected, because Claude Code patches console to keep stray writes off the terminal it renders into (patchConsole/restoreConsole are both present in the binary). Background sessions get no such protection: their fd 1 is a pty (claude --bg-pty-host …/pty/<id>.sock 132 71 -- …) whose entire stream is captured as session output and forwarded to whatever attaches. Exporter writes therefore become indistinguishable from session output and are painted into the frame. The pty geometry compounds it — ~34 KB of util.inspect output into a 132-column pty is hundreds of lines flooding the scroll region, so the layout desynchronises rather than merely looking noisy. ### What Should Happen? Console-exporter output should be kept off fd 1 for pty-backed background sessions, as it already is for foreground sessions — or console should be ignored with a warning when its output would enter a rendered stream. ### Steps to Reproduce 1. Set CLAUDE_CODE_ENABLE_TELEMETRY=1, OTEL_METRICS_EXPORTER=otlp,console, OTEL_LOGS_EXPORTER=otlp,console, plus a valid OTEL_EXPORTER_OTLP_*_ENDPOINT and OTEL_EXPORTER_OTLP_PROTOCOL. This last part matters: console only activates when the otlp exporter beside it constructs successfully. Without endpoints configured the chain aborts and nothing prints, which makes the bug look unreproducible. 2. Start a session, open agent view, and dispatch background sessions. 3. Frames fill with util.inspect'd OTel records (descriptor: { name: "claude_code.session.count", … }) and the layout breaks. Ctrl+L only helps until the next export. ### Evidence - Controlled test via CLAUDE_CONFIG_DIR pointed at a config directory with no managed settings, everything else identical: otlp,console produced 5 dumps / 10,587 bytes of stdout; otlp alone produced 0 dumps / 35 bytes, byte-identical to telemetry-off. So console is the cause, and removing it costs the OTLP pipeline nothing. - Roughly 34 KB of stdout per API call. A single one-word prompt produced 162 KB. - Foreground sessions are clean and background sessions are corrupted under identical configuration. - Version-independent: 2.1.221, 2.1.222 and 2.1.223 all behave identically. - Distinct from #58853 (closed as completed, generic agent-view garbling, fix predates this version). ### Related, arguably worse With OTEL_LOG_RAW_API_BODIES=1 (61.5% of the observed volume), full API request and response bodies are printed into the terminal and its scrollback, not merely exported. Anyone enabling console for debugging is unlikely to expect that. ### Claude Code Version 2.1.223 ### Platform macOS 15 (Darwin 25.6.0), Terminal.app ### Additional Information Configuration delivered via managed org settings.

Environment Info

  • Platform: darwin
  • Terminal: Apple_Terminal
  • Version: 2.1.223
  • Feedback ID: 91762738-964d-4a8b-9d21-98220a8dc9cf

Errors

[]

View original on GitHub ↗