Skip to content

Claude Code 1.0.9 no longer reports the costUSD field #4

Description

@nnamon

It appears that Claude Code 1.0.9 no longer includes the costUSD field that ccusage is using to track the costs in the session log files:

{
  "parentUuid": "9194323f-ea9c-486a-be20-599e666df380",
  "isSidechain": false,
  "userType": "external",
  "cwd": "/Users/nnamon/projects/mcp/playwright-mcp",
  "sessionId": "0a9a8045-53e9-44b1-83fb-aafc6e1f4f0b",
  "version": "1.0.9",
  "message": {
    "id": "msg_018vkDifij3YKNQ5gzjtvbXz",
    "type": "message",
    "role": "assistant",
    "model": "claude-opus-4-20250514",
    "content": [
      {
        "type": "tool_use",
        "id": "toolu_01S3mjJhHAtzk1uuAU1cn85r",
        "name": "Bash",
        "input": {
          "command": "docker build -f Dockerfile.dev -t playwright-mcp-dev:latest . --no-cache",
          "description": "Rebuild Docker image with the fix"
        }
      }
    ],
    "stop_reason": "tool_use",
    "stop_sequence": null,
    "usage": {
      "input_tokens": 3,
      "cache_creation_input_tokens": 161,
      "cache_read_input_tokens": 89356,
      "output_tokens": 97,
      "service_tier": "standard"
    },
    "ttftMs": 3382
  },
  "requestId": "req_011CPkCWc21qrE6dGwSHMcw1",
  "type": "assistant",
  "uuid": "03a7a350-a7db-4fcb-8844-aded9b69e7a8",
  "timestamp": "2025-06-02T22:40:37.397Z"
}

The model and token counts are still included, however. This probably means that the costs could be calculated for these by multiplying them with their listed prices?

Activity

  1. ryoppippi commented on Jun 3, 2025

    @ryoppippi
    Member

    Hi nnamon!
    Yes, I think we can integrate with https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json file.
    This is my inital thought by the way.
    I'll work on it tomorrow(maybe Claude Code can write code for my while I'm sleeping!)

    Thank you for letting me know!

  2. ryoppippi commented on Jun 3, 2025

    @ryoppippi
    Member

    so it's related to #3

  3. self-assigned this
    on Jun 3, 2025
  4. ryoppippi commented on Jun 3, 2025

    @ryoppippi
    Member

    So I'm working on the updated version,
    and I found the cost mismatch

    ---log
    File: 67a6f4f7-8c9e-42d9-a87b-c1dcf1332b9e.jsonl
    Timestamp: 2025-05-25T19:16:15.368Z
    Model: claude-opus-4-20250514
    Original cost: $0.064230
    Calculated cost: $0.128459
    Difference: $0.064230 (100.00%)
    Tokens: {"input_tokens":3,"output_tokens":397,"cache_creation_input_tokens":131,"cache_read_input_tokens":64122}
    
  5. nnamon commented on Jun 3, 2025

    @nnamon
    Author

    Wow, the original reported cost being half of the actual API price is quite a big discrepancy.

  6. ryoppippi commented on Jun 3, 2025

    @ryoppippi
    Member

    This only happens in opus model. Here is the summary by Claude Code:

    ⏺ Looking at the conversation history and the current state of the codebase, I can see that:
    
      1. The initial issue where bun ./index.ts -s 20250603 showed tokens but zero cost has been fixed by correcting the schema to place the model field
      inside the message object.
      2. A verification script was created that revealed:
        - 83.34% of entries with both costUSD and model match the new calculations
        - 16.66% show mismatches, all with exactly 2x difference
        - All mismatches are for the claude-opus-4-20250514 model
        - This indicates the pricing for this model has doubled since the original calculations
      3. The verification script has been kept as requested and shows detailed results including model-by-model breakdowns.
    
      The user's requests have been completed:
      - The bug was fixed
      - The pricing verification was performed
      - The verification script was kept
      - Full results were shown
    
      The codebase is now working correctly with the fixed schema and can handle both old entries (with pre-calculated costUSD) and new entries (with model
      field for dynamic cost calculation).

    As far as my understanding, the price hasn't changed

  7. ryoppippi commented on Jun 3, 2025

    @ryoppippi
    Member

    I need your help!!!!!

    I have pushed the validation scripts to the alpha branch.

    https://github.com/ryoppippi/ccusage/blob/91adb43e7bdb34f1808f5f8e49f54809924cfbe8/verify-pricing.ts

    I would like you guys to test the script and report it here. This helps me to improve ccusage. Thanks

    git clone https://github.com/ryoppippi/ccusage
    cd ccusage
    git checkout 91adb43
    bun i
    bun ./verify-prising.ts

    Also, you can test the new one by

    bun ./index.ts
    
  8. nnamon commented on Jun 3, 2025

    @nnamon
    Author

    I've attached the output from my box.

    verify_pricing.txt

    Looks like it's mostly matching with 3% discrepancy. Awesome work! :)

  9. ryoppippi commented on Jun 3, 2025

    @ryoppippi
    Member

    @nnamon
    Thank you for your report.
    This is interesting because in your environment, all of the difference comes from sonnet, while my issue comes from opus.

  10. nnamon commented on Jun 3, 2025

    @nnamon
    Author

    Could probably be because I usually use sonnet most of the time and the error came from a bugged version? I sampled a few of the files, they were all from versions 1.0.7.

  11. ryoppippi commented on Jun 3, 2025

    @ryoppippi
    Member

    Oh really? How did you find the log comes from version 1.0.7

  12. ryoppippi commented on Jun 3, 2025

    @ryoppippi
    Member

    In my log, I found a mimatch before releasing 1.0.7 🤔

    ---
    File: 67a6f4f7-8c9e-42d9-a87b-c1dcf1332b9e.jsonl
    Timestamp: 2025-05-25T19:16:15.368Z
    Model: claude-opus-4-20250514
    Original cost: $0.064230
    Calculated cost: $0.128459
    Difference: $0.064230 (100.00%)
    Tokens: {"input_tokens":3,"output_tokens":397,"cache_creation_input_tokens":131,"cache_read_input_tokens":64122}
    ---
    File: 67a6f4f7-8c9e-42d9-a87b-c1dcf1332b9e.jsonl
    Timestamp: 2025-05-25T19:16:15.368Z
    Model: claude-opus-4-20250514
    Original cost: $0.064230
    Calculated cost: $0.128459
    Difference: $0.064230 (100.00%)
    Tokens: {"input_tokens":3,"output_tokens":397,"cache_creation_input_tokens":131,"cache_read_input_tokens":64122}
    
  13. itsUndefined commented on Jun 3, 2025

    @itsUndefined

    Here are my logs in case they help you with the investigation. I run your scripts using ts-node because I don't have bun installed. I always restarted claude code as soon as I saw the message "Update installed. Restart to apply"

    verify-pricing.txt

  14. ryoppippi commented on Jun 3, 2025

    @ryoppippi
    Member

    @itsUndefined
    Thanks. It looks like you can run it successfully.

    Oh 81.9% matches? hmm

  15. 3 remaining items

  16. itsUndefined commented on Jun 3, 2025

    @itsUndefined

    That's just the output of running ts-node index.ts on the commit 91adb43, not sure if it's actually "good"

  17. nnamon commented on Jun 3, 2025

    @nnamon
    Author

    I've got a modified verified-pricing.ts which dumps the version:

    === Discrepancy Analysis ===
    
    Cost ratio patterns (calculated/original):
      2.0x: 322 occurrences (100.0%)
    
    === Version Summary ===
    
    Total unique versions: 9
    Entries per version:
      1.0.3: 6,220 entries (55.1%)
      1.0.7: 3,127 entries (27.7%)
      1.0.4: 687 entries (6.1%)
      1.0.5: 548 entries (4.9%)
      1.0.9: 384 entries (3.4%)
      1.0.6: 193 entries (1.7%)
      1.0.8: 102 entries (0.9%)
      1.0.2: 16 entries (0.1%)
      1.0.0: 10 entries (0.1%)
    
    === Version Discrepancy Summary ===
    
    Versions with discrepancies: 1
    Discrepancies per version:
      1.0.7: 322 discrepancies (10.3% of version entries, 100.0% of all discrepancies)
    

    verify-pricing.ts.txt

    verify_pricing_output_with_version.txt

    Though, it could be just something on the server side end during that same time period for all of us that was reporting the wrong costUSDs regardless of version as @itsUndefined mentioned.

  18. ryoppippi commented on Jun 3, 2025

    @ryoppippi
    Member

    Thank you guys! I'll preparing for the script!

  19. ryoppippi commented on Jun 3, 2025

    @ryoppippi
    Member

    Hi! I pushed the new script. Check it out!!

  20. mimikun commented on Jun 3, 2025

    @mimikun

    I tried it myself, but I haven't used it much, so I don't know if it will be of any help. I ran it on the claude v1.0.3 and the v1.0.9.

    log file: https://gist.github.com/mimikun/f10f44ac8417d52904fd96c42d8e2d5e

    In my case, there was no difference in the numbers. I haven't used claude cli yet after updating.

  21. changed the title [-]Claude Code 1.0.9 no longer reports the costUSD field[/-] [+]Claude Code 1.0.7 no longer reports the costUSD field[/+] on Jun 3, 2025
  22. ryoppippi commented on Jun 3, 2025

    @ryoppippi
    Member

    @mimikun I guess you are using API usage plan right? not max

  23. itsUndefined commented on Jun 3, 2025

    @itsUndefined

    verify-pricing-new.txt , using Max Plan 5x

  24. mimikun commented on Jun 3, 2025

    @mimikun

    @mimikun I guess you are using API usage plan right? not max

    I forgot to mention. sorry. that I am using for the Max Plan (100 USD/month).

  25. changed the title [-]Claude Code 1.0.7 no longer reports the costUSD field[/-] [+]Claude Code 1.0.9 no longer reports the costUSD field[/+] on Jun 3, 2025
  26. ryoppippi commented on Jun 3, 2025

    @ryoppippi
    Member

    Thanks guys!!

    Based on the verification so far.

    • costUSD values are different from API prices
    • API calculations are partly correct and partly incorrect

    For now, we will incorporate this mechanism and create a new version

  27. nnamon commented on Jun 3, 2025

    @nnamon
    Author

    Awesome work @ryoppippi, thank you!

  28. ryoppippi commented on Jun 3, 2025

    @ryoppippi
    Member

    THANK YOU GUYS.
    JUST PUBLISHED!!!!

    GIVE ME FIVE!!!

  29. deleted a comment from EasonC13 on Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions