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.
Scripts Directory
This directory contains build and maintenance scripts for the Crystal application.
generate-notices.js
Generates a NOTICES file containing all third-party licenses for dependencies included in the Crystal distribution.
Usage
# Generate NOTICES file
pnpm run generate-notices
# Or run directly
node scripts/generate-notices.js
How it works
- Scans all node_modules directories in the workspace
- Collects license information from LICENSE files and package.json
- Excludes development-only dependencies that aren't distributed
- Creates a NOTICES file in the project root
When to run
- Automatically runs during
pnpm run build:macandpnpm run release:mac - Should be run whenever dependencies change
- CI/CD runs this in the license-compliance workflow
License compliance
The script helps ensure Crystal complies with open source license requirements by:
- Including all third-party license texts in distributions
- Identifying packages with missing license information
- Supporting the license-compliance GitHub workflow