[BUG] Bash output "+N lines" count is computed from total chars / terminal width, not actual newlines — undercounts hidden lines

Resolved 💬 1 comment Opened May 15, 2026 by sjbronner Closed May 22, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Summary

In Claude Code's collapsed Bash-output preview, the +N lines (ctrl+r to expand) indicator does not reflect the actual number of hidden newline-separated lines. Instead, it is derived from a character-budget heuristic (Math.ceil(totalChars / terminalWidth) − 3), which systematically undercounts when the output has many short lines and overcounts when lines are very long.

Why this matters

The indicator is the only signal a user has — before deciding to expand — about how much content was suppressed. A 56-line tool result that claims "32 lines" misleads the user into thinking the output is small. Worse: the value silently changes with terminal width, so the same command behaves differently across sessions.

What Should Happen?

Expected behavior

+N lines should reflect the actual number of newline-separated lines that are hidden, independent of terminal width or character density.

Suggested fix

Replace the character-budget heuristic with a direct newline count of the suppressed portion:

let M = f
  ? K.slice(z.length).split("\n").length
  : O;

(Plus minor adjustments for trailing newlines.)

Error Messages/Logs

Steps to Reproduce

Repro

  1. Run a command that produces ~50–60 short lines (e.g. JSON arrays, ls -1 of many short filenames):

``bash
timew export 2026-05-09 - 2026-05-15 # produced 53 entries / ~56 lines
``

  1. Observe the collapsed view: 3 lines visible + "+29 lines" → total reported = 32.
  2. Expand with Ctrl+R. Real visible output = ~56 raw lines (~65 with wrapping).

The "+29" is wrong by ~24 lines. With a wider terminal the reported number drops further, with a narrower one it rises — even though the underlying byte content is unchanged.

Root cause (from claude-code 2.1.142 bundle)

EMK(H, $, q) in the rendering layer computes:

var ZEH = 3, m19 = 10;          // ZEH = visible-lines const; m19 = width margin
let _ = Math.max($ - m19, 10);  // _ ≈ terminal width
let A = ZEH * _ * 4;            // budget = 12 × width chars
let f = K.length > A;
let M = f
  ? Math.max(O, Math.ceil(K.length / _) - ZEH)
  : O;
// → "+${M} lines"

When the output exceeds the budget A, the displayed M is calculated from total character length divided by terminal width, minus the constant ZEH = 3. Real \n count is ignored. O (the true remaining-lines count from the visible chunk) is used only as a floor.

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.142

Platform

Anthropic API

Operating System

Other Linux

Terminal/Shell

Other

Additional Information

_No response_

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗