statusline: native context %, session-limit segment, wrapped + sorted MCPs - #156
Merged
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A batch of statusline improvements that lean on the data Claude Code now hands the script on stdin instead of recomputing it.
context_window.used_percentage. This drops a ~60-line file read per render and fixes an accuracy bug — the old calc foldedoutput_tokensinto "used", whereas the canonical percentage is input-only (input + cache_creation + cache_read), so our "% left" read hotter than/context. The80 - x"% until auto-compact" framing and the pre-first-response80% leftfallback are unchanged.sess: N% left until <time>segment fromrate_limits.five_hour(the 5-hour session window):used_percentagedrives the remaining %, andresets_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; theuntilclause is dropped whenresets_atis absent. White normally, yellow at <=20% left. The whole segment is absent on API-key billing and before the first response, whererate_limitsisn't present.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 inlineMCP: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.