[Feature] Visual Token Warning Thresholds
Description
Change the color of the context token counter to yellow at 80% usage and red at 95% usage of the current model's maximum context limit.
Use Case
Context windows can fill up unexpectedly during long debugging sessions. Users often don't realize they are out of tokens until the API throws an error or the agent forgets instructions. Visual indicators provide an intuitive early warning.
Proposed Solution
- Determine the
maxTokenslimit for the currently loaded model (e.g., 128k for GPT-4o). - Calculate the percentage of
currentTokens / maxTokens. - In the React component rendering the token count, apply Chalk/Ink colors: green (< 80%), yellow (80%-94%), red (>= 95%).
Alternatives Considered
- Showing a blocking modal/warning prompt. This is too intrusive and interrupts the chat flow.
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] This feature aligns with the project's goals (local-first AI assistance)
Implementation Notes (optional)
- You may need to maintain a mapping of popular model names to their context window limits if the API provider doesn't reliably return
maxTokensin the model list endpoint.
Hi @akramcodez !
I think this is already on main.
getContextColor in source/components/development-mode-indicator.tsx:31 does exactly this, using TOKEN_THRESHOLD_WARNING_PERCENT = 80 / TOKEN_THRESHOLD_CRITICAL_PERCENT = 95 from source/constants.ts:83-84,
applied to the ctx: N% segment at line 233.
The model → context-limit mapping from the implementation notes is covered too: resolveModelContextLimit (source/models/models-dev-client.ts:426) layers session override → provider config → env → models.dev, with /context-max for manual overrides.
Only deviation: under 80% renders colors.secondary (dim) instead of green.
Reads intentional a green counter at rest looks like an alert.
One real gap though: the specs assert the ctx: N% text but never the colour transitions, so a regression in getContextColor would pass CI silently.
If that's worth locking down, I'd be glad to add the boundary tests
This is already in place: getContextColor in development-mode-indicator.tsx switches colour at 80% (TOKEN_THRESHOLD_WARNING_PERCENT) and 95% (CRITICAL), and those constants predate this issue. The only difference from the proposal is that the warning colour is dimmed. Open a new issue for a narrower one if you'd like that changed.