claude-code-usage-audit · EN · 2026-10-30

Auditing Which Claude Code Session Ate the Most USDC on One Key

Learn how to attribute USDC spend to specific Claude Code sessions by correlating local session transcripts with aggregator request logs, enabling accurate cost auditing and optimization.

When you use a single API key for multiple Claude Code sessions, it can be challenging to determine which session consumed the most USDC. This guide shows you how to correlate local session transcripts with aggregator request logs to attribute spend per session.

Understanding the Data Sources

Two primary data sources are available for auditing:

  • Claude Code session transcripts: Stored locally by Claude Code, these logs record each interaction, including timestamps, model used, and token counts (if enabled).
  • Aggregator request logs: Your API aggregator provides logs of each request made with your key, including timestamp, model, token usage, and the USDC cost (calculated as official price × 1.3).

By matching requests from the aggregator logs to sessions from the transcripts, you can attribute costs accurately.

Step 1: Export Aggregator Request Logs

Log in to your aggregator dashboard and export the request logs for the desired time range. Ensure the export includes:

  • Timestamp (UTC recommended)
  • Model name
  • Input tokens and output tokens
  • Calculated USDC cost
  • Any request ID or metadata

Save this as a CSV or JSON file for processing.

Step 2: Locate Claude Code Session Transcripts

Claude Code stores session transcripts locally. The exact location depends on your operating system and configuration, but typically you can find them in a directory such as ~/.claude/transcripts or within your project's .claude folder. Each session is usually a separate file containing a sequence of events with timestamps.

If transcripts do not include token counts, you may need to enable detailed logging in Claude Code settings.

Step 3: Align Timestamps and Identify Sessions

Because both data sources have timestamps, you can align them. Note that timestamps may differ in timezone or precision, so normalize them to UTC and round to the nearest second or minute as needed.

A simple approach is to:

  • Parse each session transcript to extract the start and end times, and optionally the sequence of model calls.
  • For each request in the aggregator log, find the session whose time window contains the request timestamp.
  • If sessions overlap, use additional context (e.g., model name, token counts) to disambiguate.

Step 4: Calculate USDC Spend per Session

Once requests are mapped to sessions, sum the USDC cost for each session. The aggregator log already includes the cost per request (official price × 1.3), so you can simply aggregate.

If you are a key contributor, remember that you receive credit at official price × 1.1 (or × 1.2 for premium models). This credit is separate from the cost you pay as a user; for auditing your own spend, use the user-side cost.

Step 5: Analyze and Optimize

With spend attributed to sessions, you can identify which sessions or projects are most expensive. Consider:

  • Reviewing sessions with high token usage for potential optimizations (e.g., trimming context, using cheaper models for simple tasks).
  • Setting up alerts or budgets per session or project.
  • Using separate API keys for different projects to simplify future attribution.

Automating the Process

For ongoing auditing, script the correlation process. A basic Python script could:

  • Load the aggregator CSV.
  • Iterate over session transcript files, parsing timestamps.
  • Match requests to sessions based on time windows.
  • Output a summary table of USDC spend per session.

Ensure your script handles timezone conversions and overlapping sessions gracefully.

Best Practices

  • Keep transcripts and logs for at least the period you need for auditing.
  • Use consistent timezones (UTC) across systems.
  • Enable detailed logging in Claude Code if token counts are needed for deeper analysis.
  • Periodically review your API key usage to detect anomalies.

By following these steps, you can accurately audit USDC spend per Claude Code session and make informed decisions to optimize costs.