From 87b2cd0e21de311c33fbedb5a24c97e256e78ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Nov=C3=A1k?= Date: Thu, 29 Jan 2026 19:28:22 +0100 Subject: [PATCH] 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 --- hooks/gsd-statusline.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hooks/gsd-statusline.js b/hooks/gsd-statusline.js index 6083c07c1..c9cc2d904 100755 --- a/hooks/gsd-statusline.js +++ b/hooks/gsd-statusline.js @@ -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`;