Repository navigation
Open
Labels
area:corearea:tuibugSomething isn't workingSomething isn't workinghas reproHas detailed reproduction stepsHas detailed reproduction stepsplatform:linuxIssue specifically occurs on LinuxIssue specifically occurs on Linux
Description
Preflight Checklist
- I have searched existing issues and this hasn't been reported yet
- This is a single bug report (please file separate reports for different bugs)
- I am using the latest version of Claude Code
What's Wrong?
Context percentage displays are inconsistent across different UI elements. The /context command and statusline JSON API show 67% used (31.7% free), but the built-in context warning on the right side of the status bar shows "2% remaining" and the system triggers "Context limit reached" even though there's ~63k tokens of free space available.
What Should Happen?
All context usage displays should show consistent percentages.
If /context reports 67% used with 63k tokens free (31.7%), the status bar warning should also show ~33% remaining (not 2%), and Context limit reached should not trigger until context is actually near capacity.
Error Messages/Logs
`Context limit reached · /compact or /clear to continue`
This message appeared while /context showed:
`claude-opus-4-5-20251101 · 134k/200k tokens (67%)` | `Free space: 63k (31.7%)`Steps to Reproduce
- Set autocompact to disabled in /config
- Start a long conversation (or continue an existing one) with Claude Code
- Work until the "Context limit reached" message appears
- Run /context command to see actual usage breakdown
- Compare the "Free space" percentage from /context with the "X% remaining" shown in the right side of the status bar
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
2.1.6
Claude Code Version
2.1.7
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
WSL2 with Wez-Term
Additional Information
My statusline-command.sh
#!/bin/bash
# Read JSON input from stdin
input=$(cat)
# Parse JSON fields
MODEL=$(echo "$input" | jq -r '.model.display_name')
USED=$(echo "$input" | jq -r '.context_window.used_percentage // 0')
CWD=$(echo "$input" | jq -r '.workspace.current_dir')
# Get git info
BRANCH=$(git -C "$CWD" branch --show-current 2>/dev/null || echo "")
if [ -n "$BRANCH" ]; then
git -C "$CWD" diff --quiet 2>/dev/null || DIRTY="*"
GIT="${BRANCH}${DIRTY}"
else
GIT=""
fi
# Build progress bar (10 characters wide)
BAR_WIDTH=10
FILLED=$(printf "%.0f" $(echo "scale=2; $USED * $BAR_WIDTH / 100" | bc 2>/dev/null || echo "0"))
[ -z "$FILLED" ] && FILLED=0
[ "$FILLED" -lt 0 ] 2>/dev/null && FILLED=0
[ "$FILLED" -gt "$BAR_WIDTH" ] 2>/dev/null && FILLED=$BAR_WIDTH
EMPTY=$((BAR_WIDTH - FILLED))
# Build the bar string with parallelograms
BAR=""
for ((i=0; i<FILLED; i++)); do BAR+="▰"; done
for ((i=0; i<EMPTY; i++)); do BAR+="▱"; done
# Output: Percentage | Model | Git | Progress Bar
PERCENT="${USED}%"
if [ -n "$GIT" ]; then
printf "%s | %s | %s %s" "$PERCENT" "$MODEL" "$GIT" "$BAR"
else
printf "%s | %s %s" "$PERCENT" "$MODEL" "$BAR"
fiReacted by psychcook, gabrielgad, ManiMamao, Maximilien Garenne, Costantino Marcello, Daniel Storm, Isaac Weber, James Gillard, Jonathan Wedin, Matt Attaway and 5 more
Metadata
Metadata
Assignees
Labels
area:corearea:tuibugSomething isn't workingSomething isn't workinghas reproHas detailed reproduction stepsHas detailed reproduction stepsplatform:linuxIssue specifically occurs on LinuxIssue specifically occurs on Linux
Activity
github-actions commentedon Jan 14, 2026
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
smconner commentedon Jan 18, 2026
🔗 Related: Orphaned background agents
This mismatch appears to have a secondary consequence: background agents become orphaned when context limit triggers early.
See #18981 for details — when "Context limit reached" fires based on one metric, the cleanup logic may be checking a different metric that still shows headroom. Result: agent never gets terminated, runs at 100%+ CPU indefinitely.
The fix for this issue (#18241) would likely also fix #18981 as a side effect.
qte77 commentedon Feb 15, 2026
Context percentage mismatch between /context, statusline API, and internal limit trigger
Root cause identified:
The mismatch is caused by the autocompact buffer not being accounted for consistently across UI elements.
The Math:
/contextreports:remaining_percentage(includes autocompact buffer)remaining_percentage - 16.5%Your reported numbers:
/context: 31.7% freeWhy this happens:
/contextshows total remaining space (including the reserved autocompact buffer)context_window.remaining_percentageincludes the buffer (misleading)The 16.5% buffer is NOT exposed in statusline JSON, forcing custom statusline scripts to reverse-engineer it:
Sebi2020 commentedon May 23, 2026
Error also occurs if auto compact is disabled. /context shows 88%, but no new messages can be send. (latest claude code version as of today, macOS).
adam-stone-zocdoc commentedon Jun 4, 2026
I am seeing the same thing today.
junaidtitan commentedon Jun 5, 2026
The mismatch between
/contextreporting 67% and the status bar showing 2% remaining (with "Context limit reached" firing while 63k tokens are supposedly free) is something we ran into while building cozempic, and it pointed to a real measurement gap: CC assembles the "context used" number differently in different places.cozempic current --diagnosereads your session JSONL directly and reports the ground-truth token count — independent of the status line or/contextdisplay. You can see the real number side-by-side with what CC shows you.What's most interesting for this issue specifically: if the diagnose output matches the 67% from
/contextbut not the 2% from the status bar, that confirms the status bar is computing against a different ceiling. If diagnose shows something closer to 98%, it suggests the JSONL has grown more than/contextis surfacing.Would genuinely like to know which way it goes for your session — github.com/Ruya-AI/cozempic, pip/pipx install, auto-runs. Happy to dig into the numbers with you.