claude_code_commit_count_total resets repeatedly within one session during /goal, breaking increase()

Resolved 💬 1 comment Opened Jun 30, 2026 by backstromjoel Closed Jun 30, 2026

What happens

During a long-running autonomous /goal session, the cumulative OTel counter claude_code.commit.count (claude_code_commit_count_total) is non-monotonic within a single session_id. It climbs, drops back toward 0, and climbs again, many times over the session.

Counters are supposed to be monotonic, so a Prometheus/Grafana increase() or rate() query treats every drop as a counter reset and adds the pre-reset value back in. A /goal session that produced ~22 real commits reported ~6,200 via increase() over the range. Normal interactive sessions are perfectly monotonic and report correctly.

Environment

  • Claude Code version: 2.1.195 (also present cross-checking against 2.1.193)
  • Telemetry: OTLP metrics → Grafana Alloy → Prometheus (Mimir)
  • Temporality: cumulative (OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=cumulative)
  • session_id included as a metric attribute (OTEL_METRICS_INCLUDE_SESSION_ID)
  • OS: macOS (darwin 25.4.0), arm64; terminal: ghostty

Expected

claude_code_commit_count_total stays monotonically non-decreasing for the lifetime of a session_id, so increase()/rate() return the true commit count.

Actual

Hundreds of counter resets within one session_id during the /goal run (interactive sessions: zero). This inflates increase() by ~100×.

Likely cause (guess - internals not public)

The resets occur within a single, stable session_id, which suggests the metrics SDK / meter state is re-initialized mid-session (per goal iteration or per compaction) while the session_id is preserved — restarting the cumulative count from 0 under the same series. Other cumulative _count_total counters (pull_request, session, lines_of_code, tokens, cost) may share this and are worth checking.

Suggested fix

Keep the counter monotonic across the whole session_id lifetime (don't reset meter state on goal iterations/compaction), or mint a fresh session_id per segment so each is its own clean series.

Environment

  • Claude Code 2.1.195, macOS arm64
  • OTLP metrics exporter, cumulative temporality

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗