Erick Shaffer 4182b9e0b3 Fix token tracking to show accurate usage and add empirical warnings
This PR fixes critical issues with token tracking and provides users with
actionable warnings based on real failure data.

1. **Incorrect token counting**: The system was adding cache tokens
   (cache_creation_input_tokens, cache_read_input_tokens) as if they were
   new tokens, causing inflated counts like 28125% usage. Cache tokens are
   cumulative state, not incremental additions.

2. **No user guidance**: Users had no warning when approaching context limits,
   leading to unexpected "Prompt is too long" errors.

- Show only raw token counts from Claude API (input + output)
- Remove percentage calculations and context window estimates
- Display running totals that users can trust

Based on analysis of 29 failed sessions, implemented three warning levels:
- ✅ Safe: < 80K tokens
- ⚠️ Caution: 80K-95K tokens (yellow warning)
- 🚨 Danger: > 95K tokens (red alert)

The lowest observed failure was at 96,800 tokens, so warnings start at 80K
to give users ample time to start a new session.

- Styled clickable popover (replacing poor native tooltips)
- Token breakdown (input/output/total)
- Clear warning messages with context
- Dark mode support

- Fixed `extractTokenUsage()` to only count actual input/output tokens
- Removed hardcoded system overhead calculations
- Added contextWindowTokens tracking for future use
- Updated UI to show raw truth instead of estimates

This gives users the information they need without confusing calculations
or impossible percentages.
2025-07-20 15:12:41 -06:00
..
2025-06-12 11:54:26 -04:00
2025-07-18 18:24:26 -04:00