[BUG] Custom Statusline auto-compact percentage - calculation incorrect
Environment
- Platform (select one):
- Anthropic subscription
- Claude CLI version: 1.0.73 (Claude Code)
- Operating System: Windows 11
- Terminal: Command Prompt/PowerShell
Operating System: Windows 11
- Terminal: Command Prompt/PowerShell
Bug Description
Custom Statusline shows incorrect auto-compact percentage. Displays "Context
left until auto-compact: 3%" when 162,073 tokens remain, which should be
~81% remaining (162,073/200,000).
Steps to Reproduce
- Use Claude Code until statusline shows: Tokens: 37927 (523 in/37404
out) | 162073 left | Context left until auto-compact: 3%
- Calculate actual percentage: 162,073/200,000 = ~81%
- Notice mismatch between displayed (3%) and calculated (81%)
percentages
Expected Behavior
Auto-compact percentage should show ~81% remaining when 162,073 tokens
are left.
Actual Behavior
Shows 3% remaining instead of the correct 81%.
Additional Context
Token counts appear accurate - only the auto-compact percentage
calculation is wrong.
----token status code for /statusline
`
Claude Code Token Usage Status Line Script
param()
Read JSON input from stdin
$inputData = [Console]::In.ReadToEnd() | ConvertFrom-Json
Get the transcript path
$transcriptPath = $inputData.transcript_path
if (Test-Path $transcriptPath) {
try {
# Read the transcript file
$content = Get-Content $transcriptPath -Raw -ErrorAction Stop
# Extract token usage data using improved regex patterns
# Look for "input_tokens": number and "output_tokens": number patterns
$inputMatches = [regex]::Matches($content, '"input_tokens":\s*(\d+)')
$outputMatches = [regex]::Matches($content, '"output_tokens":\s*(\d+)')
$totalInput = 0
$totalOutput = 0
# Sum all input tokens
foreach ($match in $inputMatches) {
$totalInput += [int]$match.Groups[1].Value
}
# Sum all output tokens
foreach ($match in $outputMatches) {
$totalOutput += [int]$match.Groups[1].Value
}
$totalUsed = $totalInput + $totalOutput
# Claude 3.5 Sonnet typical context window (adjust based on your model)
$tokenLimit = 200000
$remaining = [math]::Max(0, $tokenLimit - $totalUsed)
# Format the output with current working directory, git branch, and model info
$modelName = $inputData.model.display_name -replace "Claude ", "C"
$currentDir = Split-Path -Leaf $inputData.workspace.current_dir
# Get git branch name
$gitBranch = ""
try {
Push-Location $inputData.workspace.current_dir
$gitBranch = git rev-parse --abbrev-ref HEAD 2>$null
if ($LASTEXITCODE -eq 0 -and $gitBranch) {
$gitBranch = " ($gitBranch)"
} else {
$gitBranch = ""
}
Pop-Location
}
catch {
$gitBranch = ""
if (Get-Location) { Pop-Location }
}
Write-Host "$modelName | $currentDir$gitBranch | Tokens: $totalUsed ($totalInput in/$totalOutput out) | $remaining left"
}
catch {
Write-Host "Tokens: Error parsing session data - $($_.Exception.Message)"
}
}
else {
Write-Host "Tokens: No session transcript found"
}
`
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗