feat(#2160): collapse verbose '(1M context)' model suffix to compact (1M) badge (#2173)

* feat(#2160): collapse verbose '(1M context)' model suffix to compact (1M) badge

Claude Code appends " (1M context)" to the model display name in
long-context sessions, eating 12 characters of statusline width. Collapse
it to " (1M)" — the signal stays, the width doesn't. Any other display
name passes through unchanged.

Claude-Session: https://claude.ai/code/session_01Hme55Pvq6BhpgwBcyC5HAg

* docs(#2160): changeset fragment for PR #2173

* fix(#2160): review fixes — ctx variant, boundary test, changeset format

- broaden the suffix match with a context|ctx alternation (approval-condition
  variant the regex missed)
- pin non-context parentheticals ((beta), (deprecated)) as untouched
- changeset body ends with the (#2160) citation per house convention

Claude-Session: https://claude.ai/code/session_01Hme55Pvq6BhpgwBcyC5HAg

* test: regenerate golden-install-parity fixtures for the statusline hook change

Claude-Session: https://claude.ai/code/session_01Hme55Pvq6BhpgwBcyC5HAg

---------

Co-authored-by: Tom Boucher <trekkie@nomorestars.com>
This commit is contained in:
Cody Anderson
2026-07-14 18:37:43 -06:00
committed by GitHub
parent fc913b37a5
commit eec9efc351
14 changed files with 89 additions and 13 deletions

View File

@@ -319,6 +319,22 @@ function contextTokenSuffix(currentUsage) {
return total > 0 ? ` (${formatTokens(total)})` : '';
}
// --- Model name --------------------------------------------------------------
/**
* Collapse the verbose " (… context)" model-name suffix Claude Code sends for
* long-context sessions (e.g. "Sonnet 4.5 (1M context)") to a compact badge
* (" (1M)"). The signal is preserved; the width isn't. Tolerant by design
* (issue #2160 approval condition): any trailing parenthesized token ending
* in "context" is collapsed — a future "(500K context)" becomes "(500K)"
* rather than silently no-opping. The token's own casing is preserved.
* Any other display name passes through unchanged.
*/
function compactModelName(name) {
if (typeof name !== 'string') return name;
return name.replace(/\s*\(([^)]+?)\s+(?:context|ctx)\)$/i, ' ($1)');
}
// --- Git segment (opt-in) ------------------------------------------------------
//
// Opt-in via `statusline.show_git: true` in .planning/config.json. Renders the
@@ -409,7 +425,7 @@ function runStatusline() {
clearTimeout(stdinTimeout);
try {
const data = JSON.parse(input);
const model = data.model?.display_name || 'Claude';
const model = compactModelName(data.model?.display_name || 'Claude');
const dir = data.workspace?.current_dir || process.cwd();
const session = data.session_id || '';
const remaining = data.context_window?.remaining_percentage;
@@ -659,6 +675,7 @@ module.exports = {
evaluateUpdateCache,
formatTokens,
contextTokenSuffix,
compactModelName,
readGitStatus, parseGitStatus, buildGitSegment,
};
@@ -667,7 +684,7 @@ module.exports = {
* testing without feeding stdin. Returns the rendered string.
*/
function renderStatusline(data) {
const model = data.model?.display_name || 'Claude';
const model = compactModelName(data.model?.display_name || 'Claude');
const dir = data.workspace?.current_dir || process.cwd();
const dirname = path.basename(dir);