claude-code - 💡(How to fix) Fix claude_code_cost_usage_USD_total OTEL counter collides across parallel processes sharing the same session_id, producing oscillating values and inflating increase() queries by 100×+ [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#56317Fetched 2026-05-06 06:31:21
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×4

Error Message

Error Messages/Logs

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Claude Code emits claude_code_cost_usage_USD_total from multiple processes (likely multiple --resume instances) without a process-distinguishing label, causing collisions in
any time-series backend.

jsonl file of the session: 25554c44-43fd-4d31-beb2-905547620336_jsonl.csv

cost reports that were received in Prometheus from Claude Code: 25554c44-session-metrics-2026-04-27.csv

What Should Happen?

Add pid or instance_uuid to the label set, or aggregate to a single per-session emitter.

Error Messages/Logs

Steps to Reproduce

  1. Configure Claude Code OTEL export to a Prometheus-compatible backend (Mimir, Prometheus, etc.) per the https://docs.anthropic.com/en/docs/claude-code/monitoring-usage. Confirm cumulative temporality at both the Claude Code OTEL SDK and the OTEL collector.
  2. In one terminal (e.g., PyCharm), run claude --resume <session-id> and start working — make a few prompts that incur cost.
  3. Without exiting the first instance, in a second terminal of the same terminal_type (another PyCharm window) run claude --resume <session-id> against the same session UUID. Issue a few more prompts.
  4. After both processes have emitted at least one OTEL export interval (~60s), query the metric in your TSDB:
    claude_code_cost_usage_USD_total{session_id="<session-id>"}
  5. Sample at fine resolution (step=2s over a 5-minute window).

Claude Model

Not sure / Multiple models

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.126

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Other

Additional Information

No response

extent analysis

TL;DR

Adding a process-distinguishing label, such as pid or instance_uuid, to the claude_code_cost_usage_USD_total metric can resolve the collision issue in the time-series backend.

Guidance

  • Verify that multiple --resume instances are indeed emitting the claude_code_cost_usage_USD_total metric without a unique identifier.
  • Check the Claude Code documentation to see if there are any existing configuration options for adding custom labels to metrics.
  • Consider aggregating metrics to a single per-session emitter to avoid collisions.
  • Review the provided jsonl and csv files to understand the current metric emission pattern.

Example

No code snippet is provided as the issue does not imply a specific code change, but rather a configuration or design adjustment.

Notes

The exact solution may depend on the specific Prometheus-compatible backend being used and its configuration. Additionally, the issue may be resolved in a future version of Claude Code, but the current version (2.1.126) does not provide a clear solution.

Recommendation

Apply a workaround by adding a unique identifier to the metric label set, as this is the most straightforward solution given the current information.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix claude_code_cost_usage_USD_total OTEL counter collides across parallel processes sharing the same session_id, producing oscillating values and inflating increase() queries by 100×+ [1 participants]