Bug: "undefined is not an object (evaluating '$.input_tokens')" error crashes the session

Resolved 💬 4 comments Opened Apr 12, 2026 by Lihlan Closed May 24, 2026

Preflight Checklist

  • [ ] 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?

The application crashes with a error: "undefined is not an object (evaluating '$.input_tokens')".

This happens during long-running tasks or complex code analysis. It seems the UI component responsible for displaying token usage fails to handle cases where the usage object or specific token fields (like input_tokens) are missing or structured differently in the API response. Once this error occurs, the session becomes completely unresponsive.

What Should Happen?

The application should gracefully handle missing or differently structured usage data from the API without crashing the entire session. If token information is unavailable, it should either skip the display or show a placeholder instead of throwing an 'undefined' error.

Error Messages/Logs

TypeError: undefined is not an object (evaluating '$.input_tokens')

Steps to Reproduce

  1. Use Claude Code with an OpenAI-compatible provider (via CCswitch/LongCat).
  2. Perform a complex analysis task on a large codebase involving multiple file reads and git diffs.
  3. After several turns of conversation, the UI attempts to update the token usage.
  4. The error "undefined is not an object (evaluating '$.input_tokens')" appears and the session hangs.

Claude Model

Other

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

Claude Code version 2.1.96.cc1, running as a VSCode extension

Platform

Other

Operating System

Windows

Terminal/Shell

VS Code integrated terminal

Additional Information

I am using CCswitch to connect Claude Code to a third-party API provider (LongCat-Flash-Chat) that uses an OpenAI-compatible format.

The bug likely stems from a mismatch between the expected Anthropic usage object structure and the one returned by the compatible provider (which might use 'prompt_tokens' instead of 'input_tokens'). The frontend does not seem to have a null-check for the '$' or 'usage' object before accessing '.input_tokens'.

<img width="359" height="41" alt="Image" src="https://github.com/user-attachments/assets/730aaeb9-f59a-4aa7-b6b8-4f0c1cb63d58" />

View original on GitHub ↗

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