Skip to content

feat(custom-command): include terminal_width in stdin JSON - #396

Merged
sirmalloc merged 3 commits into
sirmalloc:mainfrom
CorticalCode:feat/308-terminal-width-stdin
Jun 14, 2026
Merged

sirmalloc merged 3 commits into
sirmalloc:mainfrom
CorticalCode:feat/308-terminal-width-stdin

Conversation

@CorticalCode

Copy link
Copy Markdown
Contributor

Summary

Custom Command widgets receive context.data as JSON over stdin, but the terminal width was not part of it, so scripts had no way to adapt their output to the terminal. tput cols / stty size / $COLUMNS all report 80 in ccstatusline's piped stdio context, so the width is otherwise unrecoverable from a custom command. Requested in #308.

What changed

  • src/ccstatusline.ts — populate terminalWidth once on the render context via getTerminalWidth(). Custom commands execute during preRenderAllWidgets, before renderStatusLine computes the width, so the value has to be on the context up front. As a side benefit, the renderer now reuses this value instead of re-probing per line.
  • src/widgets/CustomCommand.tsx — add terminal_width to the JSON piped to the command when a numeric width is known (omitted otherwise).
{ "model": { "display_name": "..." }, "workspace": { "current_dir": "..." }, "terminal_width": 142 }

Notes

  • Field name terminal_width (snake_case) matches the existing Claude Code payload (session_id, current_dir, used_percentage, …).
  • Raw terminal width, not flex-adjusted — scripts get the actual column count (and it honors CCSTATUSLINE_WIDTH), independent of flexMode. This is complementary to feat(terminal): honor CCSTATUSLINE_WIDTH env var to override probe #380: CCSTATUSLINE_WIDTH overrides the probe, whereas this exposes the resulting width to custom-command stdin.
  • Omitted when undetectable, so script authors can guard for its absence.

Use case

Adaptive labels — full text ("ReadCache", "CacheCreate") on wide terminals, abbreviated ("RC", "CC") on narrow ones — as described in the issue.

Testing

  • New unit test (src/widgets/__tests__/CustomCommand.test.ts) mocking the execSync boundary: field present when width is known, existing data still passes through, field omitted when width is unknown.
  • Full suite green (1396 tests), lint clean.
  • Manually verified end-to-end with an adaptive custom-command script through both bun and the bundled dist (via node): full labels on wide terminals, abbreviated on narrow, the real tty width picked up with no override, and the raw width preserved under full-minus-40.
  • docs/USAGE.md updated.

Closes #308

CorticalCode and others added 2 commits June 9, 2026 20:59
Custom Command widgets receive context.data as JSON over stdin, but the
terminal width was not part of it, so scripts had no way to adapt their
output to the terminal (tput/stty/$COLUMNS all return 80 in the piped
context).

Populate context.terminalWidth once in the render pipeline via
getTerminalWidth() (which also lets the renderer reuse it instead of
re-probing per line) and add terminal_width to the JSON piped to custom
commands when a numeric width is known. The field name uses snake_case
to match the existing Claude Code payload (session_id, current_dir, ...).

Resolves the request in upstream issue sirmalloc#308.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CorticalCode
CorticalCode force-pushed the feat/308-terminal-width-stdin branch from c6b1a4c to 9f0079c Compare June 10, 2026 02:08
@sirmalloc
sirmalloc merged commit dd820ea into sirmalloc:main Jun 14, 2026
2 checks passed
@sirmalloc

Copy link
Copy Markdown
Owner

Thanks, this will be published in the next release.

@CorticalCode
CorticalCode deleted the feat/308-terminal-width-stdin branch June 14, 2026 15:02
tahodev pushed a commit to tahodev/ccstatusline that referenced this pull request Oct 20, 2026
…#396)

* feat(custom-command): include terminal_width in stdin JSON

Custom Command widgets receive context.data as JSON over stdin, but the
terminal width was not part of it, so scripts had no way to adapt their
output to the terminal (tput/stty/$COLUMNS all return 80 in the piped
context).

Populate context.terminalWidth once in the render pipeline via
getTerminalWidth() (which also lets the renderer reuse it instead of
re-probing per line) and add terminal_width to the JSON piped to custom
commands when a numeric width is known. The field name uses snake_case
to match the existing Claude Code payload (session_id, current_dir, ...).

Resolves the request in upstream issue sirmalloc#308.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(custom-command): document terminal_width in stdin JSON

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Matthew Breedlove <sirmalloc@gmail.com>
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.

Pass terminalWidth in custom command stdin JSON

2 participants