Clarification needed on /cost calculation logic and token breakdown

Resolved 💬 3 comments Opened Feb 19, 2026 by Ccheers Closed Feb 22, 2026

Preflight Checklist

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

What's Wrong?

Any clarification on the formula used to derive that $3.10 from the provided stats would be greatly appreciated!

What Should Happen?

just cost $1.87

Error Messages/Logs

Steps to Reproduce

Context:
I'm trying to better understand how Claude Code calculates the total cost and tracks token usage. After running some commands, I noticed the output of /cost and /context provides detailed stats, but I'm curious about the specific math behind the final dollar amount.

Example Output:

Plaintext

❯ /cost
  ⎿  Total cost:            $3.10
     Total duration (API):  7m 48s
     Total duration (wall): 16m 49s
     Total code changes:    383 lines added, 133 lines removed
     Usage by model:
        claude-sonnet-4-5:  9.4k input, 33.7k output, 2.3m cache read, 172.2k cache write ($3.10)

❯ /context
  ⎿  Context Usage
     ⛀ ⛁ ⛁ ⛁ ⛀ ⛀ ⛀ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   claude-sonnet-4-5[1m] · 96k/1000k
     ⛁ ⛁ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶    okens (10%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   Estimated usage by category
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System prompt: 2.7k tokens (0.3%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System tools: 16.3k tokens (1.6%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ MCP tools: 60 tokens (0.0%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Custom agents: 319 tokens (0.0%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Skills: 1k tokens (0.1%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Messages: 77.3k tokens (7.7%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝   ⛶ Free space: 869k (86.9%)
                                               ⛝ Autocompact buffer: 33k tokens
                                                                     (3.3%)

Questions:

Caching logic: How are "cache read" (e.g., 2.3m) and "cache write" (e.g., 172.2k) factored into the final price compared to standard input/output tokens?

Total vs. Context: My /context shows around 96k tokens used, but /cost shows a cumulative "cache read" in the millions. Is the /cost command showing the cumulative usage of the entire session (including every turn where the cache was hit), while /context shows the current active window?

Price breakdown: Does the cost calculation use the standard Anthropic API pricing for Sonnet 4.5, or are there additional overheads considered?

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.1.45

Platform

Google Vertex AI

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

_No response_

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗