Skip to content

feat(terminal): read COLUMNS from Claude Code before probing - #612

Open
lancemarks wants to merge 1 commit into
sirmalloc:mainfrom
lancemarks:feat/read-columns-env
Open

lancemarks wants to merge 1 commit into
sirmalloc:mainfrom
lancemarks:feat/read-columns-env

Conversation

@lancemarks

Copy link
Copy Markdown

Summary

Claude Code 2.1.153+ sets COLUMNS and LINES to the current terminal size when it runs the status line (changelog, docs: "Sizing output to the terminal"). getTerminalWidth() now reads COLUMNS right after the CCSTATUSLINE_WIDTH override, so on current Claude Code the ancestor walk never runs.

Motivation

Change

src/utils/terminal.ts: after the override block, a positive-integer COLUMNS is memoized and returned. Order is now:

  1. CCSTATUSLINE_WIDTH (explicit user override still wins)
  2. COLUMNS
  3. session "no TTY" cache
  4. native /proc probe → ps/stty walk → tput cols

COLUMNS goes 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.

LINES is 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):

  • COLUMNS short-circuits probing (no execFileSync calls)
  • CCSTATUSLINE_WIDTH beats COLUMNS
  • COLUMNS=0 / COLUMNS=wide fall back to probing
  • COLUMNS applies on Windows
  • COLUMNS wins over a cached session "no TTY" without touching the cache
$ bun test
 2364 pass
 0 fail
$ bun run lint   # clean

The three behavior cases fail against main, and the fallback and precedence cases pass on both.

Risk

  • If someone exports COLUMNS in 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 trust tput cols (the existing last fallback) already gives COLUMNS through ncurses, and CCSTATUSLINE_WIDTH still overrides it.
  • The TUI reads process.stdout.columns and never calls this path, so it's unchanged.

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.
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