Skip to content

statusline: native context %, session-limit segment, wrapped + sorted MCPs - #156

Merged
ldayton merged 2 commits into
mainfrom
lily/statusline-context-session-wrap
Jun 12, 2026
Merged

statusline: native context %, session-limit segment, wrapped + sorted MCPs#156
ldayton merged 2 commits into
mainfrom
lily/statusline-context-session-wrap

Conversation

@ldayton

@ldayton ldayton commented Jun 12, 2026

Copy link
Copy Markdown
Owner

A batch of statusline improvements that lean on the data Claude Code now hands the script on stdin instead of recomputing it.

  • Context %: replace the transcript-tailing token sum with Claude Code's pre-calculated context_window.used_percentage. This drops a ~60-line file read per render and fixes an accuracy bug — the old calc folded output_tokens into "used", whereas the canonical percentage is input-only (input + cache_creation + cache_read), so our "% left" read hotter than /context. The 80 - x "% until auto-compact" framing and the pre-first-response 80% left fallback are unchanged.
  • New sess: N% left until <time> segment from rate_limits.five_hour (the 5-hour session window): used_percentage drives the remaining %, and resets_at (a Unix epoch) is rendered as the window's reset time in local computer time, e.g. sess: 64% left until 2:30pm. The 12-hour clock is formatted by hand (hour % 12, am/pm) to stay portable across the mac and linux brew builds; the until clause is dropped when resets_at is absent. White normally, yellow at <=20% left. The whole segment is absent on API-key billing and before the first response, where rate_limits isn't present.
  • Width-aware MCP layout: read COLUMNS (set by Claude Code v2.1.153+) and wrap the MCP server list onto continuation lines instead of letting it truncate at the terminal edge. Stays on one line when it fits; otherwise packs servers after the inline MCP: title and spills overflow to new lines, dropping the whole block to its own line when even the first server won't fit. Width is measured on visible text with ANSI escapes stripped, minus a 2-column margin for the double-width emoji and the right-side notification area.
  • Sort MCP servers connected-before-failing, each group alphabetical, so the list is stable and the broken ones cluster at the end.

ldayton added 2 commits June 12, 2026 13:15
… MCPs

A batch of statusline improvements that lean on the data Claude Code now hands the script on stdin instead of recomputing it.

- Context %: replace the transcript-tailing token sum with Claude Code's pre-calculated `context_window.used_percentage`. This drops a ~60-line file read per render and fixes an accuracy bug — the old calc folded `output_tokens` into "used", whereas the canonical percentage is input-only (input + cache_creation + cache_read), so our "% left" read hotter than `/context`. The `80 - x` "% until auto-compact" framing and the pre-first-response `80% left` fallback are unchanged.
- New `sess: N% left` segment from `rate_limits.five_hour.used_percentage` (the 5-hour session window), white normally and yellow at <=20% left. Absent on API-key billing and before the first response, where the field isn't present.
- Width-aware MCP layout: read `COLUMNS` (set by Claude Code v2.1.153+) and wrap the MCP server list onto continuation lines instead of letting it truncate at the terminal edge. Stays on one line when it fits; otherwise packs servers after the inline `MCP:` title and spills overflow to new lines, dropping the whole block to its own line when even the first server won't fit. Width is measured on visible text with ANSI escapes stripped, minus a 2-column margin for the double-width emoji and the right-side notification area.
- Sort MCP servers connected-before-failing, each group alphabetical, so the list is stable and the broken ones cluster at the end.
Append the 5-hour window's reset time to the sess segment from rate_limits.five_hour.resets_at, rendered in local computer time as e.g. "sess: 64% left until 2:30pm". The 12-hour clock is formatted by hand (hour % 12, am/pm) to avoid the non-portable %-I strftime flag across the mac and linux brew builds. Omitted when resets_at is absent.
@ldayton
ldayton merged commit 2edad4a into main Jun 12, 2026
1 check passed
@ldayton
ldayton deleted the lily/statusline-context-session-wrap branch June 12, 2026 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant