Skip to content

Commit a4a58a9

Browse files
yepzdkclaude
andcommitted
fix: derive context percentage from remaining_percentage
The statusline showed a different percentage than Claude Code's native "Context low (X% remaining)" message because used_percentage excludes reserved overhead. Now uses 100 - remaining_percentage for alignment, falling back to used_percentage for older versions. Co-authored-by: Claude <noreply@anthropic.com>
1 parent 36eb4bc commit a4a58a9

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- `itkdev-statusline` extension with context window usage, git branch, and plan progress display
1313

14+
### Fixed
15+
16+
- Context percentage in `itkdev-statusline` now matches Claude Code's native context display by deriving from `remaining_percentage` instead of `used_percentage`
17+
1418
## [0.4.0] - 2026-02-20
1519

1620
### Added

extensions/itkdev-statusline/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ feat/auth │ 2/5 │ ▰▰▰▰▰▱▱▱▱▱ 45%
1212
|---------|--------|-------|
1313
| Git branch | `.git/HEAD` in `cwd` | Handles detached HEAD (short hash) |
1414
| Plan progress | `docs/plans/*.md` in `cwd` | Newest non-VERIFIED plan, checkbox counts |
15-
| Context % | stdin JSON `context_window.used_percentage` | 10-segment progress bar, color coded |
15+
| Context % | stdin JSON `context_window.remaining_percentage` | 10-segment progress bar, color coded. Falls back to `used_percentage`. |
1616

1717
### Context color thresholds
1818

extensions/itkdev-statusline/bin/statusline.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env bash
22
# itkdev-statusline: Claude Code statusline showing git branch, plan progress, and context usage.
3-
# Reads JSON from stdin (context_window.used_percentage, cwd).
3+
# Reads JSON from stdin (context_window.remaining_percentage, cwd).
44
# Target: <30ms execution, no unnecessary subprocesses.
55

66
set -euo pipefail
77

8-
# Parse cwd and used_percentage from stdin JSON via a single jq call.
9-
# Use parameter expansion to split on tab (read strips leading IFS chars).
10-
tsv=$(jq -r '[(.cwd // ""), (.context_window.used_percentage // 0), (.transcript_path // "")] | @tsv' 2>/dev/null) || true
8+
# Parse cwd and context percentage from stdin JSON via a single jq call.
9+
# Prefer remaining_percentage (matches Claude Code's native context display)
10+
# over used_percentage, which excludes reserved overhead and can differ.
11+
tsv=$(jq -r '[(.cwd // ""), (if (.context_window.remaining_percentage // null) != null then (100 - .context_window.remaining_percentage) | floor else (.context_window.used_percentage // 0) end), (.transcript_path // "")] | @tsv' 2>/dev/null) || true
1112
cwd="${tsv%%$'\t'*}"
1213
rest="${tsv#*$'\t'}"
1314
pct="${rest%%$'\t'*}"

0 commit comments

Comments
 (0)