feat(terminal): read COLUMNS from Claude Code before probing - #612
Open
lancemarks wants to merge 1 commit into
Open
lancemarks wants to merge 1 commit into
lancemarks wants to merge 1 commit into
Conversation
Claude Code 2.1.153+ sets COLUMNS (and LINES) to the terminal size when it runs the status line. Reading it after CCSTATUSLINE_WIDTH and before the session cache skips the ps/stty ancestor walk on macOS/BSD and gives Windows a width without an override. Invalid values fall through to probing.
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.
Summary
Claude Code 2.1.153+ sets
COLUMNSandLINESto the current terminal size when it runs the status line (changelog, docs: "Sizing output to the terminal").getTerminalWidth()now readsCOLUMNSright after theCCSTATUSLINE_WIDTHoverride, so on current Claude Code the ancestor walk never runs.Motivation
Perf. On macOS/BSD the walk still spawns
pstwice per ancestor plussttyon every refresh. Linux already avoids that via the/procprobe from perf: stop re-probing the terminal width on every line of every render #501. Measured on an M-series Mac (builtdist, 40 interleaved runs, minimalterminal-width+modelconfig, same process depth as anpx ccstatuslinestatus line):COLUMNS)COLUMNS=120About 57 ms saved per render.
Robustness. It closes the "no ancestor owns a TTY" gap from Terminal width probe fails under Claude Code ≥ 2.1.139 (no controlling TTY for spawned statusline) #376/feat(terminal): honor
CCSTATUSLINE_WIDTHenv var to override probe #380 without the user setting anything, and gives Windows a width source by default, since probing is disabled there.Change
src/utils/terminal.ts: after the override block, a positive-integerCOLUMNSis memoized and returned. Order is now:CCSTATUSLINE_WIDTH(explicit user override still wins)COLUMNS/procprobe →ps/sttywalk →tput colsCOLUMNSgoes before the cache so that a stale cached "no TTY" result can't hide a real width. Missing, empty,0, or non-numeric values fall through to the existing path, the same way #380 handles bad input.LINESis deliberately not read, since nothing in ccstatusline uses terminal height yet.Test plan
Six new cases in
src/utils/__tests__/terminal.test.ts(COLUMNS is also cleared in setup/teardown so an ambient value can't leak into the probe tests):COLUMNSshort-circuits probing (noexecFileSynccalls)CCSTATUSLINE_WIDTHbeatsCOLUMNSCOLUMNS=0/COLUMNS=widefall back to probingCOLUMNSapplies on WindowsCOLUMNSwins over a cached session "no TTY" without touching the cacheThe three behavior cases fail against
main, and the fallback and precedence cases pass on both.Risk
COLUMNSin their shell rc and runs Claude Code older than 2.1.153, the status line inherits that fixed value where the probe used to find the live width. This is the same trusttput cols(the existing last fallback) already givesCOLUMNSthrough ncurses, andCCSTATUSLINE_WIDTHstill overrides it.process.stdout.columnsand never calls this path, so it's unchanged.