fix: scale context bar to show 100% at actual 80% limit

Claude Code enforces an 80% context window limit as a safety mechanism.
The statusline was showing the raw percentage, which meant the bar never
reached 100% before Claude ran out of context.

This change scales the percentage so that:
- 0% real usage = 0% displayed
- 80% real usage (the actual limit) = 100% displayed

Color thresholds are adjusted accordingly to maintain the same visual
progression (green -> yellow -> orange -> red with skull).

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
David Novák
2026-01-29 19:28:22 +01:00
committed by GitHub
parent 339e911299
commit 87b2cd0e21

View File

@@ -18,22 +18,25 @@ process.stdin.on('end', () => {
const session = data.session_id || '';
const remaining = data.context_window?.remaining_percentage;
// Context window display (shows USED percentage)
// Context window display (shows USED percentage scaled to 80% limit)
// Claude Code enforces an 80% context limit, so we scale to show 100% at that point
let ctx = '';
if (remaining != null) {
const rem = Math.round(remaining);
const used = Math.max(0, Math.min(100, 100 - rem));
const rawUsed = Math.max(0, Math.min(100, 100 - rem));
// Scale: 80% real usage = 100% displayed
const used = Math.min(100, Math.round((rawUsed / 80) * 100));
// Build progress bar (10 segments)
const filled = Math.floor(used / 10);
const bar = '█'.repeat(filled) + '░'.repeat(10 - filled);
// Color based on usage
if (used < 50) {
// Color based on scaled usage (thresholds adjusted for new scale)
if (used < 63) { // ~50% real
ctx = ` \x1b[32m${bar} ${used}%\x1b[0m`;
} else if (used < 65) {
} else if (used < 81) { // ~65% real
ctx = ` \x1b[33m${bar} ${used}%\x1b[0m`;
} else if (used < 80) {
} else if (used < 95) { // ~76% real
ctx = ` \x1b[38;5;208m${bar} ${used}%\x1b[0m`;
} else {
ctx = ` \x1b[5;31m💀 ${bar} ${used}%\x1b[0m`;