claude-code - 💡(How to fix) Fix Admin API lines_of_code metric significantly undercounts compared to /cost [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#46281Fetched 2026-04-11 06:24:27
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Timeline (top)
labeled ×2

The Claude Code Admin API endpoint (/v1/organizations/usage_report/claude_code) returns lines_of_code values that are dramatically lower than what the /cost command reports for the same user on the same day.

Root Cause

The Claude Code Admin API endpoint (/v1/organizations/usage_report/claude_code) returns lines_of_code values that are dramatically lower than what the /cost command reports for the same user on the same day.

RAW_BUFFERClick to expand / collapse

Summary

The Claude Code Admin API endpoint (/v1/organizations/usage_report/claude_code) returns lines_of_code values that are dramatically lower than what the /cost command reports for the same user on the same day.

Example data

For the same user (Ajit) on the same days:

Apr 9 /costApr 9 Admin APIApr 10 /costApr 10 Admin API
Lines added273342914
Lines removed8301

The cost and token data from the API are in the right ballpark compared to /cost, so this appears specific to the lines_of_code metric.

Context

  • API endpoint: GET /v1/organizations/usage_report/claude_code
  • The documentation describes lines_of_code.added as "Total number of lines of code added across all files by Claude Code"
  • /cost describes its metric as "Total code changes: N lines added, M lines removed"
  • Both claim to measure lines changed by Claude Code, but the API reports 1-2 orders of magnitude less

Additional observations

  • Token counts and estimated costs from the API are reasonably close to /cost output, so the data pipeline is generally working
  • The tool_actions counts (e.g., edit_tool.accepted: 3) are suspiciously close to the lines_of_code.added value (3) on April 9, raising the question of whether operations are being counted instead of lines
  • All actors in our org show as api_actor type with terminal_type: "unknown" or specific terminal types

Questions

  1. What exactly does the Admin API's lines_of_code metric measure? Is it intentionally different from /cost's "Total code changes"?
  2. If they should match, is this a known bug in the aggregation pipeline?
  3. Is there a way to get the full line count (matching /cost) through the Admin API?

Environment

  • Claude Code CLI (latest)
  • Admin API with anthropic-version: 2023-06-01

extent analysis

TL;DR

The discrepancy between the /cost command and the Admin API's lines_of_code metric may be due to differences in how lines of code are measured, potentially counting operations instead of lines.

Guidance

  • Review the documentation for the Admin API's lines_of_code metric to understand what it measures and how it differs from the /cost command's "Total code changes" metric.
  • Investigate the possibility that the lines_of_code metric is counting operations (e.g., tool actions) instead of individual lines of code, which could explain the significantly lower values.
  • Compare the tool_actions counts with the lines_of_code.added values to see if there's a correlation, which could indicate that operations are being counted instead of lines.
  • Consider reaching out to the API maintainers or support team to clarify the intended behavior of the lines_of_code metric and to report the discrepancy.

Example

No code snippet is provided as it is not clearly supported by the issue.

Notes

The issue may be specific to the lines_of_code metric and not a general problem with the API or data pipeline, as token counts and estimated costs are reasonably close to /cost output.

Recommendation

Apply workaround: Use the /cost command's "Total code changes" metric as the primary source of truth for lines of code changed, and treat the Admin API's lines_of_code metric with caution until its behavior is clarified.

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 Admin API lines_of_code metric significantly undercounts compared to /cost [1 participants]